From 7962e1c210469074e9fff0692c6c98f89df3f781 Mon Sep 17 00:00:00 2001 From: Bousquin Date: Thu, 11 Apr 2024 14:03:22 -0500 Subject: [PATCH] Updated implementations of the dicts vs functions. --- harmonize_wq/clean.py | 2 +- harmonize_wq/domains.py | 9 +++++---- harmonize_wq/location.py | 4 ++-- harmonize_wq/wrangle.py | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/harmonize_wq/clean.py b/harmonize_wq/clean.py index 52ac28e..4007527 100644 --- a/harmonize_wq/clean.py +++ b/harmonize_wq/clean.py @@ -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 diff --git a/harmonize_wq/domains.py b/harmonize_wq/domains.py index dd9e110..85a258b 100644 --- a/harmonize_wq/domains.py +++ b/harmonize_wq/domains.py @@ -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 = { @@ -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, }, } @@ -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 = { diff --git a/harmonize_wq/location.py b/harmonize_wq/location.py index 791735c..bc545a8 100644 --- a/harmonize_wq/location.py +++ b/harmonize_wq/location.py @@ -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 diff --git a/harmonize_wq/wrangle.py b/harmonize_wq/wrangle.py index 68916e8..799308f 100644 --- a/harmonize_wq/wrangle.py +++ b/harmonize_wq/wrangle.py @@ -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 @@ -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} @@ -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: