Skip to content

Commit

Permalink
update acis scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 13, 2014
1 parent 9ac3941 commit fac24d9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
15 changes: 9 additions & 6 deletions climata/acis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from .constants import *


class ParameterOpt(ChoiceOpt):
multi = True
url_param = 'elems'
choices = ELEMENT_BY_ID.keys() + ELEMENT_BY_NAME.keys()


class AcisIO(WebserviceLoader, JsonParser, TupleMapper, BaseIO):
"""
Base class for loading data from ACIS web services
Expand All @@ -20,12 +26,6 @@ class AcisIO(WebserviceLoader, JsonParser, TupleMapper, BaseIO):
county = FilterOpt(multi=True)
basin = FilterOpt(multi=True)
station = FilterOpt(ignored=True)
parameter = ChoiceOpt(
required=True,
multi=True,
url_param='elems',
choices=ELEMENT_BY_ID.keys() + ELEMENT_BY_NAME.keys(),
)

# Additional ACIS-specific option
meta = ChoiceOpt(
Expand Down Expand Up @@ -68,6 +68,7 @@ class StationMetaIO(AcisIO):
# These options are not required for StationMetaIO
start_date = DateOpt(url_param='sdate')
end_date = DateOpt(url_param='edate')
parameter = ParameterOpt()

def parse(self):
"""
Expand Down Expand Up @@ -131,6 +132,8 @@ class StationDataIO(StationMetaIO):
start_date = DateOpt(required=True, url_param='sdate')
end_date = DateOpt(required=True, url_param='edate')

parameter = ParameterOpt(required=True)

# Additional information for daily results
add = ChoiceOpt(multi=True, choices=ADD_IDS)

Expand Down
10 changes: 6 additions & 4 deletions climata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,18 @@ def get_filter_options(cls):
"""
List all filter options defined on class (and superclasses)
"""
if hasattr(cls, '_filter_options'):
return cls._filter_options
attr = '_filter_options_%s' % id(cls)

options = getattr(cls, attr, {})
if options:
return options

options = {}
for key in dir(cls):
val = getattr(cls, key)
if isinstance(val, FilterOpt):
options[key] = val

cls._filter_options = options
setattr(cls, attr, options)
return options

@property
Expand Down
6 changes: 1 addition & 5 deletions climata/bin/acis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ def load_data(basin, elem, syear=1950, eyear=curyear,
seen_auths.add(auth)

# Sort sites by longitude
include_sites = sorted(include_sites, key=lambda s: s.ll[0])
include_sites = sorted(include_sites, key=lambda s: s.longitude)
seen_auths = sorted(seen_auths)

def get_val(site, field):
if hasattr(site, field):
return getattr(site, field)
elif field == "latitude":
return site.ll[1]
elif field == "longitude":
return site.ll[0]
else:
return site.sids.get(field, "")

Expand Down
4 changes: 2 additions & 2 deletions climata/bin/acis_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def load_sites(*basin_ids):
print ",".join(map(str,
[site.uid, site.name]
+ [site.sids.get(auth, "") for auth in seen_auths]
+ [site.ll[1], site.ll[0]]
+ [site.latitude, site.longitude]
+ [start.date(), end.date(), years]
+ elem_ranges
))
Expand All @@ -110,7 +110,7 @@ def load_sites(*basin_ids):
print ",".join(map(str,
[site.uid, site.name]
+ [site.sids.get(auth, "") for auth in seen_auths]
+ [site.ll[1], site.ll[0]]
+ [site.latitude, site.longitude]
+ ["NO DATA"]
))

Expand Down

0 comments on commit fac24d9

Please sign in to comment.