Skip to content

Commit 0fc4378

Browse files
committed
move L0 script to deprecated
1 parent 0bd34f2 commit 0fc4378

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

pycurrents_ADCP_processing/ADCP_processing_L0.py renamed to deprecated/ADCP_processing_L0.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
import warnings
1414
from pycurrents.adcp.rdiraw import rawfile
1515
from pycurrents.adcp.rdiraw import SysCfg
16-
from pycurrents_ADCP_processing.ADCP_processing_L1 import mean_orientation, \
17-
convert_time_var, check_depths
18-
import pycurrents_ADCP_processing.add_var2nc as add_var2nc
16+
from pycurrents_ADCP_processing.ADCP_processing_L0_L1 import convert_time_var, check_depths
17+
from pycurrents_ADCP_processing import utils
1918

2019

2120
def add_attrs_2vars_L0(out_obj, metadata_dict, instrument_depth, fillValue,
@@ -423,7 +422,8 @@ def add_attrs_2vars_L0(out_obj, metadata_dict, instrument_depth, fillValue,
423422
var.attrs['legacy_GF3_code'] = 'SDN:GF3::CMAG_01'
424423
var.attrs['sdn_parameter_name'] = 'Correlation magnitude of acoustic signal returns from the water body by ' \
425424
'moored acoustic doppler current profiler (ADCP) beam 1'
426-
var.attrs['standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
425+
var.attrs[
426+
'standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
427427
var.attrs['data_min'] = np.nanmin(var.data)
428428
var.attrs['data_max'] = np.nanmax(var.data)
429429

@@ -438,7 +438,8 @@ def add_attrs_2vars_L0(out_obj, metadata_dict, instrument_depth, fillValue,
438438
var.attrs['legacy_GF3_code'] = 'SDN:GF3::CMAG_02'
439439
var.attrs['sdn_parameter_name'] = 'Correlation magnitude of acoustic signal returns from the water body by ' \
440440
'moored acoustic doppler current profiler (ADCP) beam 2'
441-
var.attrs['standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
441+
var.attrs[
442+
'standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
442443
var.attrs['data_min'] = np.nanmin(var.data)
443444
var.attrs['data_max'] = np.nanmax(var.data)
444445

@@ -453,7 +454,8 @@ def add_attrs_2vars_L0(out_obj, metadata_dict, instrument_depth, fillValue,
453454
var.attrs['legacy_GF3_code'] = 'SDN:GF3::CMAG_03'
454455
var.attrs['sdn_parameter_name'] = 'Correlation magnitude of acoustic signal returns from the water body by ' \
455456
'moored acoustic doppler current profiler (ADCP) beam 3'
456-
var.attrs['standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
457+
var.attrs[
458+
'standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
457459
var.attrs['data_min'] = np.nanmin(var.data)
458460
var.attrs['data_max'] = np.nanmax(var.data)
459461

@@ -468,7 +470,8 @@ def add_attrs_2vars_L0(out_obj, metadata_dict, instrument_depth, fillValue,
468470
var.attrs['legacy_GF3_code'] = 'SDN:GF3::CMAG_04'
469471
var.attrs['sdn_parameter_name'] = 'Correlation magnitude of acoustic signal returns from the water body by ' \
470472
'moored acoustic doppler current profiler (ADCP) beam 4'
471-
var.attrs['standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
473+
var.attrs[
474+
'standard_name'] = 'beam_consistency_indicator_from_multibeam_acoustic_doppler_velocity_profiler_in_sea_water'
472475
var.attrs['data_min'] = np.nanmin(var.data)
473476
var.attrs['data_max'] = np.nanmax(var.data)
474477
# done variables
@@ -564,7 +567,7 @@ def create_meta_dict_L0(f_meta):
564567
print('Metadata file contains a blank row; skipping this row !')
565568
elif row[0] != '' and row[1] == '':
566569
print('Metadata item in csv file has blank value; skipping this row '
567-
'in metadata file !')
570+
'in metadata file !')
568571
else:
569572
meta_dict[row[0]] = row[1]
570573

@@ -576,6 +579,11 @@ def create_meta_dict_L0(f_meta):
576579
meta_dict['variable_code_reference'] = 'BODC P01'
577580
meta_dict['Conventions'] = "CF-1.8"
578581

582+
# Use Geojson definitions for IOS
583+
meta_dict['geographic_area'] = utils.find_geographic_area_attr(
584+
lon=meta_dict['longitude'], lat=meta_dict['latitude']
585+
)
586+
579587
return meta_dict
580588

581589

@@ -590,12 +598,12 @@ def nc_create_L0(f_adcp, f_meta, dest_dir, start_year=None, time_file=None):
590598
:param time_file: full file name of csv file containing user-generated time data;
591599
required if inFile has garbled out-of-range time data
592600
"""
593-
601+
594602
if not os.path.exists(dest_dir):
595603
os.makedirs(dest_dir)
596604

597605
# Define the name for the netCDF file
598-
out_name = os.path.basename(f_adcp)[:-4] + '.adcp.L0.nc'
606+
out_name = os.path.basename(f_adcp)[:-4] + '_L0.adcp.nc'
599607
print(out_name)
600608
if not dest_dir.endswith('/') or not dest_dir.endswith('\\'):
601609
out_absolute_name = os.path.abspath(dest_dir + '/' + out_name)
@@ -719,7 +727,7 @@ def nc_create_L0(f_adcp, f_meta, dest_dir, start_year=None, time_file=None):
719727
# Orientation values such as 65535 and 231 cause SysCfg().up to generate an IndexError: list index out of range
720728
try:
721729
orientations = [SysCfg(fl).up for fl in fixed_leader.raw.FixedLeader['SysCfg']]
722-
meta_dict['orientation'] = mean_orientation(orientations)
730+
meta_dict['orientation'] = utils.mean_orientation(orientations)
723731
except IndexError:
724732
warnings.warn('Orientation obtained from data.sysconfig[\'up\'] to avoid IndexError: list index out of range',
725733
UserWarning)
@@ -733,8 +741,7 @@ def nc_create_L0(f_adcp, f_meta, dest_dir, start_year=None, time_file=None):
733741

734742
# Set up dimensions and variables
735743

736-
time_s, time_DTUT8601 = convert_time_var(time_var=vel.dday, number_of_profiles=data.nprofs,
737-
metadata_dict=meta_dict,
744+
time_s, time_DTUT8601 = convert_time_var(time_var=vel.dday, number_of_profiles=data.nprofs, meta_dict=meta_dict,
738745
origin_year=data.yearbase, time_csv=time_file)
739746

740747
# Distance dimension
@@ -749,10 +756,10 @@ def nc_create_L0(f_adcp, f_meta, dest_dir, start_year=None, time_file=None):
749756
# Do not create pressure variable if no data exists
750757
flag_no_pres = 0
751758
try:
752-
decapascal2decibar = 1/1000
759+
decapascal2decibar = 1 / 1000
753760
pressure = np.array(vel.VL['Pressure'] * decapascal2decibar, dtype='float32')
754761
except ValueError:
755-
warnings.warn('No pressure data available (no field of name Pressure')
762+
warnings.warn('No pressure data available (no field of name Pressure)')
756763
flag_no_pres += 1
757764

758765
# ------------------------------Depth-------------------------------
@@ -805,7 +812,7 @@ def nc_create_L0(f_adcp, f_meta, dest_dir, start_year=None, time_file=None):
805812
if flag_no_pres == 0:
806813
print('Assigning pressure variable')
807814
out = out.assign(PRESPR01=(('time'), pressure))
808-
815+
809816
if flag_pg == 0:
810817
print('Assigning percent good variables')
811818
out = out.assign(PCGDAP00=(('distance', 'time'), pg.pg1.transpose()))
@@ -871,7 +878,7 @@ def nc_create_L0(f_adcp, f_meta, dest_dir, start_year=None, time_file=None):
871878
out.attrs['three_beam_used'] = str(vel.trans['threebeam']).upper() # netCDF4 file format doesn't support bool
872879
out.attrs['valid_correlation_range'] = vel.FL['LowCorrThresh'] # lowCorrThresh
873880
out.attrs['min_percent_good'] = fixed_leader.FL['PGMin']
874-
out.attrs['blank'] = '{} m'.format(fixed_leader.FL['Blank'] / 100) #convert cm to m
881+
out.attrs['blank'] = '{} m'.format(fixed_leader.FL['Blank'] / 100) # convert cm to m
875882
out.attrs['error_velocity_threshold'] = "{} mm s-1".format(fixed_leader.FL['EVMax'])
876883
tpp_min = '{0:0>2}'.format(fixed_leader.FL['TPP_min'])
877884
tpp_sec = '{0:0>2}'.format(fixed_leader.FL['TPP_sec'])
@@ -912,10 +919,8 @@ def example_L0_1():
912919

913920
# Create netCDF file
914921
nc_name = nc_create_L0(raw_file, raw_file_meta, dest_dir, start_year=None, time_file=None)
915-
# Produce new netCDF file that includes a geographic_area variable
916-
geo_name = add_var2nc.add_geo(nc_name, dest_dir)
917922

918-
return nc_name, geo_name
923+
return nc_name
919924

920925

921926
def example_L0_2():
@@ -934,7 +939,4 @@ def example_L0_2():
934939
# Create netCDF file
935940
nc_name = nc_create_L0(f_adcp=raw_file, f_meta=raw_file_meta, dest_dir=dest_dir, time_file=scott_time)
936941

937-
# Produce new netCDF file that includes a geographic_area variable
938-
geo_name = add_var2nc.add_geo(nc_name, dest_dir)
939-
940-
return nc_name, geo_name
942+
return nc_name

0 commit comments

Comments
 (0)