Skip to content

Commit

Permalink
Remove commented code from build_erddap_catalog.py script
Browse files Browse the repository at this point in the history
  • Loading branch information
benjwadams committed Jan 5, 2024
1 parent 5b756aa commit ff02ab7
Showing 1 changed file with 0 additions and 122 deletions.
122 changes: 0 additions & 122 deletions scripts/build_erddap_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,6 @@ def build_erddap_catalog_chunk(data_root, deployment):
""").findall("dataVariable")


# variables which need to have the variable {var_name}_qc present in the
# template. Right now these are all the same, so are hardcoded
# required_qc_vars = {"conductivity_qc", "density_qc", "depth_qc",
# "latitude_qc", "lat_uv_qc", "longitude_qc",
# "lon_uv_qc", "profile_lat_qc", "profile_lon_qc",
# "pressure_qc", "salinity_qc", "temperature_qc",
# "time_qc", "time_uv_qc", "profile_time_qc",
# "u_qc", "v_qc"}

required_qartod_vars = {"qartod_conductivity_flat_line_flag",
"qartod_conductivity_gross_range_flag",
Expand Down Expand Up @@ -546,14 +538,6 @@ def build_erddap_catalog_chunk(data_root, deployment):
"qartod_temperature_rate_of_change_flag",
"qartod_temperature_spike_flag"}

# any destinationNames that need to have a different name.
# by default the destinationName will equal the sourceName
# dest_var_remaps = {'longitude_qc': 'precise_lon_qc',
# 'latitude_qc': 'precise_lat_qc',
# 'profile_lon_qc': 'longitude_qc',
# 'profile_lat_qc': 'latitude_qc',
# 'time_qc': 'precise_time_qc',
# 'profile_time_qc': 'time_qc'}

existing_varnames = {'trajectory', 'wmo_id', 'profile_id', 'profile_time',
'profile_lat', 'profile_lon', 'time', 'depth',
Expand All @@ -564,21 +548,6 @@ def build_erddap_catalog_chunk(data_root, deployment):

nc_file = os.path.join(data_root, deployment_dir, latest_file)
with Dataset(nc_file, 'r') as ds:
# qc_var_types = check_for_qc_vars(ds)
# #qc_vars = qc_var_snippets(required_qc_vars, qc_var_types)
# # need to explicitly cast keys to set in Python 2
# exclude_vars = (existing_varnames | set(dest_var_remaps.keys()) |
# required_qc_vars | {'latitude', 'longitude'} |
# qc_var_types['gen_qc'].keys() | qc_var_types['qartod'].keys())
# all_other_vars = [add_erddap_var_elem(var) for var in
# ds.get_variables_by_attributes(name=lambda n: n not in exclude_vars)]
# gts_ingest = getattr(ds, 'gts_ingest', 'true') # Set default value to true
# qc_vars_snippet = qc_var_snippets(required_qc_vars, qc_var_types, dest_var_remaps)
#
# vars_sorted = sorted(common_variables +
# qc_vars_snippet + all_other_vars,
# key=variable_sort_function)
# variable_order = core_variables + vars_sorted

qartod_var_type = check_for_qartod_vars(ds)

Expand Down Expand Up @@ -693,83 +662,6 @@ def qartod_var_snippets(required_qartod_vars, qartod_var_type):
return var_list


# def qc_var_snippets(required_vars, qc_var_types, dest_var_remaps):
# var_list = []
# for req_var in required_vars:
# # If the required non-QARTOD QC variable isn't already defined,
# # then supply a set of default attributes.
# if req_var not in qc_var_types['gen_qc']:
# flag_atts = """
# <att name="flag_values" type="byteList">0 1 2 3 4 5 6 7 8 9</att>
# <att name="flag_meanings">no_qc_performed good_data probably_good_data bad_data_that_are_potentially_correctable bad_data value_changed interpolated_value missing_value</att>
# <att name="_FillValue" type="byte">-127</att>
# <att name="valid_min" type="byte">0</att>
# <att name="valid_max" type="byte">9</att>
# """
# else:
# flag_atts = ""
#
# var_str = f"""
# <dataVariable>
# <sourceName>{req_var}</sourceName>
# <destinationName>{dest_var_remaps.get(req_var, req_var)}</destinationName>
# <dataType>byte</dataType>
# <addAttributes>
# <att name="ioos_category">Quality</att>
# <att name="long_name">{dest_var_remaps.get(req_var, req_var).replace('_qc', '')} Variable Quality Flag</att>
# {flag_atts}
# </addAttributes>
# </dataVariable>"""
# var_list.append(etree.fromstring(var_str))
#
# for qartod_var in qc_var_types["qartod"]:
# # if there are QARTOD variables defined, populate them
#
# if "_FillValue" not in qc_var_types['qartod'][qartod_var]:
# fill_value_snippet = '<att name="_FillValue" type="byte">-127</att>'
# else:
# fill_value_snippet = ""
# # all qartod variables should have _FillValue, missing_value,
# # flag_values, and flag_meanings defined
#
# qartod_snip = f"""
# <dataVariable>
# <sourceName>{qartod_var}</sourceName>
# <destinationName>{qartod_var}</destinationName>
# <dataType>byte</dataType>
# <addAttributes>
# <att name="ioos_category">Quality</att>
# <att name="flag_values" type="byteList">1 2 3 4 9</att>
# <att name="flag_meanings">GOOD NOT_EVALUATED SUSPECT BAD MISSING</att>
# <att name="valid_min" type="byte">1</att>
# <att name="valid_max" type="byte">9</att>
# {fill_value_snippet}
# </addAttributes>
# </dataVariable>
# """
# var_list.append(etree.fromstring(qartod_snip))
#
# for gen_qc_var in qc_var_types["gen_qc"]:
# # if we already have this variable as part of required QC variables,
# # skip it.
# if gen_qc_var in required_vars:
# continue
# # assume byte for data type as it is required
# gen_qc_snip = f"""
# <dataVariable>
# <sourceName>{gen_qc_var}</sourceName>
# <dataType>byte</dataType>
# <addAttributes>
# <att name="ioos_category">Quality</att>
# </addAttributes>
# </dataVariable>
# """
# var_list.append(etree.fromstring(gen_qc_snip))
#
# return var_list



def add_erddap_var_elem(var):
"""
Adds an unhandled standard name variable to the ERDDAP datasets.xml
Expand Down Expand Up @@ -839,20 +731,6 @@ def check_for_qartod_vars(nc):
qartod_vars['qartod'][var] = nc.variables[var].ncattrs()
return qartod_vars

# def check_for_qc_vars(nc):
# """
# Checks for general gc variables and QARTOD variables by naming conventions.
# Returns a dict with both sets of variables as keys, and their attributes
# as values.
# """
# qc_vars = {'gen_qc': {}, 'qartod': {}}
# for var in nc.variables:
# if var.endswith('_qc'):
# qc_vars['gen_qc'][var] = nc.variables[var].ncattrs()
# elif var.startswith('qartod'):
# qc_vars['qartod'][var] = nc.variables[var].ncattrs()
# return qc_vars


def get_latest_nc_file(root):
'''
Expand Down

0 comments on commit ff02ab7

Please sign in to comment.