NearestTime#

Demonstrate synoptic.services.NearestTime

This is very similar to the Latest service, except you can specify the date/time you want the closest time to.

[2]:
from synoptic import NearestTime

import matplotlib.pyplot as plt
from datetime import datetime, timedelta
[3]:
df = NearestTime(
    attime=datetime(2024, 1, 1),
    within=timedelta(hours=1),
    bbox=[-120, 40, -119, 41],
    showemptystations=True,
    vars="air_temp",
    units="english",
).df()
df
πŸššπŸ’¨ Speedy delivery from Synoptic's nearesttime service.
πŸ“¦ Received data from 12 stations (1.32 seconds).
[3]:
shape: (12, 22)
stidvariablesensor_indexis_derivedvaluedate_timeunitsidnameelevationlatitudelongitudemnet_idstatetimezoneelev_demperiod_of_record_startperiod_of_record_endqc_flaggedis_restrictedrestricted_metadatais_active
strstru32boolf64datetime[ΞΌs, UTC]stru32strf64f64f64u32strstrf64datetime[ΞΌs, UTC]datetime[ΞΌs, UTC]boolboolboolbool
"BLUN2""air_temp"1false44.02023-12-31 23:37:00 UTC"Fahrenheit"2169"BLUEWING MOUNTAIN"4570.040.50147-119.121612"NV""America/Los_Angeles"4655.51998-07-28 00:00:00 UTC2024-12-19 05:37:00 UTCfalsefalsefalsetrue
"BUFN2""air_temp"1false44.02023-12-31 23:59:00 UTC"Fahrenheit"2171"BUFFALO CREEK"3940.040.58058-119.788812"NV""America/Los_Angeles"3917.31998-07-28 00:00:00 UTC2024-12-19 05:59:00 UTCfalsefalsefalsetrue
"D1623"nullnullnullnullnullnull24903"DW1623 Gerlach"3947.040.65133-119.3551765"NV""America/Los_Angeles"3950.12008-11-05 00:00:00 UTC2012-11-22 12:44:00 UTCnullfalsefalsefalse
"UP973"nullnullnullnullnullnull35321"PHIL"3998.040.62174-119.4138464"NV""America/Los_Angeles"3930.42013-01-04 00:00:00 UTC2024-12-19 05:40:00 UTCnullfalsefalsetrue
"UP974"nullnullnullnullnullnull35322"TREGO"4005.040.78996-119.0708864"NV""America/Los_Angeles"3937.02013-01-04 00:00:00 UTC2024-12-19 04:29:00 UTCfalsefalsefalsetrue
"UP999""air_temp"1false45.02023-12-31 23:21:00 UTC"Fahrenheit"35347"REYNRD"3880.040.53186-119.6135464"NV""America/Los_Angeles"3874.72013-01-04 00:00:00 UTC2024-12-19 05:04:00 UTCfalsefalsefalsetrue
"NHUA""air_temp"1false43.212024-01-01 00:00:00 UTC"Fahrenheit"41973"Hualapai Flat"4055.040.90111-119.3330662"NV""America/Los_Angeles"4081.42013-12-19 00:00:00 UTC2024-01-01 07:20:00 UTCfalsefalsefalsefalse
"COOPGERN2"nullnullnullnullnullnull57082"GERLACH"3954.040.6517-119.357973"NV""America/Los_Angeles"3927.22016-07-18 18:18:00 UTC2019-05-17 16:00:00 UTCnullfalsefalsefalse
"F0371""air_temp"1false44.02024-01-01 00:00:00 UTC"Fahrenheit"61916"FW0371 Gerlach"3953.040.65176-119.3579965"NV""America/Los_Angeles"3963.32017-02-12 08:19:00 UTC2024-12-15 18:45:00 UTCfalsefalsefalsetrue
"G2749"nullnullnullnullnullnull181031"GW2749 Gerlach"4028.040.85933-119.3418365"NV""America/Los_Angeles"4022.32023-01-03 22:09:00 UTC2024-12-19 06:00:00 UTCnullfalsefalsetrue
[4]:
fig, ax = plt.subplots(1, 1, figsize=(10, 10))

for i in df.iter_rows(named=True):
    ax.text(
        i["longitude"],
        i["latitude"] + 0.01,
        f'{i["stid"]}\n{i["value"]} F',
        va="bottom",
        ha="left",
    )
    if i["value"] is None:
        art = ax.scatter(
            i["longitude"],
            i["latitude"],
            color=None,
            ec="k",
            s=100,
        )
    else:
        art = ax.scatter(
            i["longitude"],
            i["latitude"],
            c=i["value"],
            ec="k",
            cmap="Spectral_r",
            vmin=20,
            vmax=80,
            s=100,
        )
plt.colorbar(art, ax=ax, location="bottom", pad=0.05, label="Air Temperature (F)")
[4]:
<matplotlib.colorbar.Colorbar at 0x7fcb9ccf0da0>
../../_images/user_guide_services_tutorials_NearestTime_3_1.png