-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
)) |