Skip to content

Commit

Permalink
EPA WQX domain values service
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Apr 20, 2017
1 parent ebd841a commit e926c92
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Available Services
Module Classes Data Source Agency/Org.
=================== ================================================================ ============== ============
climata.acis_ ``StationMetaIO``, ``StationDataIO`` ACIS_ NOAA RCCs
climata.epa_ ``WqxDomainIO`` WQX_ EPA
climata.cocorahs_ ``CocorahsIO`` CoCoRaHS_ CoCoRaHS
climata.hydromet_ ``DailyDataIO``, ``InstantDataIO``, ``AgrimetRecentIO`` Hydromet_ USBR
climata.nws_ ``HydroForecastIO``, ``EnsembleForecastIO``, ``EnsembleSiteIO`` CNRFC_ NWS
Expand Down Expand Up @@ -104,12 +105,14 @@ More Python code examples are available via the `climata-viewer website`_.

.. _ACIS: http://data.rcc-acis.org/
.. _CoCoRaHS: http://data.cocorahs.org/cocorahs/export/exportmanager.aspx
.. _WQX: https://www3.epa.gov/storet/wqx/wqx_getdomainvalueswebservice.html
.. _Hydromet: http://www.usbr.gov/pn/hydromet/arcread.html
.. _CNRFC: http://www.cnrfc.noaa.gov/
.. _SNOTEL AWDB: http://www.wcc.nrcs.usda.gov/web_service/awdb_web_service_landing.htm
.. _NWIS: http://waterdata.usgs.gov/nwis
.. _climata.acis: https://github.com/heigeo/climata/blob/master/climata/acis/__init__.py
.. _climata.cocorahs: https://github.com/heigeo/climata/blob/master/climata/cocorahs/__init__.py
.. _climata.epa: https://github.com/heigeo/climata/blob/master/climata/epa/__init__.py
.. _climata.hydromet: https://github.com/heigeo/climata/blob/master/climata/hydromet/__init__.py
.. _climata.nws: https://github.com/heigeo/climata/blob/master/climata/nws/__init__.py
.. _climata.snotel: https://github.com/heigeo/climata/blob/master/climata/snotel/__init__.py
Expand Down
55 changes: 55 additions & 0 deletions climata/epa/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from wq.io import BaseIO, TimeSeriesMapper, XmlParser
from climata.base import ZipWebserviceLoader, FilterOpt, DateOpt, ChoiceOpt
from .constants import DOMAINS


class WqxDomainIO(ZipWebserviceLoader, XmlParser, TimeSeriesMapper, BaseIO):
"""
Load WQX / STORET domain values from EPA web services.
Usage:
chars = WqxDomainIO(domain='Characteristic')
for char in chars:
print char.picklist, char.name
"""

# Override Default WebserviceLoader options
start_date = DateOpt(ignored=True)
end_date = DateOpt(ignored=True)
state = FilterOpt(ignored=True)
basin = FilterOpt(ignored=True)
county = FilterOpt(ignored=True)
station = FilterOpt(ignored=True)
parameter = FilterOpt(ignored=True)

# Custom Loader options
domain = ChoiceOpt(choices=DOMAINS, required=True)
base_url = 'http://cdx.epa.gov/wqx/download/DomainValues/'

@property
def url(self):
domain = self.getvalue('domain')
if domain == 'CharacteristicWithPickList':
domain = 'ResultMeasureValuePickList'
return self.base_url + domain + '.zip'

@property
def params(self):
return {}

# Custom Parser options
ns = '{http://www.exchangenetwork.net/schema/wqx/2}'
root_tag = ns + 'WQXElement'
item_tag = ns + 'WQXElementRow'

def parse_item(self, el):
return {
e.attrib['colname']: e.attrib['value']
for e in el.findall(self.ns + 'WQXElementRowColumn')
}

# Custom Mapper options
date_formats = ['iso8601']
map_floats = False
scan_fields = True
60 changes: 60 additions & 0 deletions climata/epa/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
DOMAINS = (
'ActivityGroupType',
'ActivityMedia',
'ActivityMediaSubdivision',
'ActivityRelativeDepth',
'ActivityType',
'AddressType',
'AnalyticalMethod',
'AnalyticalMethodContext',
'Assemblage',
'BiologicalIntent',
'CellForm',
'CellShape',
'Characteristic',
'CharacteristicWithPickList',
'Country',
'County',
'DetectionQuantitationLimitType',
'ElectronicAddressType',
'FrequencyClassDescriptor',
'Habit',
'HorizontalCollectionMethod',
'HorizontalCoordinateReferenceSystemDatum',
'MeasureUnit',
'MethodSpeciation',
'MetricType',
'MetricTypeContext',
'MonitoringLocationType',
'NetType',
'Organization',
'ReferenceLocationType',
'ResultDetectionCondition',
'ResultLaboratoryComment',
'ResultMeasureQualifier',
'ResultMeasureValuePickList',
'ResultSampleFraction',
'ResultStatus',
'ResultTemperatureBasis',
'ResultTimeBasis',
'ResultValueType',
'ResultWeightBasis',
'SampleCollectionEquipment',
'SampleContainerColor',
'SampleContainerType',
'SampleTissueAnatomy',
'SamplingDesignType',
'State',
'StatisticalBase',
'Taxon',
'TelephoneNumberType',
'TimeZone',
'ThermalPreservativeUsed',
'ToxicityTestType',
'Tribe',
'VerticalCollectionMethod',
'VerticalCoordinateReferenceSystemDatum',
'Voltinism',
'WellFormationType',
'WellType',
)
16 changes: 16 additions & 0 deletions tests/test_epa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .base import ClimataTestCase
from climata.epa import WqxDomainIO


class EpaTestCase(ClimataTestCase):
module = "epa"

def test_domain(self):
data = WqxDomainIO(
domain='Characteristic',
)
self.assertGreater(len(data), 0)
item = data[0]
self.assertHasFields(item, (
"name", "picklist", "samplefractionrequired", "lastchangedate"
))

0 comments on commit e926c92

Please sign in to comment.