diff --git a/dweather_client/client.py b/dweather_client/client.py index 3be1053..c05391c 100644 --- a/dweather_client/client.py +++ b/dweather_client/client.py @@ -18,8 +18,8 @@ from timezonefinder import TimezoneFinder from dweather_client import gridded_datasets from dweather_client.storms_datasets import IbtracsDataset, AtcfDataset, SimulatedStormsDataset -from dweather_client.ipfs_queries import AustraliaBomStations, CedaBiomass, CmeStationsDataset, DutchStationsDataset, DwdStationsDataset, DwdHourlyStationsDataset, GlobalHourlyStationsDataset, JapanStations, StationDataset, EauFranceDataset,\ - YieldDatasets, FsaIrrigationDataset, AemoPowerDataset, AemoGasDataset, AesoPowerDataset, ForecastDataset, AfrDataset, DroughtMonitor, CwvStations, SpeedwellStations, TeleconnectionsDataset, CsvStationDataset, StationForecastDataset, SapStations +from dweather_client.ipfs_queries import AustraliaBomStations, CedaBiomass, CmeStationsDataset, DutchStationsDataset, DwdStationsDataset, DwdHourlyStationsDataset, GlobalHourlyStationsDataset, JapanStations, StationDataset, EauFranceDataset, \ + YieldDatasets, FsaIrrigationDataset, AemoPowerDataset, AemoGasDataset, AesoPowerDataset, ForecastDataset, AfrDataset, DroughtMonitor, CwvStations, SpeedwellStations, TeleconnectionsDataset, CsvStationDataset, StationForecastDataset, SapStations, NQH2ODataset from dweather_client.slice_utils import DateRangeRetriever, has_changed from dweather_client.ipfs_errors import * from io import StringIO @@ -871,6 +871,11 @@ def get_afr_history(ipfs_timeout=None): return dataset_obj.get_data() +def get_nqh2o_history(ipfs_timeout=None): + with NQH2ODataset(ipfs_timeout=ipfs_timeout) as dataset_obj: + return dataset_obj.get_data() + + def has_dataset_updated(dataset, slices, as_of, ipfs_timeout=None): """ Determine whether any dataset updates generated after `as_of` affect any `slices` of date ranges. diff --git a/dweather_client/ipfs_queries.py b/dweather_client/ipfs_queries.py index edc0075..16bf8f0 100644 --- a/dweather_client/ipfs_queries.py +++ b/dweather_client/ipfs_queries.py @@ -1105,6 +1105,21 @@ def get_data(self): return ret_dict +class NQH2ODataset(IpfsDataset): + @property + def dataset(self): + return "NQH2O-weekly" + + def get_data(self): + super().get_data() + hashes = self.traverse_ll(self.head) + ret_dict = {} + for h in hashes: + f = self.get_file_object(f"{h}/NQH2O.json") + ret_dict = {**ret_dict, **json.load(f)} + return ret_dict + + class CedaBiomass(IpfsDataset): """ Instantiable class to pull CEDA biomass data diff --git a/dweather_client/tests/test_client.py b/dweather_client/tests/test_client.py index 911b409..261fc61 100644 --- a/dweather_client/tests/test_client.py +++ b/dweather_client/tests/test_client.py @@ -1,9 +1,9 @@ from dweather_client.ipfs_errors import * from dweather_client.tests.mock_fixtures import get_patched_datasets -from dweather_client.client import get_australia_station_history, get_station_history, get_gridcell_history, get_tropical_storms,\ - get_yield_history, get_irrigation_data, get_power_history, get_gas_history, get_alberta_power_history, GRIDDED_DATASETS, has_dataset_updated,\ - get_forecast_datasets, get_forecast, get_cme_station_history, get_european_station_history, get_hourly_station_history, get_drought_monitor_history, get_japan_station_history,\ - get_afr_history, get_cwv_station_history, get_teleconnections_history, get_station_forecast_history, get_station_forecast_stations, get_eaufrance_history, get_sap_station_history +from dweather_client.client import get_australia_station_history, get_station_history, get_gridcell_history, get_tropical_storms, \ + get_yield_history, get_irrigation_data, get_power_history, get_gas_history, get_alberta_power_history, GRIDDED_DATASETS, has_dataset_updated, \ + get_forecast_datasets, get_forecast, get_cme_station_history, get_european_station_history, get_hourly_station_history, get_drought_monitor_history, get_japan_station_history, \ + get_afr_history, get_cwv_station_history, get_teleconnections_history, get_station_forecast_history, get_station_forecast_stations, get_eaufrance_history, get_sap_station_history, get_nqh2o_history from dweather_client.aliases_and_units import snotel_to_ghcnd import pandas as pd from io import StringIO @@ -458,6 +458,11 @@ def test_afr(): assert len(afr_dict) >= 32 +def test_nqh2o(): + nqh2o_dict = get_nqh2o_history() + assert len(nqh2o_dict) >= 260 + + def test_drought_monitor(): drought_dict = get_drought_monitor_history( "48", "071", ipfs_timeout=IPFS_TIMEOUT)