Skip to content

Commit d222d2a

Browse files
committed
add 3 rma yield datasets
1 parent 10b2c25 commit d222d2a

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

dweather_client/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from timezonefinder import TimezoneFinder
1313
from dweather_client import gridded_datasets
1414
from dweather_client.storms_datasets import IbtracsDataset, AtcfDataset, SimulatedStormsDataset
15-
from dweather_client.ipfs_queries import StationDataset, ScoYieldDataset, AemoPowerDataset, AemoGasDataset
15+
from dweather_client.ipfs_queries import StationDataset, YieldDatasets, AemoPowerDataset, AemoGasDataset
1616
from dweather_client.ipfs_errors import *
1717
import ipfshttpclient
1818

@@ -216,7 +216,7 @@ def get_station_history(
216216

217217
return history
218218

219-
def get_yield_history(commodity, state, county, ipfs_timeout=None):
219+
def get_yield_history(commodity, state, county, dataset="sco-yearly", ipfs_timeout=None):
220220
"""
221221
return:
222222
string containing yield data in csv format
@@ -228,8 +228,10 @@ def get_yield_history(commodity, state, county, ipfs_timeout=None):
228228
You can look up code values at:
229229
https://webapp.rma.usda.gov/apps/RIRS/AreaPlanHistoricalYields.aspx
230230
"""
231+
if "imputed" in dataset and commodity != "0081":
232+
raise ValueError("Imputed currently only available for soybeans (commodity code 0081)")
231233
try:
232-
return ScoYieldDataset(ipfs_timeout=ipfs_timeout).get_data(commodity, state, county)
234+
return YieldDatasets(dataset, ipfs_timeout=ipfs_timeout).get_data(commodity, state, county)
233235
except ipfshttpclient.exceptions.ErrorResponse:
234236
raise ValueError("Invalid commodity/state/county code combination")
235237

dweather_client/ipfs_queries.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,20 +385,33 @@ def get_data(self, station):
385385
with gzip.open(self.get_file_object(file_name)) as gz:
386386
return gz.read().decode('utf-8')
387387

388-
class ScoYieldDataset(IpfsDataset):
388+
class YieldDatasets(IpfsDataset):
389389
"""
390-
Instantiable class used for pulling in "ghcnd" or "ghcnd-imputed-daily" station data
390+
Instantiable class used for pulling in sco and rma transitional yield data
391391
"""
392392
@property
393393
def dataset(self):
394-
return "sco-yearly"
394+
return self._dataset
395+
396+
def __init__(self, dataset, ipfs_timeout=None):
397+
if dataset not in {
398+
"sco-yearly",
399+
"rmasco_imputed-yearly",
400+
"rma_t_yield-single-value",
401+
"rma_t_yield_imputed-single-value"
402+
}:
403+
raise ValueError("Invalid yield dataset")
404+
super().__init__(ipfs_timeout=ipfs_timeout)
405+
self._dataset = dataset
395406

396407
def get_data(self, commodity, state, county):
397408
super().get_data()
398-
file_name = f"{self.head}/{commodity}-{state}-{county}.csv"
409+
if "imputed" in self.dataset:
410+
file_name = f"{self.head}/{state}-{county}.csv"
411+
else:
412+
file_name = f"{self.head}/{commodity}-{state}-{county}.csv"
399413
return self.get_file_object(file_name).read().decode("utf-8")
400414

401-
402415
class AemoDataset(IpfsDataset):
403416
"""
404417
Abstract class from which all AEMO datasets inherit
@@ -431,7 +444,6 @@ def get_data(self):
431444
ret_dict = {**ret_dict, **new_dict}
432445
return ret_dict
433446

434-
435447
class AemoPowerDataset(AemoDataset):
436448
"""
437449
Instantiable class for AEMO Victoria power data

0 commit comments

Comments
 (0)