Testing Xray on the PRISM data


In [19]:
import xray
import datetime
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
%matplotlib inline

In [20]:
URL = 'http://cida.usgs.gov/thredds/dodsC/prism_v2'

In [21]:
ds = xray.open_dataset(URL)

In [22]:
ds


Out[22]:
<xray.Dataset>
Dimensions:    (lat: 621, lon: 1405, tbnd: 2, time: 1440)
Coordinates:
  * lon        (lon) float32 -125.021 -124.979 -124.938 -124.896 -124.854 ...
  * lat        (lat) float32 49.9375 49.8958 49.8542 49.8125 49.7708 49.7292 ...
  * time       (time) datetime64[ns] 1895-01-01 1895-02-01 1895-03-01 ...
  * tbnd       (tbnd) int64 0 1
Data variables:
    time_bnds  (time, tbnd) float32 ...
    ppt        (time, lat, lon) float64 ...
    tmx        (time, lat, lon) float64 ...
    tmn        (time, lat, lon) float64 ...
Attributes:
    Conventions: CF-1.4
    acknowledgment: PRISM Climate Group, Oregon State University, http://prism.oregonstate.edu, Accessed August 2015.
    Metadata_Conventions: Unidata Dataset Discovery v1.0
    title: Parameter-elevation Regressions on Independent Slopes Model Monthly Climate Data for the Continental United States. August 2015 Snapshot
    summary:  This dataset was created using the PRISM (Parameter-elevation Regressions on Independent Slopes Model) climate mapping system, developed by Dr. Christopher Daly, PRISM Climate Group director. PRISM is a unique knowledge-based system that uses point measurements of precipitation, temperature, and other climatic factors to produce continuous, digital grid estimates of monthly, yearly, and event-based climatic parameters. Continuously updated, this unique analytical tool incorporates point data...
    keywords: Atmospheric Temperature, Air Temperature Atmosphere, Precipitation, Rain, Maximum Daily Temperature, Minimum  Daily Temperature
    keywords_vocabulary: GCMD Science Keywords
    id: prism/thredds/cida.usgs.gov
    naming_authority: cida.usgs.gov
    cdm_data_type: Grid
    creator_name: Christopher Daley
    creator_email: daley@nacse.org
    publisher_name: PRISM Climate Group
    publisher_url: http://prism.oregonstate.edu/
    geospatial_lat_min: 24
    geospatial_lat_max: 53
    geospatial_lon_min: -125
    geospatial_lon_max: -67
    time_coverage_start: 1895-01-01T00:00
    time_coverage_end: 2014-12-01T00:00
    time_coverage_resolution: Monthly
    license: Freely Available: The PRISM Climate Group, Oregon State University retains rights to ownership of the data and information.
    authors: PRISM Climate Group
    institution: Oregon State University

In [23]:
# select lat,lon region of interest
# note: slice(20.5,55.0) fails
dsloc = ds.sel(lon=slice(-75.0,-69.0),lat=slice(45.0,40.0))

In [24]:
# select closest data to time of interest
date = datetime.datetime(2005,8,1,0,0)
#date = datetime.datetime.now()
ds_snapshot = dsloc.sel(time=date,method='nearest')

In [25]:
ds.data_vars
# ds.coords
# ds.attrs


Out[25]:
Data variables:
    time_bnds  (time, tbnd) float32 ...
    ppt        (time, lat, lon) float64 ...
    tmx        (time, lat, lon) float64 ...
    tmn        (time, lat, lon) float64 ...

In [26]:
t = ds_snapshot['ppt']

In [27]:
t.shape


Out[27]:
(120, 144)

In [28]:
tvals = t.data

In [29]:
tvals = np.ma.masked_invalid(t.data)

In [30]:
plt.pcolormesh(t.lon.data,t.lat.data,tvals)
plt.title(t.name+pd.Timestamp(t.time.values).strftime(': %Y-%m-%d  %H:%M:%S %Z %z'));
plt.colorbar();



In [31]:
tvals.min()


Out[31]:
5.5899999999999999

In [32]:
# time series closest to specified lon,lat location
ds_series = ds.sel(lon=-72.,lat=42.,method='nearest')

In [33]:
# Select temperature and convert to Pandas Series
v_series = ds_series['ppt'].to_series()

In [34]:
v_series.plot(title=v_series.name);



In [35]:
ds_snapshot


Out[35]:
<xray.Dataset>
Dimensions:    (lat: 120, lon: 144, tbnd: 2)
Coordinates:
  * lon        (lon) float32 -74.9792 -74.9375 -74.8958 -74.8542 -74.8125 ...
  * lat        (lat) float32 44.9792 44.9375 44.8958 44.8542 44.8125 44.7708 ...
    time       datetime64[ns] 2005-08-01
  * tbnd       (tbnd) int64 0 1
Data variables:
    time_bnds  (tbnd) float32 49520.0 49550.0
    ppt        (lat, lon) float64 97.85 95.44 93.59 92.65 92.37 92.32 92.05 ...
    tmx        (lat, lon) float64 26.77 26.79 26.81 26.84 26.92 26.95 26.95 ...
    tmn        (lat, lon) float64 15.5 15.34 15.25 15.47 15.88 16.15 16.11 ...
Attributes:
    Conventions: CF-1.4
    acknowledgment: PRISM Climate Group, Oregon State University, http://prism.oregonstate.edu, Accessed August 2015.
    Metadata_Conventions: Unidata Dataset Discovery v1.0
    title: Parameter-elevation Regressions on Independent Slopes Model Monthly Climate Data for the Continental United States. August 2015 Snapshot
    summary:  This dataset was created using the PRISM (Parameter-elevation Regressions on Independent Slopes Model) climate mapping system, developed by Dr. Christopher Daly, PRISM Climate Group director. PRISM is a unique knowledge-based system that uses point measurements of precipitation, temperature, and other climatic factors to produce continuous, digital grid estimates of monthly, yearly, and event-based climatic parameters. Continuously updated, this unique analytical tool incorporates point data...
    keywords: Atmospheric Temperature, Air Temperature Atmosphere, Precipitation, Rain, Maximum Daily Temperature, Minimum  Daily Temperature
    keywords_vocabulary: GCMD Science Keywords
    id: prism/thredds/cida.usgs.gov
    naming_authority: cida.usgs.gov
    cdm_data_type: Grid
    creator_name: Christopher Daley
    creator_email: daley@nacse.org
    publisher_name: PRISM Climate Group
    publisher_url: http://prism.oregonstate.edu/
    geospatial_lat_min: 24
    geospatial_lat_max: 53
    geospatial_lon_min: -125
    geospatial_lon_max: -67
    time_coverage_start: 1895-01-01T00:00
    time_coverage_end: 2014-12-01T00:00
    time_coverage_resolution: Monthly
    license: Freely Available: The PRISM Climate Group, Oregon State University retains rights to ownership of the data and information.
    authors: PRISM Climate Group
    institution: Oregon State University

In [36]:
#ds_snapshot.to_netcdf('ds_snapshot.nc')

In [ ]: