metloom package

Subpackages

Submodules

metloom.cli module

Console script for metloom.

metloom.cli.main()[source]

Console script for metloom.

metloom.dataframe_utils module

metloom.dataframe_utils.append_df(df: Optional[DataFrame], new_df: Optional[DataFrame])[source]

append 2 dfs handling Nones Args:

df: optional dataframe new_df: optional dataframe

Returns:

dataframe or None

metloom.dataframe_utils.join_df(df: Optional[DataFrame], new_df: Optional[DataFrame], how='left', on=None, filter_unused=False)[source]

join two dataframes handling None Args:

df: optional dataframe new_df: optional dataframe how: method for merging on: optional kwarg for DataFrame.join filter_unused: boolean, whether to filter out columns with _unused in

then name

Returns:

The joined dataframes. This method prefers values from the first if columns are overlapping and renames the overlapping values from the new_df to <column>_unused

metloom.dataframe_utils.merge_df(df: Optional[DataFrame], new_df: Optional[DataFrame], how='left')[source]

join two dataframes. Assumes the dataframes are indexed on datetime Args:

df: optional dataframe new_df: optional dataframe

Returns:

The merged dataframe

metloom.dataframe_utils.resample_df(raw_df: DataFrame, variable: SensorDescription, interval: str = 'H')[source]

Resample an datatime indexed pandas dateframe to hourly or daily timer intervals. Resample a datetime indexed pandas dataframe for 1 variable

Args:
raw_df: Pandas Dataframe containing a datetime index at an interval

smaller than hourly.

variable: SensorDescriptions to be found in the dataframe interval: Interval to resample to. Options are H = Hourly, D=Daily

Returns:
df: Pandas Dataframe of a single variable resampled to the

desired interval

metloom.dataframe_utils.resample_whole_df(raw_df: DataFrame, variable: SensorDescription, interval: str = 'H')[source]

Resample an datatime indexed pandas dateframe to hourly or daily timer intervals. Resample a datetime indexed pandas dataframe for 1 variable Other columns get resampled with the .first() values

Args:
raw_df: Pandas Dataframe containing a datetime index at an interval

smaller than hourly.

variable: SensorDescriptions to be found in the dataframe interval: Interval to resample to. Options are H = Hourly, D=Daily

Returns:
df: Pandas Dataframe of a single variable resampled to the

desired interval

metloom.dataframe_utils.shp_to_box(geometry)[source]

Convert a shapefiles geodataframe to the bounding box of the shapefile as a new geodataframe

Args:

geometry: geodataframe polygon

Returns:

geodataframe of the bounding box

metloom.request_utils module

Taken from stackoverflow.com/questions/15445981/how-do-i-disable-the-security-certificate-check-in-python-requests This is necessary to make requests to Snotel without exceptions as we are not able to do the SSL verification

metloom.request_utils.no_ssl_verification()[source]

metloom.variables module

class metloom.variables.CdecStationVariables[source]

Bases: VariableBase

Available sensors from CDEC. Exhaustive list: http://cdec4gov.water.ca.gov/reportapp/javareports?name=SensList

PRECIPITATION = SensorDescription(code='45', name='PRECIPITATION', description='PRECIPITATION, INCREMENTAL', accumulated=True)
PRECIPITATIONACCUM = SensorDescription(code='2', name='ACCUMULATED PRECIPITATION', description='PRECIPITATION, ACCUMULATED', accumulated=False)
RH = SensorDescription(code='12', name='Relative Humidity', description='RELATIVE HUMIDITY', accumulated=False)
SNOWDEPTH = SensorDescription(code='18', name='SNOWDEPTH', description='SNOW DEPTH', accumulated=False)
SOLARRAD = SensorDescription(code='103', name='SOLAR RADIATION', description='SOLAR RADIATION', accumulated=False)
SWE = SensorDescription(code='3', name='SWE', description='SNOW, WATER CONTENT', accumulated=False)
TEMP = SensorDescription(code='4', name='AIR TEMP', description='TEMPERATURE, AIR', accumulated=False)
TEMPAVG = SensorDescription(code='30', name='AVG AIR TEMP', description='TEMPERATURE, AIR AVERAGE', accumulated=False)
TEMPGROUND = SensorDescription(code='52', name='GROUND TEMPERATURE INT', description='GROUND TEMPERATURE SNOW/SOIL INTERFACE', accumulated=False)
TEMPGROUND100CM = SensorDescription(code='196', name='GROUND TEMPERATURE -100CM', description='GROUND TEMPERATURE OBS -100CM', accumulated=False)
TEMPGROUND25CM = SensorDescription(code='194', name='GROUND TEMPERATURE -25CM', description='GROUND TEMPERATURE OBS -25CM', accumulated=False)
TEMPGROUND50CM = SensorDescription(code='195', name='GROUND TEMPERATURE -50CM', description='GROUND TEMPERATURE OBS -50CM', accumulated=False)
TEMPMAX = SensorDescription(code='31', name='MAX AIR TEMP', description='TEMPERATURE, AIR MAXIMUM', accumulated=False)
TEMPMIN = SensorDescription(code='32', name='MIN AIR TEMP', description='TEMPERATURE, AIR MINIMUM', accumulated=False)
WINDDIR = SensorDescription(code='10', name='WIND DIRECTION', description='WIND DIRECTION', accumulated=False)
WINDSPEED = SensorDescription(code='9', name='WIND SPEED', description='WIND SPEED', accumulated=False)
class metloom.variables.GeoSphereCurrentVariables[source]

Bases: VariableBase

PRECIPITATION = SensorDescription(code='RR', name='Rainfall in the last 10 minutes', description=None, accumulated=True)
SNOWDEPTH = SensorDescription(code='SCHNEE', name='Snowdepth', description=None, accumulated=False)
TEMP = SensorDescription(code='TL', name='Air Temperature', description=None, accumulated=False)
TEMPGROUND10CM = SensorDescription(code='TB1', name='Soil temperature at a depth of 10cm', description=None, accumulated=False)
TEMPGROUND20CM = SensorDescription(code='TB2', name='Soil temperature at a depth of 20cm', description=None, accumulated=False)
TEMPGROUND50CM = SensorDescription(code='TB3', name='Soil temperature at a depth of 50cm', description=None, accumulated=False)
class metloom.variables.GeoSphereHistVariables[source]

Bases: VariableBase

Variables that correspond to the DAILY historical Klima dataset

Daily and hourly have different variable names https://dataset.api.hub.geosphere.at/v1/station/historical/klima-v1-1h/metadata https://dataset.api.hub.geosphere.at/v1/station/historical/klima-v1-1d/metadata

PRECIPITATION = SensorDescription(code='nied', name='Precipitation Total', description=None, accumulated=True)
SNOWDEPTH = SensorDescription(code='schnee', name='Snowdepth', description=None, accumulated=False)
TEMP = SensorDescription(code='t7', name='Air temperature 2m on observation date', description=None, accumulated=False)
class metloom.variables.MesowestVariables[source]

Bases: VariableBase

Available sensors from Mesowest There are a lot of variables here. Feel free to PR to add some https://developers.synopticdata.com/mesonet/v2/api-variables/

DEWPOINT = SensorDescription(code='dew_point_temperature', name='DEW POINT TEMPERATURE', description=None, accumulated=False)
NETLONGWAVE = SensorDescription(code='net_radiation_lw', name='NET LONGWAVE RADIATION', description=None, accumulated=False)
NETSHORTWAVE = SensorDescription(code='net_radiation_sw', name='NET SHORTWAVE RADIATION', description=None, accumulated=False)
PRESSURE = SensorDescription(code='pressure', name='PRESSURE', description=None, accumulated=False)
RH = SensorDescription(code='relative_humidity', name='RELATIVE HUMIDITY', description=None, accumulated=False)
SNOWDEPTH = SensorDescription(code='snow_depth', name='SNOWDEPTH', description=None, accumulated=False)
SOILTEMP = SensorDescription(code='soil_temp', name='SOIL TEMPERATURE', description=None, accumulated=False)
SOILTEMPIR = SensorDescription(code='soil_temp_ir', name='SOIL TEMPERATURE IR', description=None, accumulated=False)
SOLARRADIATION = SensorDescription(code='solar_radiation', name='SOLAR RADIATION', description=None, accumulated=False)
STREAMFLOW = SensorDescription(code='stream_flow', name='STREAMFLOW', description=None, accumulated=False)
SWE = SensorDescription(code='snow_water_equiv', name='SWE', description=None, accumulated=False)
TEMP = SensorDescription(code='air_temp', name='AIR TEMP', description=None, accumulated=False)
WETBULBTEMPERATURE = SensorDescription(code='wet_bulb_temperature', name='WET BULB TEMPERATURE', description=None, accumulated=False)
WINDDIRECTION = SensorDescription(code='wind_direction', name='WIND DIRECTION', description=None, accumulated=False)
WINDSPEED = SensorDescription(code='wind_speed', name='WIND SPEED', description=None, accumulated=False)
class metloom.variables.SensorDescription(code: str = '-1', name: str = 'basename', description: Optional[str] = None, accumulated: bool = False)[source]

Bases: object

data class for describing a snow sensor

accumulated: bool = False
code: str = '-1'
description: str = None
name: str = 'basename'
class metloom.variables.SnotelVariables[source]

Bases: VariableBase

Available sensors from SNOTEL

PRECIPITATION = SensorDescription(code='PRCPSA', name='PRECIPITATION', description='PRECIPITATION INCREMENT SNOW-ADJUSTED', accumulated=False)
PRECIPITATIONACCUM = SensorDescription(code='PREC', name='ACCUMULATED PRECIPITATION', description='PRECIPITATION ACCUMULATION', accumulated=False)
RH = SensorDescription(code='RHUMV', name='RELATIVE HUMIDITY', description='RELATIVE HUMIDITY', accumulated=False)
SNOWDEPTH = SensorDescription(code='SNWD', name='SNOWDEPTH', description=None, accumulated=False)
SOILMOISTURE20IN = SensorDescription(code='SMS', name='SOIL MOISTURE -20IN', description='SOIL MOISTURE PERCENT -20IN', accumulated=False)
SOILMOISTURE2IN = SensorDescription(code='SMS', name='SOIL MOISTURE -2IN', description='SOIL MOISTURE PERCENT -2IN', accumulated=False)
SOILMOISTURE4IN = SensorDescription(code='SMS', name='SOIL MOISTURE -4IN', description='SOIL MOISTURE PERCENT -4IN', accumulated=False)
SOILMOISTURE8IN = SensorDescription(code='SMS', name='SOIL MOISTURE -8IN', description='SOIL MOISTURE PERCENT -8IN', accumulated=False)
STREAMVOLUMEADJ = SensorDescription(code='SRVOX', name='STREAM VOLUME ADJ', description='STREAM VOLUME ADJ', accumulated=False)
STREAMVOLUMEOBS = SensorDescription(code='SRVO', name='STREAM VOLUME OBS', description='STREAM VOLUME OBS', accumulated=False)
SWE = SensorDescription(code='WTEQ', name='SWE', description=None, accumulated=False)
TEMP = SensorDescription(code='TOBS', name='AIR TEMP', description=None, accumulated=False)
TEMPAVG = SensorDescription(code='TAVG', name='AVG AIR TEMP', description='AIR TEMPERATURE AVERAGE', accumulated=False)
TEMPGROUND20IN = SensorDescription(code='STO', name='GROUND TEMPERATURE -20IN', description='GROUND TEMPERATURE OBS -20IN', accumulated=False)
TEMPGROUND2IN = SensorDescription(code='STO', name='GROUND TEMPERATURE -2IN', description='GROUND TEMPERATURE OBS -2IN', accumulated=False)
TEMPGROUND4IN = SensorDescription(code='STO', name='GROUND TEMPERATURE -4IN', description='GROUND TEMPERATURE OBS -4IN', accumulated=False)
TEMPGROUND8IN = SensorDescription(code='STO', name='GROUND TEMPERATURE -8IN', description='GROUND TEMPERATURE OBS -8IN', accumulated=False)
TEMPMAX = SensorDescription(code='TMAX', name='MAX AIR TEMP', description='AIR TEMPERATURE MAXIMUM', accumulated=False)
TEMPMIN = SensorDescription(code='TMIN', name='MIN AIR TEMP', description='AIR TEMPERATURE MINIMUM', accumulated=False)
class metloom.variables.USGSVariables[source]

Bases: VariableBase

To add more sensors: https://help.waterdata.usgs.gov/codes-and-parameters/parameters

DISCHARGE = SensorDescription(code='00060', name='DISCHARGE', description='DISCHARGE (CFS)', accumulated=False)
SNOWDEPTH = SensorDescription(code='72189', name='SNOWDEPTH', description='Snow depth, Meters', accumulated=False)
STREAMFLOW = SensorDescription(code='74082', name='STREAMFLOW', description='STREAMFLOW, DAILY VOLUME (AC-FT)', accumulated=False)
SWE = SensorDescription(code='72341', name='SWE', description='Water content of snow, millimeters', accumulated=False)
class metloom.variables.VariableBase[source]

Bases: object

Base class to store all variables for a specific datasource. Each datasource should implement the class. The goal is that the variables are synonymous across implementations.(i.e. PRECIPITATION should have the same meaning in each implementation). Additionally, variables with the same meaning should have the same name attribute of the SensorDescription. This way, if multiple datsources are used to sample the same variable, they can be written to the same column in a csv.

Variables in this base class should ideally be implemented by all classes and cannot be directly used from the base class.

PRECIPITATION = SensorDescription(code='-1', name='basename', description=None, accumulated=False)
SNOWDEPTH = SensorDescription(code='-1', name='basename', description=None, accumulated=False)
SWE = SensorDescription(code='-1', name='basename', description=None, accumulated=False)
classmethod from_code(code)[source]

Get the correct sensor description from the code

Module contents

Top-level package for metloom.