TimeSeries#

Demonstrate using the TimeSeries service.

[1]:
from datetime import datetime, timedelta

import matplotlib.pyplot as plt
import polars as pl
import seaborn as sns

import synoptic

Single Station, multi-variable#

[3]:
df = synoptic.TimeSeries(
    stid="ukbkb",
    recent=timedelta(hours=24),
    vars="air_temp,dew_point_temperature",
    units="english",
).df()

plt.figure(figsize=(10, 5))
ax = sns.lineplot(
    df,
    x="date_time",
    y="value",
    hue="variable",
    marker=".",
    palette=["tab:red", "tab:green"],
)
ax.set_title(f"{df['stid'][0]}: {df['name'][0]}")
ax.set_ylabel("Temperature (°F)")
ax.set_xlabel("")
ax.grid(alpha=0.5, zorder=0, lw=0.5, ls="--")
ax.legend(title="")

df.head()
🚚💨 Speedy delivery from Synoptic's timeseries service.
📦 Received data from 1 stations (0.27 seconds).
[3]:
shape: (5, 21)
stiddate_timevariablesensor_indexis_derivedvalueunitsidnameelevationlatitudelongitudemnet_idstatetimezoneelev_demperiod_of_record_startperiod_of_record_endqc_flaggedis_restrictedis_active
strdatetime[μs, UTC]stru32boolf64stru32strf64f64f64u32strstrf64datetime[μs, UTC]datetime[μs, UTC]boolboolbool
"UKBKB"2024-12-11 05:00:00 UTC"air_temp"1false26.0"Fahrenheit"37032"EW2355 Spanish Fork"4734.040.09867-111.6276765"UT""America/Denver"4740.82013-03-13 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"UKBKB"2024-12-11 05:15:00 UTC"air_temp"1false26.0"Fahrenheit"37032"EW2355 Spanish Fork"4734.040.09867-111.6276765"UT""America/Denver"4740.82013-03-13 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"UKBKB"2024-12-11 05:30:00 UTC"air_temp"1false26.0"Fahrenheit"37032"EW2355 Spanish Fork"4734.040.09867-111.6276765"UT""America/Denver"4740.82013-03-13 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"UKBKB"2024-12-11 05:45:00 UTC"air_temp"1false26.0"Fahrenheit"37032"EW2355 Spanish Fork"4734.040.09867-111.6276765"UT""America/Denver"4740.82013-03-13 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"UKBKB"2024-12-11 06:00:00 UTC"air_temp"1false25.0"Fahrenheit"37032"EW2355 Spanish Fork"4734.040.09867-111.6276765"UT""America/Denver"4740.82013-03-13 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
../../_images/user_guide_services_tutorials_TimeSeries_3_2.png

Single variable, multi-station#

[4]:
df = synoptic.TimeSeries(
    stid="kslc,kmry,klas",
    recent=timedelta(hours=24),
    vars="air_temp",
    units="english",
).df()

plt.figure(figsize=(10, 5))
ax = sns.lineplot(
    df,
    x="date_time",
    y="value",
    hue="stid",
    marker=".",
)
ax.set_title("Air Temperature")
ax.set_ylabel("Temperature (°F)")
ax.set_xlabel("")
ax.grid(alpha=0.5, zorder=0, lw=0.5, ls="--")
ax.legend(title="")

df.head()
🚚💨 Speedy delivery from Synoptic's timeseries service.
📦 Received data from 3 stations (6.25 seconds).
[4]:
shape: (5, 21)
stiddate_timevariablesensor_indexis_derivedvalueunitsidnameelevationlatitudelongitudemnet_idstatetimezoneelev_demperiod_of_record_startperiod_of_record_endqc_flaggedis_restrictedis_active
strdatetime[μs, UTC]stru32boolf64stru32strf64f64f64u32strstrf64datetime[μs, UTC]datetime[μs, UTC]boolboolbool
"KSLC"2024-12-11 04:54:00 UTC"air_temp"1false28.94"Fahrenheit"53"Salt Lake City, Salt Lake City…4226.040.77069-111.965031"UT""America/Denver"4235.61997-01-01 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"KSLC"2024-12-11 04:55:00 UTC"air_temp"1false28.94"Fahrenheit"53"Salt Lake City, Salt Lake City…4226.040.77069-111.965031"UT""America/Denver"4235.61997-01-01 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"KSLC"2024-12-11 05:00:00 UTC"air_temp"1false28.94"Fahrenheit"53"Salt Lake City, Salt Lake City…4226.040.77069-111.965031"UT""America/Denver"4235.61997-01-01 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"KSLC"2024-12-11 05:05:00 UTC"air_temp"1false28.4"Fahrenheit"53"Salt Lake City, Salt Lake City…4226.040.77069-111.965031"UT""America/Denver"4235.61997-01-01 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
"KSLC"2024-12-11 05:10:00 UTC"air_temp"1false28.94"Fahrenheit"53"Salt Lake City, Salt Lake City…4226.040.77069-111.965031"UT""America/Denver"4235.61997-01-01 00:00:00 UTC2024-12-12 04:30:00 UTCfalsefalsetrue
../../_images/user_guide_services_tutorials_TimeSeries_5_2.png