Other Features¶
What haven’t we covered¶
Saving data¶
[1]:
# we need imports
from datetime import datetime
import pandas as pd
from metloom.pointdata import CDECPointData
from metloom.variables import CdecStationVariables, SensorDescription
[2]:
# Let's save some timeseries data
pt = CDECPointData("SLI", "Slide Canyon")
# start data and end date
start_date = datetime(2019, 3, 1)
end_date = datetime(2019, 4, 1)
variables = [pt.ALLOWED_VARIABLES.SNOWDEPTH]
# request the data
df = pt.get_daily_data(start_date, end_date, variables)
df.head(10)
df.to_csv("./data/sli_data.csv")
# if you want to read it back in
df2 = pd.read_csv("./data/sli_data.csv")
df2.head(10)
[2]:
| datetime | site | geometry | SNOWDEPTH | SNOWDEPTH_units | datasource | |
|---|---|---|---|---|---|---|
| 0 | 2019-03-01 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 128 | INCHES | CDEC |
| 1 | 2019-03-02 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 131 | INCHES | CDEC |
| 2 | 2019-03-03 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 137 | INCHES | CDEC |
| 3 | 2019-03-04 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 135 | INCHES | CDEC |
| 4 | 2019-03-05 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 133 | INCHES | CDEC |
| 5 | 2019-03-06 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 139 | INCHES | CDEC |
| 6 | 2019-03-07 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 145 | INCHES | CDEC |
| 7 | 2019-03-08 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 144 | INCHES | CDEC |
| 8 | 2019-03-09 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 142 | INCHES | CDEC |
| 9 | 2019-03-10 08:00:00+00:00 | SLI | POINT Z (-119.431881 38.091234 9200) | 144 | INCHES | CDEC |
[3]:
# Imports
import geopandas as gpd
from pathlib import Path
from metloom.pointdata import SnotelPointData
[4]:
# Let's save some points
# Find your area
sf_path = Path("./data/outline.shp").expanduser()
sf = gpd.read_file(str(sf_path))
variables = [SnotelPointData.ALLOWED_VARIABLES.SNOWDEPTH]
points = SnotelPointData.points_from_geometry(sf, variables)
# convert to geodataframe and save
points_df = points.to_dataframe()
points_df.to_file("./data/my_points.geojson")
/home/docs/checkouts/readthedocs.org/user_builds/metloom/envs/stable/lib/python3.10/site-packages/pyogrio/geopandas.py:917: UserWarning: 'crs' was not provided. The output dataset will not have projection information defined and may not be usable in other systems.
write(
Extending classes¶
What if we want a new variable?
[5]:
# Extend the variables to add our new sensor(s)
# http://cdec4gov.water.ca.gov/reportapp/javareports?name=SensList
class ExtendedCDECVars(CdecStationVariables):
PEAKGUST = SensorDescription("77", "WIND GUST", "WIND, PEAK GUST")
# Extend the class to redefine the varaibles
class ExtendedCDECPoints(CDECPointData):
ALLOWED_VARIABLES = ExtendedCDECVars
[6]:
# use our new class to retrieve the data
pt = ExtendedCDECPoints("GIN", "Gin Flat")
data = pt.get_daily_data(start_date, end_date, [pt.ALLOWED_VARIABLES.PEAKGUST])
data
[6]:
| geometry | WIND GUST | WIND GUST_units | datasource | ||
|---|---|---|---|---|---|
| datetime | site | ||||
| 2019-03-01 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 4.166667 | MPH | CDEC |
| 2019-03-02 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 3.235294 | MPH | CDEC |
| 2019-03-03 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 4.291667 | MPH | CDEC |
| 2019-03-04 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 3.086957 | MPH | CDEC |
| 2019-03-05 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 54.600000 | MPH | CDEC |
| 2019-03-06 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 5.869565 | MPH | CDEC |
| 2019-03-07 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 5.166667 | MPH | CDEC |
| 2019-03-08 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.100000 | MPH | CDEC |
| 2019-03-09 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 4.625000 | MPH | CDEC |
| 2019-03-10 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.666667 | MPH | CDEC |
| 2019-03-11 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 1.750000 | MPH | CDEC |
| 2019-03-12 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.958333 | MPH | CDEC |
| 2019-03-13 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.750000 | MPH | CDEC |
| 2019-03-14 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.826087 | MPH | CDEC |
| 2019-03-15 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.541667 | MPH | CDEC |
| 2019-03-16 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.363636 | MPH | CDEC |
| 2019-03-17 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.782609 | MPH | CDEC |
| 2019-03-18 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.541667 | MPH | CDEC |
| 2019-03-19 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 3.545455 | MPH | CDEC |
| 2019-03-20 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.181818 | MPH | CDEC |
| 2019-03-21 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.083333 | MPH | CDEC |
| 2019-03-22 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 1.125000 | MPH | CDEC |
| 2019-03-23 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 1.958333 | MPH | CDEC |
| 2019-03-24 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.375000 | MPH | CDEC |
| 2019-03-25 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 4.750000 | MPH | CDEC |
| 2019-03-26 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 3.791667 | MPH | CDEC |
| 2019-03-27 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 3.631579 | MPH | CDEC |
| 2019-03-28 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.347826 | MPH | CDEC |
| 2019-03-29 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 2.458333 | MPH | CDEC |
| 2019-03-30 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 1.500000 | MPH | CDEC |
| 2019-03-31 08:00:00+00:00 | GIN | POINT Z (-119.77491 37.76689 7050) | 1.583333 | MPH | CDEC |
mesowest¶
Mesowest is a great resource to find an even wider selection of sensors.
The metloom documentation has instructions for setting up your free API token that allows you to read data from the mesonet API with the MesowestPointData class.
See the resources below:
https://metloom.readthedocs.io/en/latest/usage.html#mesowest
https://developers.synopticdata.com/mesonet/
[ ]: