Giter VIP home page Giter VIP logo

obsio's Introduction

obsio

obsio is an Python package that provides a consistent generic interface for accessing weather and climate observations from multiple different data providers. All station and observation data are returned using pandas or xarray data structures.

Installation

obsio has the following dependencies:

The easiest method to install the required dependencies is with a combination of conda and pip:

conda create -n obsio_env python=3 lxml netCDF4 numpy pandas pycurl pytz scipy shapely xarray
pip install suds-py3
pip install tzwhere

And then install obsio from source:

git clone https://github.com/jaredwo/obsio.git
pip install obsio/

Available Data Providers ============= obsio currently has full or partial support for a number of climate and weather data providers. Only daily and monthly elements are supported at this time, but hourly and sub-hourly can easily be added.

Provider Name Currently Supported Elements Req. Local Storage
ACIS tmin,tmax,prcp,tobs_tmin,tobs_tmax, tobs_prcp No
GHCN-D tmin,tmax,prcp,tobs_tmin,tobs_tmax, tobs_prcp Optional
ISDLite tmin,tmax,tdew,tdewmin,tdewmax,vpd, vpdmin,vpdmax,rh,rhmin,rhmax,prcp No
MADIS tmin,tmax,prcp,tdew,tdewmin,tdewmax, vpd,vpdmin,vpdmax,rh,rhmin,rhmax,srad, wspd Yes
NRCS tmin,tmax,prcp,snwd,swe No
USHCN | * _mth_raw,*_mth_tob,*_mth_fls | Yes
WRCC | tmi
n,tmax,tdew,tdewmin,tdewmax,vpd, | No

vpdmin,vpdmax,rh,rhmin,rhmax,prcp,srad, wspd

Element definitions:

  • tmin : daily minimum temperature (C)
  • tmax : daily maximum temperature (C)
  • tdew : daily average dewpoint (C)
  • tdewmin : daily minimum dewpoint (C)
  • tdewmax : daily maximum dewpoint (C)
  • vpd : daily average vapor pressure deficit (Pa)
  • vpdmin : daily minimum vapor pressure deficit (Pa)
  • vpdmax : daily maximum vapor pressure deficit (Pa)
  • rh : daily average relative humidity (%)
  • rhmin : daily minimum relative humidity (%)
  • rhmax : daily maximum relative humidity (%)
  • prcp : daily total precipitation (mm)
  • srad : daily 24-hr average incoming solar radiation (w m-2)
  • wspd : daily average windspeed (m s-1)
  • snwd : snow depth (mm)
  • swe : snow water equivalent (mm)
  • tobs_tmin : time-of-observation for daily tmin (local hr)
  • tobs_tmax : time-of-observation for daily tmax (local hr)
  • tobs_prcp : time-of-observation for daily prcp (local hr)
  • *_mth_raw : USHCN-specific elements. Original, raw monthly elements:
    • tmin_mth_raw (C)
    • tmax_mth_raw (C)
    • tavg_mth_raw(C)
    • prcp_mth_raw (mm)
  • *_mth_tob : USHCN-specific elements. Time-of-observation adjusted elements:
    • tmin_mth_tob (C)
    • tmax_mth_tob (C)
    • tavg_mth_tob (C)
  • *_mth_fls : USHCN-specific elements. Homogenized and infilled elements:
    • tmin_mth_fls (C)
    • tmax_mth_fls (C)
    • tavg_mth_fls (C)
    • prcp_mth_fls (mm)

Usage

The main entry point for using obsio is through ObsIoFactory. ObIoFactory is used to build ObsIO objects for accessing station metadata and observations from specific providers.

# Example code for accessing NRCS SNOTEL/SCAN observations in the Pacific
# Northwest for January 2015

import obsio
import pandas as pd

# List of elements to obtain
elems = ['tmin', 'tmax', 'swe']

# Lat/Lon bounding box for the Pacific Northwest
bbox = obsio.BBox(west_lon=-126, south_lat=42, east_lon=-111, north_lat=50)

# Start, end dates as pandas Timestamp objects
start_date = pd.Timestamp('2015-01-01')
end_date = pd.Timestamp('2015-01-31')

# Initialize factory with specified parameters
obsiof = obsio.ObsIoFactory(elems, bbox, start_date, end_date)

# Create ObsIO object for accessing daily NRCS observations
nrcs_io = obsiof.create_obsio_dly_nrcs()

# All ObsIO objects contain a stns attribute. This is a pandas DataFrame
# containing metadata for all stations that met the specified parameters.
print nrcs_io.stns

# Access observations using read_obs() method. By default, read_obs() will
# return observations for all stations in the stns attribute
obs = nrcs_io.read_obs()

# Observations are provided in a pandas DataFrame. Observation values are 
# indexed by a 3 level multi-index: station_id, elem, time
print obs

# To access observations for only a few specific stations, send in a list
# of station ids to read_obs()
obs = nrcs_io.read_obs(['11E07S', '11E31S'])

In contrast to the NRCS SNOTEL/SCAN example, some ObsIO provider objects require all observation data to first be downloaded and stored locally, and then parsed (see provider table above). The data directory for local storage can be pre-specified in a 'OBSIO_DATA' environmental variable or specified as a parameter when creating the ObsIO object. If no directory is specified, obsio will default to a standard temporary directory. Example:

# Example code for accessing GHCN-D observations in the Pacific
# Northwest for January 2015. GHCN-D is a data provider that
# has an option to download and store observations locally for more
# efficient bulk parsing and access.

import obsio
import pandas as pd

# List of elements to obtain
elems = ['tmin', 'tmax']

# Lat/Lon bounding box for the Pacific Northwest
bbox = obsio.BBox(west_lon=-126, south_lat=42, east_lon=-111, north_lat=50)

# Start, end dates as pandas Timestamp objects
start_date = pd.Timestamp('2015-01-01')
end_date = pd.Timestamp('2015-01-31')

# Initialize factory with specified parameters
obsiof = obsio.ObsIoFactory(elems, bbox, start_date, end_date)

# Create ObsIO object for accessing GHCN-D observations in bulk mode.
# A local data path can be specified in the create_obsio_dly_ghcnd() call.
# If not specified, the 'OBSIO_DATA' environmental variable will be checked.
# If 'OBSIO_DATA' doesn't exist, a default temporary directory will be used.
ghcnd_io = obsiof.create_obsio_dly_ghcnd(bulk=True)

# Access observations for first 10 stations using the read_obs() method.
# First call to read_obs() will take several minutes due to initial data
# download.
obs = ghcnd_io.read_obs(ghcnd_io.stns.station_id.iloc[0:10])

obsio's People

Contributors

jaredwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

obsio's Issues

AttributeError: 'NoneType' object has no attribute 'promotePrefixes'

suds-py3 error when running below code that queries NRCS AWDB web service. Possibility due to: cackharot/suds-py3#37 .

import obsio
import pandas as pd
	
# List of elements to obtain
elems = ['tmin', 'tmax', 'swe']
	
# Lat/Lon bounding box for the Pacific Northwest
bbox = obsio.BBox(west_lon=-126, south_lat=42, east_lon=-111, north_lat=50)

# Start, end dates as pandas Timestamp objects
start_date = pd.Timestamp('2015-01-01')
end_date = pd.Timestamp('2015-01-31')

# Initialize factory with specified parameters
obsiof = obsio.ObsIoFactory(elems, bbox, start_date, end_date)

# Create ObsIO object for accessing daily NRCS observations
nrcs_io = obsiof.create_obsio_dly_nrcs()

# All ObsIO objects contain a stns attribute. This is a pandas DataFrame
# containing metadata for all stations that met the specified parameters.
print(nrcs_io.stns)

Python 2 version?

Hi. I was using TopoWX, but since TopoWX is still written based on Python 2, do you know if it is possible to download a version of obsio that was written in python 2 as well? Or at least some advice to get both TopoWX and obsio to work with each other. Thanks!

agrimet stations

Hi Jared,

Small world: I'm going to work for Jensco et al at UM. I'm working on remote sensing methods to estimate evapotranspiration. Some of the methods need radiation data from Bureau of Reclamation AgriMet stations. Is this something you've considered adding to obsio? Would you be open to a PR if I were to write it in? Is there a testing suite that has been excluded from the github code?

I guess you could consider this a feature request, though I'd like the opportunity to learn more about obsio by adding another provider. This assuming that there is not a serious obstacle to using AgriMet that I'm ignorant of.

I think this is a great package, and could serve many other purposes aside from TopoWX and whatever else you've used it for that I'm unaware of. I hope to write code like this some day!

Cheers,

Exception thrown running example code for NRCS

Hello! I installed obsio in a new conda environment according to the instructions in the readme, and tried running the NRCS example snipped but got the following exception:

Screen Shot 2019-06-15 at 12 08 48 AM

I tried making the following modification at line 631 in /obsio/providers/nrcs.py but, it seems not to be fixing the issue.

#         self._elem_funcs = np.unique(np.array([_ELEM_EXTRACT_FUNCS[a_elem] for
#                                                a_elem in self.elems]))

    self._elem_funcs = np.array([_ELEM_EXTRACT_FUNCS[a_elem] for
                                           a_elem in np.unique(self.elems)])

Any help would be greatly appreciated. Also thank you for your work on a fantastic tool!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.