Skip to main content

metloom

https://img.shields.io/pypi/v/metloom.svg Testing Status Documentation Status Code Coverage

Location Oriented Observed Meteorology

metloom is a python library created with the goal of consistent, simple sampling of meteorology and snow related point measurments from a variety of datasources is developed by M3 Works as a tool for validating computational hydrology model results. Contributions welcome!

Warning - This software is provided as is (see the license), so use at your own risk. This is an opensource package with the goal of making data wrangling easier. We make no guarantees about the quality or accuracy of the data and any interpretation of the meaning of the data is up to you.

  • Free software: BSD license

# Find your data with ease
# !pip install folium mapclassify matplotlib
from metloom.pointdata import SnotelPointData, CDECPointData, USGSPointData
import geopandas as gpd
import pandas as pd

# Shapefile for the US states
shp = gpd.read_file('https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_040_00_500k.json').to_crs("EPSG:4326")
# Filter to states of interest
west_states = ["Washington", "Oregon", "California", "Idaho", "Nevada", "Utah", "Wyoming", "Montana", "Colorado" ]  # , "Arizona", "New Mexico"]
shp = shp.loc[shp["NAME"].isin(west_states)].dissolve()

# Collect all points with SWE from CDEC and NRCS
dfs = []
for src in  [CDECPointData, SnotelPointData]:
    dfs.append(src.points_from_geometry(shp, [src.ALLOWED_VARIABLES.SWE]).to_dataframe())
# Combine dataframes
gdf = pd.concat(dfs)
# plot the shapefile
m = shp.explore(
    tooltip=False, color="grey", highlight=False, style_kwds={"opacity": 0.2}, popup=["NAME"]
)
# plot the points on top of the shapefile
gdf.explore(m=m, tooltip=["name", "id", "datasource"], color="red", marker_kwds={"radius":4})
Resulting plot of SWE trace at Banner summit

Features

# !pip install plotly
from metloom.pointdata import SnotelPointData
import plotly.express as px
import pandas as pd

# Initialize your point
pt = SnotelPointData("312:ID:SNTL", "Banner Summit")
swe_variable = pt.ALLOWED_VARIABLES.SWE
# Get the data
df = pt.get_daily_data(
    pd.to_datetime("2024-10-01"), pd.to_datetime("2025-03-11"), [swe_variable]
).reset_index()
# Create a time series plot using Plotly Express
px.line(df, x="datetime", y=swe_variable.name, title=f"{pt.name} SWE")
Resulting plot of SWE trace at Banner summit

Requirements

python >= 3.7

Install

python3 -m pip install metloom
  • Common install issues:
    • Macbook M1 and M2 chips: some python packages run into issues with the new M chips
      • error : from lxml import etree in utils.py ((mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64)

        The solution is the following

        pip uninstall lxml
        pip install --no-binary lxml lxml

Local install for dev

The recommendation is to use virtualenv, but other local python environment isolation tools will work (pipenv, conda)

python3 -m pip install --upgrade pip
python3 -m pip install -r requirements_dev
python3 -m pip install .

Testing

pytest

If contributing to the codebase, code coverage should not decrease from the contributions. Make sure to check code coverage before opening a pull request.

pytest --cov=metloom

Documentation

readthedocs coming soon

https://metloom.readthedocs.io.

Usage

See usage documentation https://metloom.readthedocs.io/en/latest/usage.html

NOTES: PointData methods that get point data return a GeoDataFrame indexed on both datetime and station code. To reset the index simply run df.reset_index(inplace=True)

Simple usage examples are provided in this readme and in the docs. See our examples for code walkthroughs and more complicated use cases.

Usage Examples

Use metloom to find data for a station

from datetime import datetime
from metloom.pointdata import SnotelPointData

snotel_point = SnotelPointData("713:CO:SNTL", "MyStation")
df = snotel_point.get_daily_data(
    datetime(2020, 1, 2), datetime(2020, 1, 20),
    [snotel_point.ALLOWED_VARIABLES.SWE]
)
print(df)

Use metloom to find snow courses within a geometry

from metloom.pointdata import CDECPointData
from metloom.variables import CdecStationVariables

import geopandas as gpd

fp = <path to shape file>
obj = gpd.read_file(fp)

vrs = [
    CdecStationVariables.SWE,
    CdecStationVariables.SNOWDEPTH
]
points = CDECPointData.points_from_geometry(obj, vrs, snow_courses=True)
df = points.to_dataframe()
print(df)

Tutorials

In the Examples folder, there are multiple Jupyter notbook based tutorials. You can edit and run these notebooks by running Jupyter Lab from the command line

pip install jupyterlab
jupyter lab

This will open a Jupyter Lab session in your default browser.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2021-10-05)

  • This is the first release!

  • Create the package

  • Add CDEC functionality

  • Add SNOTEL functionality

  • Add CLI to find stations from shapefile

  • Write a custom Snotel client using zeep

0.2.0 (2021-12-29)

  • Added mesowest network

  • Added in a token json arg to the get_*_data functions

  • Pinned docutils for an update that happened

  • Added in a resample_df function for the highway stations where the returned data is 5min for air temp.

0.3.0 (2022-10-28)

  • Added USGS network

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metloom-0.9.3.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metloom-0.9.3-py2.py3-none-any.whl (64.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file metloom-0.9.3.tar.gz.

File metadata

  • Download URL: metloom-0.9.3.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for metloom-0.9.3.tar.gz
Algorithm Hash digest
SHA256 d307de437cc99ba73392334f3b80e1b75a44cc2f6cdb365a3b63f419a2d0976f
MD5 fd4aabd3e92b689aaf2f667306fdc974
BLAKE2b-256 0b3e407a3c488e7c719b25e55015eba89335be2a2b95729c0f8712a4bde5ee7c

See more details on using hashes here.

File details

Details for the file metloom-0.9.3-py2.py3-none-any.whl.

File metadata

  • Download URL: metloom-0.9.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 64.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for metloom-0.9.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 53c647d9896b58eb070c2f5522dde578ae8e0da6c731aebaf064c3d4cdba69fe
MD5 d6193472f298c90b5078df997048fdd0
BLAKE2b-256 e56201f59e159e7fd38e141580c3aebd984de85ef4b5aff3dce6ad69a946afe6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page