Skip to content

Commit

Permalink
Updated implementations of the dicts vs functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbousquin committed Apr 11, 2024
1 parent 20922e1 commit 7962e1c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion harmonize_wq/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def methods_check(df_in, char_val, methods=None):
"""
if methods is None:
methods = accepted_methods()
methods = accepted_methods
method_col = 'ResultAnalyticalMethod/MethodIdentifier'
df2 = df_in.copy()
# TODO: check df for method_col
Expand Down
9 changes: 5 additions & 4 deletions harmonize_wq/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def characteristic_cols(category=None):
>>> domains.xy_datum['NAD83']
{'Description': 'North American Datum 1983', 'EPSG': 4269}
>>> domains.xy_datum()['NAD83']['EPSG']
>>> domains.xy_datum['NAD83']['EPSG']
4269
"""
xy_datum = {
Expand All @@ -549,8 +549,9 @@ def characteristic_cols(category=None):
"WAKE": {"Description": "Wake-Eniwetok 1960", "EPSG": 6732},
"WGS72": {"Description": "World Geodetic System 1972", "EPSG": 6322},
"WGS84": {"Description": "World Geodetic System 1984", "EPSG": 4326},
"HARN": {"Description": "High Accuracy Reference Network for NAD83",
"EPSG": 4152,
"HARN": {
"Description": "High Accuracy Reference Network for NAD83",
"EPSG": 4152,
},
}

Expand All @@ -573,7 +574,7 @@ def characteristic_cols(category=None):
pairs, here we show how the current name can be used as a key to get the
new name:
>>> domains.stations_rename()['OrganizationIdentifier']
>>> domains.stations_rename['OrganizationIdentifier']
'org_ID'
"""
stations_rename = {
Expand Down
4 changes: 2 additions & 2 deletions harmonize_wq/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def harmonize_locations(df_in, out_EPSG=4326,
df2['geom_orig'] = list(zip(df2[lon_col], df2[lat_col]))

# Create/populate EPSG column
crs_mask = df2[crs_col].isin(xy_datum().keys()) # w/ known datum
df2.loc[crs_mask, 'EPSG'] = [xy_datum()[crs]['EPSG'] for crs
crs_mask = df2[crs_col].isin(xy_datum.keys()) # w/ known datum
df2.loc[crs_mask, 'EPSG'] = [xy_datum[crs]['EPSG'] for crs
in df2.loc[crs_mask, crs_col]]

# Fix/flag missing
Expand Down
6 changes: 3 additions & 3 deletions harmonize_wq/wrangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def split_col(df_in, result_col='QA_flag', col_prefix='QA'):
char = 'Phosphorus'
if char in char_list:
i = char_list.index(char)
suffix = '_' + domains.out_col_lookup()[char]
suffix = '_' + domains.out_col_lookup[char]
col_list[i] = [col for col in df_out.columns if col.endswith(suffix)]

# Drop rows where result na
Expand Down Expand Up @@ -754,7 +754,7 @@ def to_simple_shape(gdf, out_shp):
>>> wrangle.to_simple_shape(gdf, 'dataframe.shp')
"""
cols = gdf.columns # List of current column names
names_dict = domains.stations_rename() # Dict of column names to update
names_dict = domains.stations_rename # Dict of column names to update
# Rename non-results columns that are too long for shp field names
renaming_list = [col for col in cols if col in names_dict]
renaming_dict = {old_col: names_dict[old_col] for old_col in renaming_list}
Expand All @@ -766,7 +766,7 @@ def to_simple_shape(gdf, out_shp):

# Results columns need to be str not pint (.astype(str))
# Narrow based on out_col lookup dictionary
results_cols = [col for col in possible_results if col in domains.out_col_lookup().values()]
results_cols = [col for col in possible_results if col in domains.out_col_lookup.values()]
# TODO: check based on suffix: e.g. Phosphorus
# Rename each column w/ units and write results as str
for col in results_cols:
Expand Down

0 comments on commit 7962e1c

Please sign in to comment.