Skip to content

Commit

Permalink
doctests (should resolve some of the 43/329)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbousquin committed Sep 15, 2023
1 parent 0716072 commit a498f19
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
14 changes: 8 additions & 6 deletions harmonize_wq/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions harmonize_wq/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def density_to_PSU(val,
>>> from harmonize_wq import convert
>>> convert.density_to_PSU(input_density)
4.715428571428788 gram / kilogram
<Quantity(4.71542857, 'gram / kilogram')>
"""
# Standard Reference Value
ref = 35.16504/35.0
Expand Down Expand Up @@ -435,7 +435,7 @@ def PSU_to_density(val,
>>> unit = ureg.Quantity('PSU')
>>> unit
1 Practical_Salinity_units
<Quantity(1, 'Practical_Salinity_Units')>
>>> type(unit)
<class 'pint.Quantity'>
Expand Down Expand Up @@ -622,7 +622,7 @@ def conductivity_to_PSU(val,
>>> from harmonize_wq import convert
>>> convert.conductivity_to_PSU(input_conductivity)
0.057 dimensionless
<Quantity(0.057, 'dimensionless')>
"""
# Units wrapper returns magnitude only (faster)
p, t = pressure, temperature
Expand Down
2 changes: 1 addition & 1 deletion harmonize_wq/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def bacteria_reg(ureg=None):
Generate a new Pint unit registry object for e.g., bacteria
>>> domains.bacteria_reg()
<pint.registry.UnitRegistry at 0x237430e8370>
<pint.registry.UnitRegistry object at 0x000002BED1999880>
"""
if ureg is None:
ureg = pint.UnitRegistry()
Expand Down
7 changes: 4 additions & 3 deletions harmonize_wq/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,16 @@ def harmonize_locations(df_in, out_EPSG=4326,
0 27.595036 ... NAD83
1 27.521830 ... WGS84
2 28.066111 ... NAD27
<BLANKLINE>
[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)
<BLANKLINE>
[3 rows x 5 columns]
Note: both geometries where the CRS was not the default 4326 (WGS1984) have
Expand Down
12 changes: 7 additions & 5 deletions harmonize_wq/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<Axes: >
"""
# Column for station
loc_id = 'MonitoringLocationIdentifier'
Expand Down Expand Up @@ -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')
Expand All @@ -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)
<Axes: >
"""

merge_cols = ['MonitoringLocationIdentifier']
Expand Down
23 changes: 12 additions & 11 deletions harmonize_wq/wq_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<BLANKLINE>
[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'],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion harmonize_wq/wrangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<class 'geopandas.geodataframe.GeoDataFrame'>
"""
if not isinstance(shp, geopandas.geodataframe.GeoDataFrame):
shp = geopandas.read_file(shp)
Expand Down

0 comments on commit a498f19

Please sign in to comment.