diff --git a/src/synoptic/params.py b/src/synoptic/params.py index 148c27d..011dbc5 100644 --- a/src/synoptic/params.py +++ b/src/synoptic/params.py @@ -99,6 +99,45 @@ } ) +params_percentiles = ( + station_selectors + | {"token"} + | { + "vars", + "data", + "complete", + "daily_min", + "daily_max", + "obtimezone", # IGNORED + "hourly", + "start", + "end", + "percentiles", + "complete", + "fields", + "showemptystations", + "showemptyvars", + "units", + "sitinghistory", + } +) +params_statistics = ( + station_selectors + | {"token", "start", "end", "recent"} + | { + "vars", + "period", + "statistic", + "complete", + "fields", + "obtimezone", # IGNORED + "showemptystations", + "showemptyvars", + "units", + "sitinghistory", + } +) + params_qcsegments = ( station_selectors | {"token", "start", "end", "recent"} @@ -148,6 +187,8 @@ def validate_params(service, **params): "latest": params_latest, "nearesttime": params_nearesttime, "precipitation": params_precipitation, + "percentiles": params_percentiles, + "statistics": params_statistics, "qcsegments": params_qcsegments, "latency": params_latency, "metadata": params_metadata, diff --git a/src/synoptic/services.py b/src/synoptic/services.py index fa21bcd..1c1359f 100644 --- a/src/synoptic/services.py +++ b/src/synoptic/services.py @@ -34,6 +34,8 @@ "latest", "nearesttime", "precipitation", + "statistics", + "percentiles", "qcsegments", "latency", "metadata", @@ -52,6 +54,8 @@ "latest", "nearesttime", "precipitation", + "statistics", + "percentiles", "qcsegments", "latency", "metadata", @@ -488,6 +492,52 @@ def df(self) -> pl.DataFrame: return df +class Percentiles(SynopticAPI): + """ + Request station percentiles. + + Refer to the official documentation: https://docs.synopticdata.com/services/percentiles + + + Parameters + ---------- + # TODO: I can't develop this capability because + # TODO: "Account associated with this token does not have access to the statistics service." + """ + + def __init__(self, **params): + super().__init__("percentiles", **params) + + @lru_cache + def df(self) -> pl.DataFrame: + """Stations percentile DataFrame.""" + timer = datetime.now() + self.timers["parse_to_polars_dataframe"] = datetime.now() - timer + + +class Statistics(SynopticAPI): + """ + Request station statistics. + + Refer to the official documentation: https://docs.synopticdata.com/services/statistics + + + Parameters + ---------- + # TODO: I can't develop this capability because + # TODO: "Account associated with this token does not have access to the statistics service." + """ + + def __init__(self, **params): + super().__init__("statistics", **params) + + @lru_cache + def df(self) -> pl.DataFrame: + """Stations statistics DataFrame.""" + timer = datetime.now() + self.timers["parse_to_polars_dataframe"] = datetime.now() - timer + + class QCSegments(SynopticAPI): """Get quality control segments. NOT IMPLEMENTED.