diff --git a/harmonize_wq/clean.py b/harmonize_wq/clean.py index 347e1ab..4facd93 100644 --- a/harmonize_wq/clean.py +++ b/harmonize_wq/clean.py @@ -39,7 +39,8 @@ def datetime(df_in): ActivityStartDate ActivityStartTime/Time ActivityStartTime/TimeZoneCode 0 2004-09-01 10:01:00 EST 1 2004-07-01 NaN NaN - >>> harmonize_wq.clean.datetime(df) + >>> from harmonize_wq import clean + >>> clean.datetime(df) ActivityStartDate ... Activity_datetime 0 2004-09-01 ... 2004-09-01 15:01:00+00:00 1 2004-07-01 ... NaT @@ -95,11 +96,12 @@ def harmonize_depth(df_in, units='meter'): Get clean depth column: >>> from harmonize_wq import clean - >>> clean.harmonize_depth(df) - ResultDepthHeightMeasure/MeasureValue ... Depth - 0 3.0 ... 3.0 meter - 1 NaN ... NaN - 2 10 ... 3.0479999999999996 meter + >>> clean.harmonize_depth(df)[['ResultDepthHeightMeasure/MeasureValue', + ... 'Depth']] + ResultDepthHeightMeasure/MeasureValue Depth + 0 3.0 3.0 meter + 1 NaN NaN + 2 10 3.0479999999999996 meter """ df_out = df_in.copy() # Default columns diff --git a/harmonize_wq/convert.py b/harmonize_wq/convert.py index 8af96f5..3af9c94 100644 --- a/harmonize_wq/convert.py +++ b/harmonize_wq/convert.py @@ -381,7 +381,7 @@ def density_to_PSU(val, >>> from harmonize_wq import convert >>> convert.density_to_PSU(input_density) - 4.715428571428788 gram / kilogram + """ # Standard Reference Value ref = 35.16504/35.0 @@ -435,7 +435,7 @@ def PSU_to_density(val, >>> unit = ureg.Quantity('PSU') >>> unit - 1 Practical_Salinity_units + >>> type(unit) @@ -622,7 +622,7 @@ def conductivity_to_PSU(val, >>> from harmonize_wq import convert >>> convert.conductivity_to_PSU(input_conductivity) - 0.057 dimensionless + """ # Units wrapper returns magnitude only (faster) p, t = pressure, temperature diff --git a/harmonize_wq/domains.py b/harmonize_wq/domains.py index b042fee..04124d4 100644 --- a/harmonize_wq/domains.py +++ b/harmonize_wq/domains.py @@ -298,7 +298,7 @@ def bacteria_reg(ureg=None): Generate a new Pint unit registry object for e.g., bacteria >>> domains.bacteria_reg() - + """ if ureg is None: ureg = pint.UnitRegistry() diff --git a/harmonize_wq/location.py b/harmonize_wq/location.py index 82a3639..4f1b94a 100644 --- a/harmonize_wq/location.py +++ b/harmonize_wq/location.py @@ -138,15 +138,16 @@ def harmonize_locations(df_in, out_EPSG=4326, 0 27.595036 ... NAD83 1 27.521830 ... WGS84 2 28.066111 ... NAD27 - + [3 rows x 3 columns] - >>> harmonize_wq.location.harmonize_locations(df_in) + >>> from harmonize_wq import location + >>> location.harmonize_locations(df_in) LatitudeMeasure LongitudeMeasure ... QA_flag geometry 0 27.595036 -82.030086 ... NaN POINT (-82.03009 27.59504) 1 27.521830 -82.644760 ... NaN POINT (-82.64476 27.52183) 2 28.066111 -82.377500 ... NaN POINT (-82.37750 28.06611) - + [3 rows x 5 columns] Note: both geometries where the CRS was not the default 4326 (WGS1984) have diff --git a/harmonize_wq/visualize.py b/harmonize_wq/visualize.py index 107a307..d18699b 100644 --- a/harmonize_wq/visualize.py +++ b/harmonize_wq/visualize.py @@ -120,13 +120,14 @@ def map_counts(df_in, gdf, col=None): >>> import harmonize_wq >>> cnt_gdf = harmonize_wq.visualize.map_counts(df_in, gdf) >>> cnt_gdf - MonitoringLocationIdentifier cnt geometry QA_flag - 0 ID1 2 POINT (1.00000 2.00000) NaN - 1 ID2 1 POINT (2.00000 1.00000) NaN + MonitoringLocationIdentifier cnt geometry QA_flag + 0 ID1 2 POINT (1.00000 2.00000) NaN + 1 ID2 1 POINT (2.00000 1.00000) NaN These aggegate results can then be plotted: >>> cnt_gdf.plot(column='cnt', cmap='Blues', legend=True) + """ # Column for station loc_id = 'MonitoringLocationIdentifier' @@ -199,7 +200,7 @@ def map_measure(df_in, gdf, col): 0 ID1 NaN POINT (1.00000 2.00000) 1 ID2 NaN POINT (2.00000 1.00000) - Combine these to get an aggregation of results per station : + Combine these to get an aggregation of results per station: >>> from harmonize_wq import visualize >>> avg_temp = visualize.map_measure(df_in, gdf, 'Temperature') @@ -210,7 +211,8 @@ def map_measure(df_in, gdf, col): These aggegate results can then be plotted: - >>> avg_temp.plot(column='Temperature', cmap='Blues', legend=True) + >>> avg_temp.plot(column='mean', cmap='Blues', legend=True) + """ merge_cols = ['MonitoringLocationIdentifier'] diff --git a/harmonize_wq/wq_data.py b/harmonize_wq/wq_data.py index 50c3817..c9c0f8f 100644 --- a/harmonize_wq/wq_data.py +++ b/harmonize_wq/wq_data.py @@ -57,11 +57,9 @@ class WQCharData(): >>> from harmonize_wq import wq_data >>> wq = wq_data.WQCharData(df, 'Phosphorus') >>> wq.df - CharacteristicName ResultMeasure/MeasureUnitCode ... Units Phosphorus - 0 Phosphorus NaN ... NaN 1.0 - 1 Temperature, water NaN ... NaN NaN - - [2 rows x 5 columns] + CharacteristicName ResultMeasure/MeasureUnitCode ResultMeasureValue Units Phosphorus + 0 Phosphorus NaN 1.0 NaN 1.0 + 1 Temperature, water NaN 10.0 NaN NaN >>> wq.df.columns Index(['CharacteristicName', 'ResultMeasure/MeasureUnitCode', 'ResultMeasureValue', 'Units', 'Phosphorus'], @@ -297,7 +295,7 @@ def check_units(self, flag_col=None): >>> wq.check_units() UserWarning: WARNING: 'Unknown' UNDEFINED UNIT for Phosphorus - >>> wq.df[['CharacteristicName', 'Units']] + >>> wq.df[['CharacteristicName', 'Units', 'QA_flag']] CharacteristicName Units QA_flag 0 Phosphorus mg/l ResultMeasure/MeasureUnitCode: MISSING UNITS, ... 1 Temperature, water NaN NaN @@ -575,6 +573,9 @@ def apply_conversion(self, convert_fun, unit, u_mask=None): >>> wq = wq_data.WQCharData(df, 'Dissolved oxygen (DO)') >>> wq.apply_conversion(convert.DO_saturation, '%') >>> wq.df[['Units', 'DO']] + Units DO + 0 mg/l 1.000000 + 1 milligram / liter 0.826233 """ # TODO: QA flag inexact conversions? df_out = self.df @@ -632,7 +633,7 @@ def dimensions_list(self, m_mask=None): >>> wq = wq_data.WQCharData(df, 'Phosphorus') >>> wq.dimensions_list() - 'mg/kg' + ['mg/kg'] """ if m_mask is None: m_mask = self.measure_mask() @@ -679,10 +680,10 @@ def replace_unit_str(self, old, new, mask=None): 1 Temperature, water deg F ... deg F 87 >>> wq.replace_unit_str(' ', '') - >>> wq.df - CharacteristicName ResultMeasure/MeasureUnitCode ... Units Temperature - 0 Temperature, water deg C ... degC 31 - 1 Temperature, water deg F ... degF 87 + >>> wq.df[['ResultMeasure/MeasureUnitCode', 'Units', 'Temperature']] + ResultMeasure/MeasureUnitCode Units Temperature + 0 deg C degC 31 + 1 deg F degF 87 """ df_out = self.df if mask is None: diff --git a/harmonize_wq/wrangle.py b/harmonize_wq/wrangle.py index 28be8d7..6e92df6 100644 --- a/harmonize_wq/wrangle.py +++ b/harmonize_wq/wrangle.py @@ -585,7 +585,7 @@ def as_gdf(shp): >>> from harmonize_wq import wrangle >>> aoi_url = r'https://raw.githubusercontent.com/USEPA/harmonize-wq/main/harmonize_wq/tests/data/PPBays_NCCA.geojson' >>> type(wrangle.as_gdf(aoi_url)) - geopandas.geodataframe.GeoDataFrame + """ if not isinstance(shp, geopandas.geodataframe.GeoDataFrame): shp = geopandas.read_file(shp)