Nooksack Forest Modeling

Skookum Creek Case Study: Analyze downloaded gridded climate time-series data and generate a hybrid climate product

Use this Jupyter Notebook to:

  • Map gridded cell centroids,
  • Download climate data,
  • Make dictionaries for watershed data,
  • Generate global bias correction factors from low elevations,
  • Generate local (1 to 1) bias correction factors for each grid cell,
  • Bias correct to monthly means at each grid cell.
  • Bias correct to monthly means near observations (low elevations).
  • Generate a hydrid climate product dictionary.
  • Map results.
  • Convert daily data to 3-hourly time series for Velma and DHSVM model inputs
  • Make data publicly accessible on HydroShare.

1. HydroShare Setup and Preparation

To run this notebook, we must import several libaries. These are listed in order of a) Python standard libraries, b) hs_utils library provides functions for interacting with HydroShare, including resource querying, dowloading and creation, and c) the observatory_gridded_hydromet library that is downloaded with this notebook.


In [1]:
import os
import pandas as pd, numpy as np, dask, json
from utilities import hydroshare
%matplotlib inline
import geopandas as gpd
import warnings
warnings.filterwarnings("ignore")
import copy
import ogh

In [2]:
hs=hydroshare.hydroshare()
homedir = hs.getContentPath('e47aabb406bc45a28f34b97a832daa08')


Successfully established a connection with HydroShare

In [3]:
notebookdir = os.getcwd()

hs=hydroshare.hydroshare()
#homedir = hs.getContentPath(os.environ["HS_RES_ID"])
os.chdir(homedir)
print('Data will be loaded from and save to:'+homedir)


Successfully established a connection with HydroShare
Data will be loaded from and save to:/home/jovyan/work/notebooks/data/e47aabb406bc45a28f34b97a832daa08/e47aabb406bc45a28f34b97a832daa08/data/contents

In [4]:
json.load(open('ogh_meta.json'))


Out[4]:
{'dailywrf_salathe2014': {'domain': 'cses.washington.edu/',
  'end_date': '2010-12-31',
  'reference': {'1': 'Salathé Jr EP, Hamlet AF, Mass CF, Lee SY, Stumbaugh M, Steed R. Estimates of twenty-first-century flood risk in the Pacific Northwest based on regional climate model simulations. Journal of Hydrometeorology. 2014 Oct;15(5):1881-99. DOI: 10.1175/JHM-D-13-0137.1',
   '2': 'http://cses.washington.edu/rocinante/WRF/README'},
  'file_format': 'ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'Maximum temperature at 2m'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Daily accumulated precipitation'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'Minimum temperature at 2m'},
   'WINDSPD': {'units': 'm/s', 'dtypes': 'float64', 'desc': 'Wind Speed'}},
  'delimiter': '\\s+',
  'decision_steps': '',
  'temporal_resolution': 'D',
  'web_protocol': 'http',
  'subdomain': '/rocinante/WRF/NNRP/vic_16d/WWA_1950_2010/raw/forcings_ascii/',
  'start_date': '1950-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'data_{LAT}_{LONG}'},
 'dailymet_livneh2013': {'domain': 'livnehpublicstorage.colorado.edu',
  'end_date': '2011-12-31',
  'reference': {'1': 'Livneh, B., E. A. Rosenberg, C. Lin, B. Nijssen, V. Mishra, K. M. Andreadis, E. P. Maurer, and D. P. Lettenmaier, 2013: A Long-Term Hydrologically Based Dataset of Land Surface Fluxes and States for the Conterminous United States: Update and Extensions. J. Climate, 26, 9384-9392.',
   '2': 'ftp://livnehpublicstorage.colorado.edu/public/Livneh.2013.CONUS.Dataset/readme.txt'},
  'file_format': 'bz2-compressed ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily maximum temperature (C)'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'daily precipitation (mm)'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily minimum temperature (C)'},
   'WINDSPD': {'units': 'm/s',
    'dtypes': 'float64',
    'desc': 'daily mean wind speed (m/s)'}},
  'delimiter': '\t',
  'decision_steps': 'files organized by spatial bounding boxes',
  'temporal_resolution': 'D',
  'web_protocol': 'ftp',
  'subdomain': '/public/Livneh.2013.CONUS.Dataset/Meteorology.asc.v.1.2.1915.2011.bz2/',
  'start_date': '1915-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'Meteorology_Livneh_CONUSExt_v.1.2_2013_{LAT}_{LONG}'},
 'dailywrf_bcsalathe2014': {'domain': 'cses.washington.edu/',
  'end_date': '2010-12-31',
  'reference': {'1': 'Salathé Jr EP, Hamlet AF, Mass CF, Lee SY, Stumbaugh M, Steed R. Estimates of twenty-first-century flood risk in the Pacific Northwest based on regional climate model simulations. Journal of Hydrometeorology. 2014 Oct;15(5):1881-99. DOI: 10.1175/JHM-D-13-0137.1',
   '2': 'http://cses.washington.edu/rocinante/WRF/README'},
  'file_format': 'ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'Maximum temperature at 2m'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Daily accumulated precipitation'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'Minimum temperature at 2m'},
   'WINDSPD': {'units': 'm/s', 'dtypes': 'float64', 'desc': 'Wind Speed'}},
  'delimiter': '\\s+',
  'decision_steps': '',
  'temporal_resolution': 'D',
  'web_protocol': 'http',
  'subdomain': '/rocinante/WRF/NNRP/vic_16d/WWA_1950_2010/bc/forcings_ascii/',
  'start_date': '1950-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'data_{LAT}_{LONG}'},
 'dailymet_livneh2015': {'domain': '192.12.137.7',
  'end_date': '2013-12-31',
  'reference': {'1': 'Livneh B., T.J. Bohn, D.S. Pierce, F. Munoz-Ariola, B. Nijssen, R. Vose, D. Cayan, and L.D. Brekke, 2015: A spatially comprehensive, hydrometeorological data set for Mexico, the U.S., and southern Canada 1950-2013, Nature Scientific Data, 5:150042, doi:10.1038/sdata.2015.42.',
   '2': 'ftp://livnehpublicstorage.colorado.edu/public/Livneh.2013.CONUS.Dataset/readme.txt'},
  'file_format': 'bz2-compressed ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily maximum temperature (C)'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'daily precipitation (mm)'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily minimum temperature (C)'},
   'WINDSPD': {'units': 'm/s',
    'dtypes': 'float64',
    'desc': 'daily mean wind speed (m/s)'}},
  'delimiter': '\\s+',
  'decision_steps': 'files organized by Latitude',
  'temporal_resolution': 'D',
  'web_protocol': 'ftp',
  'subdomain': '/pub/dcp/archive/OBS/livneh2014.1_16deg/ascii/daily/',
  'start_date': '1950-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'Meteorology_Livneh_NAmerExt_15Oct2014_{LAT}_{LONG}'},
 'dailyvic_livneh2013': {'domain': 'livnehpublicstorage.colorado.edu',
  'end_date': '2011-12-31',
  'reference': {'1': 'Livneh, B., E. A. Rosenberg, C. Lin, B. Nijssen, V. Mishra, K. M. Andreadis, E. P. Maurer, and D. P. Lettenmaier, 2013: A Long-Term Hydrologically Based Dataset of Land Surface Fluxes and States for the Conterminous United States: Update and Extensions. J. Climate, 26, 9384-9392.',
   '2': 'ftp://livnehpublicstorage.colorado.edu/public/Livneh.2013.CONUS.Dataset/readme.txt'},
  'file_format': 'bz2-compressed ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'PREC': {'units': 'mm/s',
    'dtypes': 'float64',
    'desc': 'Incoming precipitation rate'},
   'WDEW': {'units': 'mm', 'dtypes': 'float64', 'desc': 'Canopy water'},
   'LATENT': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net latent heat flux'},
   'SENSIBLE': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net sensible heat flux'},
   'RADTEMP': {'units': 'K',
    'dtypes': 'float64',
    'desc': 'Mean radiative surface temperature'},
   'EVAP': {'units': 'mm/s',
    'dtypes': 'float64',
    'desc': 'Total ET rate-- includes Canopy, Sub-canopy Evaporation, Transpiration, and Snow Sublimation'},
   'RNET': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net downward radiation flux'},
   'SWE': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Snow water equivalent (SWE)'},
   'SMBOT': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Soil moisture bottom layer'},
   'MONTH': {'units': 'mo', 'dtypes': 'int8', 'desc': 'month'},
   'SMTOP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Soil moisture top layer'},
   'GRNDFLUX': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net heat flux into ground'},
   'YEAR': {'units': 'yr', 'dtypes': 'int8', 'desc': 'year'},
   'RUNOFF': {'units': 'mm/s', 'dtypes': 'float64', 'desc': 'Runoff'},
   'SMMID': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Soil moisture middle layer'},
   'DAY': {'units': 'day', 'dtypes': 'int8', 'desc': 'day'},
   'BASEFLOW': {'units': 'mm/s', 'dtypes': 'float64', 'desc': 'Baseflow'}},
  'delimiter': '\t',
  'decision_steps': 'files organized by spatial bounding boxes',
  'temporal_resolution': 'D',
  'web_protocol': 'ftp',
  'subdomain': '/public/Livneh.2013.CONUS.Dataset/Fluxes.asc.v.1.2.1915.2011.bz2/',
  'start_date': '1915-01-01',
  'variable_list': ['YEAR',
   'MONTH',
   'DAY',
   'EVAP',
   'RUNOFF',
   'BASEFLOW',
   'SMTOP',
   'SMMID',
   'SMBOT',
   'SWE',
   'WDEW',
   'SENSIBLE',
   'LATENT',
   'GRNDFLUX',
   'RNET',
   'RADTEMP',
   'PREC'],
  'filename_structure': 'VIC_fluxes_Livneh_CONUSExt_v.1.2_2013_{LAT}_{LONG}'},
 'dailymet_bclivneh2013': {'domain': 'cses.washington.edu',
  'end_date': '2011-12-31',
  'reference': {'1': 'Livneh, B., E. A. Rosenberg, C. Lin, B. Nijssen, V. Mishra, K. M. Andreadis, E. P. Maurer, and D. P. Lettenmaier, 2013: A Long-Term Hydrologically Based Dataset of Land Surface Fluxes and States for the Conterminous United States: Update and Extensions. J. Climate, 26, 9384-9392.',
   '2': 'ftp://livnehpublicstorage.colorado.edu/public/Livneh.2013.CONUS.Dataset/readme.txt'},
  'file_format': 'ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily maximum temperature (C)'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'daily precipitation (mm)'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily minimum temperature (C)'},
   'WINDSPD': {'units': 'm/s',
    'dtypes': 'float64',
    'desc': 'daily mean wind speed (m/s)'}},
  'delimiter': '\t',
  'decision_steps': '',
  'temporal_resolution': 'D',
  'web_protocol': 'http',
  'subdomain': '/rocinante/Livneh/bcLivneh_WWA_2013/forcings_ascii/',
  'start_date': '1915-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'data_{LAT}_{LONG}'},
 'dailyvic_livneh2015': {'domain': '192.12.137.7',
  'end_date': '2013-12-31',
  'reference': {'1': 'Livneh B., T.J. Bohn, D.S. Pierce, F. Munoz-Ariola, B. Nijssen, R. Vose, D. Cayan, and L.D. Brekke, 2015: A spatially comprehensive, hydrometeorological data set for Mexico, the U.S., and southern Canada 1950-2013, Nature Scientific Data, 5:150042, doi:10.1038/sdata.2015.42.',
   '2': 'ftp://192.12.137.7/pub/dcp/archive/OBS/livneh2014.1_16deg/README.Livneh.Grids.txt.v3.txt'},
  'file_format': 'bz2-compressed ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'WDEW': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Canopy water'},
   'PETSHORT': {'units': 'mm/day',
    'dtypes': 'float64',
    'desc': 'Potential Evapotranspiration from short crop (Grass)'},
   'LATENT': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net latent heat flux'},
   'SENSIBLE': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net sensible heat flux'},
   'PETTALL': {'units': 'mm/day',
    'dtypes': 'float64',
    'desc': 'Potential Evapotranspiration from tall crop (Alfalfa)'},
   'EVAP': {'units': 'mm/day',
    'dtypes': 'float64',
    'desc': 'Total ET rate-- includes Canopy, Sub-canopy Evaporation, Transpiration, and Snow Sublimation'},
   'RNET': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net downward radiation flux'},
   'SWE': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Snow water equivalent (SWE)'},
   'SMBOT': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Soil moisture bottom layer'},
   'MONTH': {'units': 'mo', 'dtypes': 'int8', 'desc': 'month'},
   'SMTOP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Soil moisture top layer'},
   'GRNDFLUX': {'units': 'W/m^2',
    'dtypes': 'float64',
    'desc': 'Net heat flux into ground'},
   'PETNATVEG': {'units': 'mm/day',
    'dtypes': 'float64',
    'desc': 'Potential Evapotranspiration from current vegetation'},
   'YEAR': {'units': 'yr', 'dtypes': 'int8', 'desc': 'year'},
   'RUNOFF': {'units': 'mm/day', 'dtypes': 'float64', 'desc': 'Runoff'},
   'SMMID': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'Soil moisture middle layer'},
   'DAY': {'units': 'day', 'dtypes': 'int8', 'desc': 'day'},
   'BASEFLOW': {'units': 'mm/day', 'dtypes': 'float64', 'desc': 'Baseflow'}},
  'delimiter': '\t',
  'decision_steps': 'files organized by Latitude',
  'temporal_resolution': 'D',
  'web_protocol': 'ftp',
  'subdomain': '/pub/dcp/archive/OBS/livneh2014.1_16deg/VIC.ASCII/',
  'start_date': '1950-01-01',
  'variable_list': ['YEAR',
   'MONTH',
   'DAY',
   'EVAP',
   'RUNOFF',
   'BASEFLOW',
   'SMTOP',
   'SMMID',
   'SMBOT',
   'SWE',
   'WDEW',
   'SENSIBLE',
   'LATENT',
   'GRNDFLUX',
   'RNET',
   'PETTALL',
   'PETSHORT',
   'PETNATVEG'],
  'filename_structure': 'Fluxes_Livneh_NAmerExt_15Oct2014_{LAT}_{LONG}'},
 'dailymet_livneh2013_wrfbc': {'domain': 'livnehpublicstorage.colorado.edu',
  'end_date': '2011-12-31',
  'reference': {'1': 'Livneh, B., E. A. Rosenberg, C. Lin, B. Nijssen, V. Mishra, K. M. Andreadis, E. P. Maurer, and D. P. Lettenmaier, 2013: A Long-Term Hydrologically Based Dataset of Land Surface Fluxes and States for the Conterminous United States: Update and Extensions. J. Climate, 26, 9384-9392.',
   '2': 'ftp://livnehpublicstorage.colorado.edu/public/Livneh.2013.CONUS.Dataset/readme.txt'},
  'file_format': 'bz2-compressed ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily maximum temperature (C)'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'daily precipitation (mm)'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily minimum temperature (C)'},
   'WINDSPD': {'units': 'm/s',
    'dtypes': 'float64',
    'desc': 'daily mean wind speed (m/s)'}},
  'delimiter': '\t',
  'decision_steps': 'files organized by spatial bounding boxes',
  'temporal_resolution': 'D',
  'web_protocol': 'ftp',
  'subdomain': '/public/Livneh.2013.CONUS.Dataset/Meteorology.asc.v.1.2.1915.2011.bz2/',
  'start_date': '1915-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'Meteorology_Livneh_CONUSExt_v.1.2_2013_{LAT}_{LONG}'},
 'dailymet_livneh2013_wrfbc_global': {'domain': 'livnehpublicstorage.colorado.edu',
  'end_date': '2011-12-31',
  'reference': {'1': 'Livneh, B., E. A. Rosenberg, C. Lin, B. Nijssen, V. Mishra, K. M. Andreadis, E. P. Maurer, and D. P. Lettenmaier, 2013: A Long-Term Hydrologically Based Dataset of Land Surface Fluxes and States for the Conterminous United States: Update and Extensions. J. Climate, 26, 9384-9392.',
   '2': 'ftp://livnehpublicstorage.colorado.edu/public/Livneh.2013.CONUS.Dataset/readme.txt'},
  'file_format': 'bz2-compressed ASCII',
  'spatial_resolution': '1/16-degree',
  'variable_info': {'TMAX': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily maximum temperature (C)'},
   'PRECIP': {'units': 'mm',
    'dtypes': 'float64',
    'desc': 'daily precipitation (mm)'},
   'TMIN': {'units': 'C',
    'dtypes': 'float64',
    'desc': 'daily minimum temperature (C)'},
   'WINDSPD': {'units': 'm/s',
    'dtypes': 'float64',
    'desc': 'daily mean wind speed (m/s)'}},
  'delimiter': '\t',
  'decision_steps': 'files organized by spatial bounding boxes',
  'temporal_resolution': 'D',
  'web_protocol': 'ftp',
  'subdomain': '/public/Livneh.2013.CONUS.Dataset/Meteorology.asc.v.1.2.1915.2011.bz2/',
  'start_date': '1915-01-01',
  'variable_list': ['PRECIP', 'TMAX', 'TMIN', 'WINDSPD'],
  'filename_structure': 'Meteorology_Livneh_CONUSExt_v.1.2_2013_{LAT}_{LONG}'}}

In [5]:
# initialize ogh_meta
meta_file = dict(ogh.ogh_meta())
sorted(meta_file.keys())


Out[5]:
['dailymet_bclivneh2013',
 'dailymet_livneh2013',
 'dailymet_livneh2013_wrfbc',
 'dailymet_livneh2013_wrfbc_global',
 'dailymet_livneh2015',
 'dailyvic_livneh2013',
 'dailyvic_livneh2015',
 'dailywrf_bcsalathe2014',
 'dailywrf_salathe2014']

In [6]:
# Livneh et al., 2013
dr1 = meta_file['dailymet_livneh2013']

# Salathe et al., 2014
dr2 = meta_file['dailywrf_salathe2014']

# define overlapping time window
dr = ogh.overlappingDates(date_set1=tuple([dr1['start_date'], dr1['end_date']]), 
                          date_set2=tuple([dr2['start_date'], dr2['end_date']]))
dr


Out[6]:
('1950-01-01', '2010-12-31')

If you are curious about where the data is being downloaded, click on the Jupyter Notebook dashboard icon to return to the File System view. The homedir directory location printed above is where you can find the data and contents you will download to a HydroShare JupyterHub server. At the end of this work session, you can migrate this data to the HydroShare iRods server as a Generic Resource.

2. Get list of gridded climate points for the watershed

This example uses a shapefile with the watershed boundary of the SKookum Basin, which is stored in HydroShare at the following url: https://www.hydroshare.org/resource/23fcce3c57584468b06526285f1116f5/.

The data for our processing routines can be retrieved using the getResourceFromHydroShare function by passing in the global identifier from the url above. In the next cell, we download this resource from HydroShare, and identify that the points in this resource are available for downloading gridded hydrometeorology data, based on the point shapefile at https://www.hydroshare.org/resource/ef2d82bf960144b4bfb1bae6242bcc7f/, which is for the extent of North America and includes the average elevation for each 1/16 degree grid cell. The file must include columns with station numbers, latitude, longitude, and elevation. The header of these columns must be FID, LAT, LONG_, and ELEV or RASTERVALU, respectively. The station numbers will be used for the remainder of the code to uniquely reference data from each climate station, as well as to identify minimum, maximum, and average elevation of all of the climate stations. The webserice is currently set to a URL for the smallest geographic overlapping extent - e.g. WRF for Columbia River Basin (to use a limit using data from a FTP service, treatgeoself() would need to be edited in observatory_gridded_hydrometeorology utility).


In [7]:
""""
1/16-degree Gridded cell centroids
"""
# List of available data
hs.getResourceFromHydroShare('ef2d82bf960144b4bfb1bae6242bcc7f')
NAmer = hs.content['NAmer_dem_list.shp']

"""
Skookum (South Fork Nooksack)
"""
# Watershed extent
hs.getResourceFromHydroShare('ef2d82bf960144b4bfb1bae6242bcc7f')
skookum = hs.content['SkookumHUC171100040404.shp']


This resource already exists in your userspace.
ef2d82bf960144b4bfb1bae6242bcc7f/
|-- ef2d82bf960144b4bfb1bae6242bcc7f/
|   |-- bagit.txt
|   |-- manifest-md5.txt
|   |-- readme.txt
|   |-- tagmanifest-md5.txt
|   |-- data/
|   |   |-- resourcemap.xml
|   |   |-- resourcemetadata.xml
|   |   |-- contents/
|   |   |   |-- NAmer_dem_list.cpg
|   |   |   |-- NAmer_dem_list.dbf
|   |   |   |-- NAmer_dem_list.prj
|   |   |   |-- NAmer_dem_list.sbn
|   |   |   |-- NAmer_dem_list.sbx
|   |   |   |-- NAmer_dem_list.shp
|   |   |   |-- NAmer_dem_list.shx
|   |   |   |-- NooksackHUC17110004.cpg
|   |   |   |-- NooksackHUC17110004.shp
|   |   |   |-- NooksackHUC17110004.shx
|   |   |   |-- SouthForkHUC1711000404.shp
|   |   |   |-- SouthForkHUC1711000404.shx
|   |   |   |-- NooksackHUC17110004.dbf
|   |   |   |-- NooksackHUC17110004.prj
|   |   |   |-- Observatory_nooksack_hybridbiascorrection_20190926.ipynb
|   |   |   |-- Observatory_skagit_hybridbiascorrection_20190315.ipynb
|   |   |   |-- OGH_puyallup_hybridbiascorrection_20190315.ipynb
|   |   |   |-- SkookumHUC171100040404.cpg
|   |   |   |-- SkookumHUC171100040404.shp
|   |   |   |-- SkookumHUC171100040404.shx
|   |   |   |-- SouthForkHUC1711000404.dbf
|   |   |   |-- SouthForkHUC1711000404.prj
|   |   |   |-- SkookumHUC171100040404.dbf
|   |   |   |-- SkookumHUC171100040404.prj
|   |   |   |-- SouthForkHUC1711000404.cpg
|   |   |   |-- Observatory_nooksack_hybridbiascorrection_20200302.ipynb
|   |   |   |-- .ipynb_checkpoints/
|   |   |   |   |-- Observatory_nooksack_hybridbiascorrection_20190926-checkpoint.ipynb
|   |   |   |   |-- Observatory_nooksack_hybridbiascorrection_20200302-checkpoint.ipynb

Do you want to overwrite these data [Y/n]? n
Found the following notebook(s) associated with this HydroShare resource.
Click the link(s) below to launch the notebook.
Found the following file(s) associated with this HydroShare resource.
NAmer_dem_list.cpg
NAmer_dem_list.dbf
NAmer_dem_list.prj
NAmer_dem_list.sbn
NAmer_dem_list.sbx
NAmer_dem_list.shp
NAmer_dem_list.shx
NooksackHUC17110004.cpg
NooksackHUC17110004.shp
NooksackHUC17110004.shx
SouthForkHUC1711000404.shp
SouthForkHUC1711000404.shx
NooksackHUC17110004.dbf
NooksackHUC17110004.prj
Observatory_nooksack_hybridbiascorrection_20190926.ipynb
Observatory_skagit_hybridbiascorrection_20190315.ipynb
OGH_puyallup_hybridbiascorrection_20190315.ipynb
SkookumHUC171100040404.cpg
SkookumHUC171100040404.shp
SkookumHUC171100040404.shx
SouthForkHUC1711000404.dbf
SouthForkHUC1711000404.prj
SkookumHUC171100040404.dbf
SkookumHUC171100040404.prj
SouthForkHUC1711000404.cpg
Observatory_nooksack_hybridbiascorrection_20200302.ipynb
These files are stored in a dictionary called hs.content for your convenience. To access a file, simply issue the following command where MY_FILE is one of the files listed above:
hs.content["MY_FILE"] 
This resource already exists in your userspace.
ef2d82bf960144b4bfb1bae6242bcc7f/
|-- ef2d82bf960144b4bfb1bae6242bcc7f/
|   |-- bagit.txt
|   |-- manifest-md5.txt
|   |-- readme.txt
|   |-- tagmanifest-md5.txt
|   |-- data/
|   |   |-- resourcemap.xml
|   |   |-- resourcemetadata.xml
|   |   |-- contents/
|   |   |   |-- NAmer_dem_list.cpg
|   |   |   |-- NAmer_dem_list.dbf
|   |   |   |-- NAmer_dem_list.prj
|   |   |   |-- NAmer_dem_list.sbn
|   |   |   |-- NAmer_dem_list.sbx
|   |   |   |-- NAmer_dem_list.shp
|   |   |   |-- NAmer_dem_list.shx
|   |   |   |-- NooksackHUC17110004.cpg
|   |   |   |-- NooksackHUC17110004.shp
|   |   |   |-- NooksackHUC17110004.shx
|   |   |   |-- SouthForkHUC1711000404.shp
|   |   |   |-- SouthForkHUC1711000404.shx
|   |   |   |-- NooksackHUC17110004.dbf
|   |   |   |-- NooksackHUC17110004.prj
|   |   |   |-- Observatory_nooksack_hybridbiascorrection_20190926.ipynb
|   |   |   |-- Observatory_skagit_hybridbiascorrection_20190315.ipynb
|   |   |   |-- OGH_puyallup_hybridbiascorrection_20190315.ipynb
|   |   |   |-- SkookumHUC171100040404.cpg
|   |   |   |-- SkookumHUC171100040404.shp
|   |   |   |-- SkookumHUC171100040404.shx
|   |   |   |-- SouthForkHUC1711000404.dbf
|   |   |   |-- SouthForkHUC1711000404.prj
|   |   |   |-- SkookumHUC171100040404.dbf
|   |   |   |-- SkookumHUC171100040404.prj
|   |   |   |-- SouthForkHUC1711000404.cpg
|   |   |   |-- Observatory_nooksack_hybridbiascorrection_20200302.ipynb
|   |   |   |-- .ipynb_checkpoints/
|   |   |   |   |-- Observatory_nooksack_hybridbiascorrection_20190926-checkpoint.ipynb
|   |   |   |   |-- Observatory_nooksack_hybridbiascorrection_20200302-checkpoint.ipynb

Do you want to overwrite these data [Y/n]? n
Found the following notebook(s) associated with this HydroShare resource.
Click the link(s) below to launch the notebook.
Found the following file(s) associated with this HydroShare resource.
NAmer_dem_list.cpg
NAmer_dem_list.dbf
NAmer_dem_list.prj
NAmer_dem_list.sbn
NAmer_dem_list.sbx
NAmer_dem_list.shp
NAmer_dem_list.shx
NooksackHUC17110004.cpg
NooksackHUC17110004.shp
NooksackHUC17110004.shx
SouthForkHUC1711000404.shp
SouthForkHUC1711000404.shx
NooksackHUC17110004.dbf
NooksackHUC17110004.prj
Observatory_nooksack_hybridbiascorrection_20190926.ipynb
Observatory_skagit_hybridbiascorrection_20190315.ipynb
OGH_puyallup_hybridbiascorrection_20190315.ipynb
SkookumHUC171100040404.cpg
SkookumHUC171100040404.shp
SkookumHUC171100040404.shx
SouthForkHUC1711000404.dbf
SouthForkHUC1711000404.prj
SkookumHUC171100040404.dbf
SkookumHUC171100040404.prj
SouthForkHUC1711000404.cpg
Observatory_nooksack_hybridbiascorrection_20200302.ipynb
These files are stored in a dictionary called hs.content for your convenience. To access a file, simply issue the following command where MY_FILE is one of the files listed above:
hs.content["MY_FILE"] 

In [37]:
# Generate list of stations to download
mappingfile=ogh.treatgeoself(shapefile=skookum, NAmer=NAmer, buffer_distance=0.09, 
                              mappingfile=os.path.join(os.getcwd(),'skookum_mappingfile.csv'))
print(mappingfile)


(20, 4)
   FID       LAT      LONG_    ELEV
0    0  48.78125 -121.96875  1029.0
1    1  48.78125 -122.03125   740.0
2    2  48.78125 -122.09375   526.0
3    3  48.78125 -122.15625   403.0
4    4  48.71875 -121.90625  1061.0
/home/jovyan/work/notebooks/data/e47aabb406bc45a28f34b97a832daa08/e47aabb406bc45a28f34b97a832daa08/data/contents/skookum_mappingfile.csv

Commercial Break for Python lession on functions and Contributing to the Observatory

In the next step, we want to select grid centroid of the lowest elevation grid cells

View the station locations in this interactive Google map of the climate dataset grid centroids and Skookum watershed.

We can do this by sorting and filtering the mappingfile by elevation, but how you select and apply a global correction to the atmospheric model grid to fit the monthly means at the low elevation stations, will likely vary by watershed and data availability and use of the model you are developing.

In the next few steps, we explain how to manually explore the data table, select centroids, and create a new file to map only the low elevation centroids for further analysis. Choose your own adventure.

1) Manual investigation options: change the spatial count of grid cell centroids to include and change the name of the output file (csv).

2) Automate by Editing the OGH treatgeoself() function: rename the function, test that it works, check the output compared to the manual steps.

Share and Contribute!!

Please share your new functions at https://github.com/ChristinaB/Observatory (April-May 2020) and the main Observatory repository (after June 2020).

1) Manual investigation: How many grid cells in your spatial average of low elevation centroids?


In [38]:
# How many grid cells in your spatial average of low elevation centroids?  
spatialcount=3   #this should be more than one station, but within less than 500 m elevation change to avoid -6 C/km lapse rate assumptions in temperature. 

#read mappingfile, it's a simple csv
all_centroids=pd.read_csv(mappingfile1)
#put into a Pandas dataframe
df_centroids=pd.DataFrame(all_centroids)
#print header plus a few rows to see the column names
df_centroids.head()
#sort by elevation
elev_sort_centroids=df_centroids.sort_values(by='ELEV')
#print header plus a few rows to see the low elevation values
elev_sort_centroids.head()
#save selection of low elevation points (we know these are near the Coop station at Acme)
print(elev_sort_centroids[:spatialcount])
elev_sort_centroids[:spatialcount].to_csv("mappinfile_3_lowelevation.csv")


    FID       LAT      LONG_   ELEV
15   15  48.65625 -122.21875  302.0
9     9  48.71875 -122.21875  318.0
8     8  48.71875 -122.15625  330.0

2) Automate the function: How many grid cells in your spatial average of low elevation centroids?


In [40]:
def treatgeoself_lowfilter(spatialcount,shapefile, NAmer, mappingfile=os.path.join(os.getcwd(), 'mappingfile.csv'), buffer_distance=0.06):
    """
    TreatGeoSelf to some [data] lovin'!
    shapefile: (dir) the path to an ESRI shapefile for the region of interest
    Namer: (dir) the path to the ESRI shapefile, which has each 1/16th-degree gridded cell centroid and DEM elevation
    mappingfile: (str) the name of the output file; default is 'mappingfile.csv'
    buffer_distance: (float64) the multiplier for increasing the geodetic boundary area; default is 0.06
    """
    # conform projections to longlat values in WGS84
    ogh.reprojShapefile(shapefile, newprojdictionary={'proj': 'longlat', 'ellps': 'WGS84', 'datum': 'WGS84'}, outpath=None)

    # read shapefile into a multipolygon shape-object
    shape_mp = ogh.getFullShape(shapefile)

    # read in the North American continental DEM points for the station elevations
    NAmer_datapoints = ogh.readShapefileTable(NAmer).rename(columns={'Lat': 'LAT', 'Long': 'LONG_', 'Elev': 'ELEV'})

    # generate maptable
    maptable = ogh.filterPointsinShape(shape_mp,
                                   points_lat=NAmer_datapoints.LAT,
                                   points_lon=NAmer_datapoints.LONG_,
                                   points_elev=NAmer_datapoints.ELEV,
                                   buffer_distance=buffer_distance, buffer_resolution=16,
                                   labels=['LAT', 'LONG_', 'ELEV'])
    maptable.reset_index(inplace=True)
    maptable=maptable.sort_values(by='ELEV')
    maptable = maptable.rename(columns={'index': 'FID'})
    elev_filter_maptable = maptable[:spatialcount] 
    print(elev_filter_maptable.shape)
    print(elev_filter_maptable.head())

    # print the mappingfile
    elev_filter_maptable.to_csv(mappingfile, sep=',', header=True, index=False)
    return(mappingfile)

In [41]:
# Use the function to Generate list of stations to download
mappingfile_low=treatgeoself_lowfilter(spatialcount,shapefile=skookum, NAmer=NAmer, buffer_distance=0.09, 
                              mappingfile=os.path.join(os.getcwd(),'acme_low_3_elev_mappingfile.csv'))
print(mappingfile_low)


(3, 4)
    FID       LAT      LONG_   ELEV
15   15  48.65625 -122.21875  302.0
9     9  48.71875 -122.21875  318.0
8     8  48.71875 -122.15625  330.0
/home/jovyan/work/notebooks/data/e47aabb406bc45a28f34b97a832daa08/e47aabb406bc45a28f34b97a832daa08/data/contents/acme_low_3_elev_mappingfile.csv

End of Commercial Break

Map the Gridded Cell Centroids that intersect with the watersheds of interest

Summarize the file availability from each watershed mapping file

2. Download climate data

Get the daily data for a gridded observation dataset and an atmospheric model for all grid cells of interest.


In [58]:
ogh.getDailyMET_livneh2013(homedir, mappingfile)
ogh.getDailyWRF_salathe2014(homedir, mappingfile)


Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-121.90625 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.78125_-122.03125 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.78125_-122.15625 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.78125_-121.96875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.78125_-122.09375 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-121.96875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-122.03125 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-122.15625 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-122.09375 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-122.21875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-121.90625 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-121.96875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-122.03125 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-122.15625 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-122.09375 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-122.21875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.59375_-121.96875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.59375_-122.03125 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.59375_-122.09375 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.59375_-122.15625 unzipped
downloaded: data_48.71875_-122.03125
downloaded: data_48.71875_-122.15625
downloaded: data_48.65625_-122.09375
downloaded: data_48.59375_-122.03125
downloaded: data_48.78125_-122.09375
downloaded: data_48.59375_-122.15625
downloaded: data_48.59375_-121.96875
downloaded: data_48.65625_-121.90625
downloaded: data_48.78125_-122.15625
downloaded: data_48.71875_-122.21875
downloaded: data_48.71875_-121.90625
downloaded: data_48.65625_-122.15625
downloaded: data_48.78125_-121.96875
downloaded: data_48.71875_-121.96875
downloaded: data_48.71875_-122.09375
downloaded: data_48.65625_-121.96875
downloaded: data_48.59375_-122.09375
downloaded: data_48.65625_-122.03125
downloaded: data_48.65625_-122.21875
downloaded: data_48.78125_-122.03125
Out[58]:
'/home/jovyan/work/notebooks/data/e47aabb406bc45a28f34b97a832daa08/e47aabb406bc45a28f34b97a832daa08/data/contents/salathe2014/WWA_1950_2010/raw'

Repeat for low elevation grid cells.


In [59]:
ogh.getDailyMET_livneh2013(homedir, mappingfile_low)
ogh.getDailyWRF_salathe2014(homedir, mappingfile_low)


Meteorology_Livneh_CONUSExt_v.1.2_2013_48.65625_-122.21875 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-122.15625 unzipped
Meteorology_Livneh_CONUSExt_v.1.2_2013_48.71875_-122.21875 unzipped
downloaded: data_48.71875_-122.15625
downloaded: data_48.71875_-122.21875
downloaded: data_48.65625_-122.21875
Out[59]:
'/home/jovyan/work/notebooks/data/e47aabb406bc45a28f34b97a832daa08/e47aabb406bc45a28f34b97a832daa08/data/contents/salathe2014/WWA_1950_2010/raw'

3. Put data in dictionaries by watershed


In [62]:
ltm_skook = ogh.gridclim_dict(mappingfile=mappingfile,
                               metadata=meta_file,
                               dataset='dailymet_livneh2013',
                               file_start_date=dr1['start_date'], 
                               file_end_date=dr1['end_date'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1])

ltm_skook = ogh.gridclim_dict(mappingfile=mappingfile,
                               metadata=meta_file,
                               dataset='dailywrf_salathe2014',
                               file_start_date=dr2['start_date'], 
                               file_end_date=dr2['end_date'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1],
                               df_dict=ltm_skook)


   FID       LAT      LONG_    ELEV  \
0    0  48.78125 -121.96875  1029.0   
1    1  48.78125 -122.03125   740.0   
2    2  48.78125 -122.09375   526.0   
3    3  48.78125 -122.15625   403.0   
4    4  48.71875 -121.90625  1061.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:20
Minimum elevation: 302.0m
Mean elevation: 709.95m
Maximum elevation: 1201.0m
Number of data files within elevation range (302.0:1201.0): 20
PRECIP dataframe reading to start: 0:00:00.033846
PRECIP dataframe complete:0:00:00.269086
TMAX dataframe reading to start: 0:00:00.301413
TMAX dataframe complete:0:00:00.539390
TMIN dataframe reading to start: 0:00:00.572643
TMIN dataframe complete:0:00:00.807468
WINDSPD dataframe reading to start: 0:00:00.839999
WINDSPD dataframe complete:0:00:01.071395
PRECIP_dailymet_livneh2013 calculations completed in 0:00:00.031779
TMAX_dailymet_livneh2013 calculations completed in 0:00:00.025945
TMIN_dailymet_livneh2013 calculations completed in 0:00:00.026095
WINDSPD_dailymet_livneh2013 calculations completed in 0:00:00.025782
   FID       LAT      LONG_    ELEV  \
0    0  48.78125 -121.96875  1029.0   
1    1  48.78125 -122.03125   740.0   
2    2  48.78125 -122.09375   526.0   
3    3  48.78125 -122.15625   403.0   
4    4  48.71875 -121.90625  1061.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:20
Minimum elevation: 302.0m
Mean elevation: 709.95m
Maximum elevation: 1201.0m
Number of data files within elevation range (302.0:1201.0): 20
PRECIP dataframe reading to start: 0:00:00.034966
PRECIP dataframe complete:0:00:00.250979
TMAX dataframe reading to start: 0:00:00.283681
TMAX dataframe complete:0:00:00.501405
TMIN dataframe reading to start: 0:00:00.534152
TMIN dataframe complete:0:00:00.746396
WINDSPD dataframe reading to start: 0:00:00.779211
WINDSPD dataframe complete:0:00:00.988146
PRECIP_dailywrf_salathe2014 calculations completed in 0:00:00.031835
TMAX_dailywrf_salathe2014 calculations completed in 0:00:00.030010
TMIN_dailywrf_salathe2014 calculations completed in 0:00:00.030090
WINDSPD_dailywrf_salathe2014 calculations completed in 0:00:00.029910

In [63]:
ltm_skook_low = ogh.gridclim_dict(mappingfile=mappingfile_low,
                               metadata=meta_file,
                               dataset='dailymet_livneh2013',
                               file_start_date=dr1['start_date'], 
                               file_end_date=dr1['end_date'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1])

ltm_skook_low = ogh.gridclim_dict(mappingfile=mappingfile_low,
                               metadata=meta_file,
                               dataset='dailywrf_salathe2014',
                               file_start_date=dr2['start_date'], 
                               file_end_date=dr2['end_date'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1],
                               df_dict=ltm_skook_low)


   FID       LAT      LONG_   ELEV  \
0   15  48.65625 -122.21875  302.0   
1    9  48.71875 -122.21875  318.0   
2    8  48.71875 -122.15625  330.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:3
Minimum elevation: 302.0m
Mean elevation: 316.6666666666667m
Maximum elevation: 330.0m
Number of data files within elevation range (302.0:330.0): 3
PRECIP dataframe reading to start: 0:00:00.008158
PRECIP dataframe complete:0:00:00.082543
TMAX dataframe reading to start: 0:00:00.088504
TMAX dataframe complete:0:00:00.148860
TMIN dataframe reading to start: 0:00:00.154692
TMIN dataframe complete:0:00:00.217247
WINDSPD dataframe reading to start: 0:00:00.223139
WINDSPD dataframe complete:0:00:00.290650
PRECIP_dailymet_livneh2013 calculations completed in 0:00:00.025960
TMAX_dailymet_livneh2013 calculations completed in 0:00:00.020972
TMIN_dailymet_livneh2013 calculations completed in 0:00:00.020443
WINDSPD_dailymet_livneh2013 calculations completed in 0:00:00.020443
   FID       LAT      LONG_   ELEV  \
0   15  48.65625 -122.21875  302.0   
1    9  48.71875 -122.21875  318.0   
2    8  48.71875 -122.15625  330.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:3
Minimum elevation: 302.0m
Mean elevation: 316.6666666666667m
Maximum elevation: 330.0m
Number of data files within elevation range (302.0:330.0): 3
PRECIP dataframe reading to start: 0:00:00.007816
PRECIP dataframe complete:0:00:00.058835
TMAX dataframe reading to start: 0:00:00.064545
TMAX dataframe complete:0:00:00.157685
TMIN dataframe reading to start: 0:00:00.163651
TMIN dataframe complete:0:00:00.210117
WINDSPD dataframe reading to start: 0:00:00.216332
WINDSPD dataframe complete:0:00:00.263489
PRECIP_dailywrf_salathe2014 calculations completed in 0:00:00.026385
TMAX_dailywrf_salathe2014 calculations completed in 0:00:00.024661
TMIN_dailywrf_salathe2014 calculations completed in 0:00:00.024691
WINDSPD_dailywrf_salathe2014 calculations completed in 0:00:00.024470

In [71]:
#EXAMPLE of manual or shapefile based creation of the mappingfile
#low_shapefile = 'a file not created in this workshop.csv'
#3/3/2020 manually made mapping file for lowest point near Acme grid cell
#mappingfile_low=os.path.join(homedir,'skookum_acme_mappingfile.csv')
#print(mappingfile_low)
#dr[1]
#ogh.getDailyMET_livneh2013(homedir, mappingfile_low)
#ogh.getDailyWRF_salathe2014(homedir, mappingfile_low)
#ltm_low = ogh.gridclim_dict(mappingfile=mappingfile_low,
#                               metadata=meta_file,
#                               dataset='dailymet_livneh2013',
#                               file_start_date=dr1['start_date'], 
#                               file_end_date=dr1['end_date'],
#                               file_time_step=dr1['temporal_resolution'],
#                               subset_start_date=dr[0],
#                               subset_end_date=dr[1])

#ltm_low = ogh.gridclim_dict(mappingfile=mappingfile_low,
#                               metadata=meta_file,
#                               dataset='dailywrf_salathe2014',
#                               file_start_date=dr2['start_date'], 
#                               file_end_date=dr2['end_date'],
#                               file_time_step=dr1['temporal_resolution'],
#                               subset_start_date=dr[0],
#                               subset_end_date=dr[1],
#                               df_dict=ltm_low)

4. Local:

Generate dataframe of correction factors for each i,j grid cell


In [64]:
BiasCorr_wrfbc_skook = ogh.compute_diffs(df_dict=ltm_skook, df_str='skookum',
                                   gridclimname1='dailywrf_salathe2014',
                                   gridclimname2='dailymet_livneh2013',
                                   prefix2=['month'],
                                   prefix1=meta_file['dailymet_livneh2013']['variable_list'])

BiasCorr_wrfbc_skook_P = ogh.compute_ratios(df_dict=ltm_skook, df_str='skookum',
                                      gridclimname1='dailywrf_salathe2014',
                                      gridclimname2='dailymet_livneh2013',
                                      prefix2=['month'],
                                      prefix1=meta_file['dailymet_livneh2013']['variable_list'])

           
BiasCorr_wrfbc_skook['PRECIP_skookum'] = BiasCorr_wrfbc_skook_P['PRECIP_skookum']
ogh.saveDictOfDf('BiasCorr_wrfbc_skook.json', dictionaryObject=BiasCorr_wrfbc_skook)
BiasCorrTemplate=BiasCorr_wrfbc_skook #size of input grid cells

In [66]:
print(BiasCorr_wrfbc_skook['PRECIP_skookum'][0])
print(BiasCorr_wrfbc_skook_P['PRECIP_skookum'][0])


     48.78125
   -121.96875
1    1.555205
2    1.672712
3    1.884841
4    2.077512
5    1.629646
6    1.906496
7    1.994424
8    1.337161
9    1.239952
10   1.248857
11   1.809441
12   1.450829
     48.78125
   -121.96875
1    1.555205
2    1.672712
3    1.884841
4    2.077512
5    1.629646
6    1.906496
7    1.994424
8    1.337161
9    1.239952
10   1.248857
11   1.809441
12   1.450829

In [67]:
print(BiasCorr_wrfbc_skook)

print('WRF')
print(ltm_skook['month_PRECIP_dailywrf_salathe2014'][0])
print('Obs')
print(ltm_skook['month_PRECIP_dailymet_livneh2013'][0])
print('LivBCWRF = Local Correction Factor')

print(BiasCorr_wrfbc_skook)


{'PRECIP_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    1.555205   1.312502   1.135985   1.202662   1.343859   1.170480   
2    1.672712   1.423598   1.271726   1.304109   1.525992   1.263092   
3    1.884841   1.609824   1.370005   1.380164   1.664649   1.469164   
4    2.077512   1.857882   1.652831   1.550220   2.055656   1.867245   
5    1.629646   1.964637   1.943215   1.688000   1.324599   1.452084   
6    1.906496   1.786993   1.638473   1.561718   1.774762   1.629132   
7    1.994424   1.687336   1.541184   1.323346   1.304764   1.445946   
8    1.337161   1.229111   1.165070   1.122198   1.321313   1.279604   
9    1.239952   1.109319   1.014277   1.027453   1.256846   1.081451   
10   1.248857   1.072364   0.962403   1.047684   1.189831   0.974402   
11   1.809441   1.514989   1.279813   1.234669   1.454073   1.375575   
12   1.450829   1.224130   1.074244   1.138759   1.282512   1.086233   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    1.188901   1.200626   1.600851   1.422228   0.941618   1.117805   
2    1.279077   1.303622   1.694968   1.485071   1.057814   1.249854   
3    1.468565   1.465887   1.744666   1.566470   1.123112   1.262468   
4    1.807233   1.727046   1.860717   1.641250   1.453746   1.624277   
5    1.905986   1.517861   1.779904   1.555437   1.809022   1.898645   
6    1.675087   1.639105   1.853952   1.583767   2.072408   2.115181   
7    1.615403   1.495087   1.460411   1.232629   1.842132   2.037223   
8    1.207417   1.172222   1.346890   1.165087   1.744984   1.775776   
9    1.085541   1.086504   1.308778   1.157138   1.153629   1.271886   
10   0.984740   1.019265   1.362259   1.230174   0.978926   1.102315   
11   1.402176   1.344189   1.527965   1.353011   0.989225   1.072144   
12   1.090157   1.125076   1.515188   1.338354   0.910455   1.042653   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    0.958953   1.535966   0.874698   1.410050   0.844208   1.305639   
2    1.054606   1.655649   0.869171   1.420254   0.930420   1.320195   
3    1.144519   1.721262   0.976645   1.529000   0.951363   1.450818   
4    1.528463   1.952782   1.045321   1.588284   1.274216   1.650346   
5    2.027227   2.092300   1.487154   1.487306   1.464946   1.814150   
6    1.868731   1.865467   1.250501   1.548787   1.746103   1.860709   
7    1.869988   1.669291   0.993630   1.175459   1.813993   1.712203   
8    1.596785   1.404037   0.920854   1.129572   1.573326   1.509606   
9    1.112101   1.371355   0.770588   1.172951   1.028854   1.247422   
10   0.922685   1.380901   0.779578   1.254788   0.837825   1.188735   
11   1.022268   1.542284   0.886308   1.329186   0.795532   1.301082   
12   0.904367   1.477229   0.830733   1.321481   0.777068   1.223278   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1    1.323640   0.858044  
2    1.340597   0.827516  
3    1.479106   0.957319  
4    1.694715   1.050273  
5    1.840806   1.470680  
6    1.815096   1.205307  
7    1.510260   1.003388  
8    1.319289   0.887672  
9    1.304857   0.799014  
10   1.221931   0.764721  
11   1.327860   0.879219  
12   1.248549   0.828064  , 'TMAX_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    0.390201  -0.512126  -0.971185  -0.687356  -0.042665   1.486356   
2   -1.847893  -2.633587  -2.677754  -2.016529  -2.088114  -0.513819   
3   -3.989439  -4.597234  -4.171354  -3.128964  -4.071708  -2.447049   
4   -5.540628  -5.791579  -4.819481  -3.294579  -5.547175  -3.665038   
5   -5.358033  -5.222152  -4.373570  -3.079910  -5.785500  -3.290116   
6   -4.292060  -4.250273  -3.929005  -3.110104  -5.146301  -2.611005   
7   -3.965674  -4.542295  -4.249233  -3.452068  -3.872015  -2.092951   
8   -3.490487  -4.414627  -4.038059  -3.276319  -2.891237  -1.577800   
9   -2.020585  -2.880984  -2.554863  -1.875770  -1.710705  -0.286836   
10  -0.749974  -1.517060  -1.486335  -0.996071  -0.866510   0.674511   
11   0.101525  -0.716568  -1.114454  -0.743268  -0.266492   1.341186   
12   0.787610  -0.126393  -0.665828  -0.364812   0.380434   1.904141   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    0.879635  -1.037922  -1.608757  -0.993971  -0.006288   1.517292   
2   -0.910290  -2.552159  -2.745618  -1.903854  -1.875473  -0.274655   
3   -2.621544  -3.958371  -3.712655  -2.656441  -3.606293  -1.915362   
4   -3.537508  -4.594481  -3.848148  -2.611601  -4.827470  -2.804322   
5   -2.703580  -4.132988  -3.570666  -2.510106  -4.036531  -1.787647   
6   -1.836339  -3.588372  -3.509628  -2.711109  -2.342055  -0.728792   
7   -2.014500  -3.799281  -3.781227  -3.032443  -1.961957  -0.668614   
8   -1.951861  -3.707192  -3.648868  -2.906002  -1.984992  -0.701539   
9   -0.575005  -2.285989  -2.298421  -1.521175  -0.957732   0.465650   
10   0.346584  -1.388884  -1.608609  -0.861592  -0.252961   1.227451   
11   0.899180  -1.008087  -1.479437  -0.814989   0.151634   1.696929   
12   1.317964  -0.649402  -1.205849  -0.619238   0.496267   2.040465   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    1.293427  -1.076949  -0.961444  -1.465843  -1.054283  -1.251830   
2   -0.356599  -2.439501  -1.906431  -2.187086  -2.490958  -2.518497   
3   -1.862686  -3.688265  -2.692295  -2.744389  -3.712253  -3.595838   
4   -2.480246  -4.064628  -2.610355  -2.525962  -4.207016  -3.793235   
5   -1.384051  -3.387366  -2.240524  -2.362766  -3.723236  -3.157990   
6   -0.834262  -3.129328  -2.298115  -2.553639  -2.992093  -2.882066   
7   -1.008741  -3.391417  -2.558477  -2.792893  -3.032274  -3.099540   
8   -1.027969  -3.389588  -2.520185  -2.753184  -3.066579  -3.152972   
9    0.259798  -2.043694  -1.149716  -1.435694  -1.917546  -1.932142   
10   1.024627  -1.304897  -0.630058  -0.973628  -1.173168  -1.230513   
11   1.476645  -0.898809  -0.644011  -1.101486  -0.794202  -0.904743   
12   1.811386  -0.579720  -0.501095  -1.050291  -0.492343  -0.676245   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1   -0.900497   2.330291  
2   -2.020952   1.501422  
3   -3.039656   0.791856  
4   -3.205027   0.911552  
5   -2.655235   1.186515  
6   -2.497251   1.110683  
7   -2.742819   0.876896  
8   -2.806520   0.816494  
9   -1.513661   2.118705  
10  -0.831994   2.660746  
11  -0.573770   2.716295  
12  -0.381486   2.814162  , 'TMIN_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    3.021174   2.399402   2.106356   2.527097   2.506716   4.263146   
2    2.358741   1.730569   1.488212   2.024098   1.962768   3.761915   
3    1.089164   0.536975   0.468001   1.113633   0.693427   2.540106   
4    0.729311   0.316077   0.381792   1.123596   0.426913   2.392246   
5    0.772089   0.379281   0.206822   0.627536   0.279646   2.416727   
6    0.979995   0.394530  -0.017066   0.091967   0.309847   2.359464   
7    1.904426   1.102052   0.729186   0.823083   1.642734   3.414109   
8    2.420735   1.547430   1.243215   1.337287   2.371200   3.977652   
9    3.756792   3.005038   2.657164   2.766246   3.438612   5.176290   
10   4.333659   3.611386   3.212036   3.339778   3.912702   5.691962   
11   3.620464   3.063568   2.768579   3.123727   3.022557   4.908836   
12   3.062004   2.528800   2.345891   2.837816   2.462723   4.313215   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    3.963162   2.244257   1.789217   2.430925   2.873215   4.573342   
2    3.562031   1.838967   1.454713   2.117562   2.517789   4.222385   
3    2.368858   0.751222   0.468239   1.206404   1.385531   3.065436   
4    2.275689   0.687180   0.470945   1.207186   1.171481   3.015355   
5    2.416753   0.524400   0.006367   0.599625   1.420196   3.213760   
6    2.334137   0.317082  -0.501361  -0.038104   1.679536   3.139230   
7    3.023797   1.042824   0.177895   0.563612   2.568551   3.935473   
8    3.353559   1.486896   0.643855   1.020238   2.802036   4.218350   
9    4.644519   2.884639   2.112836   2.488956   3.864459   5.400016   
10   5.296029   3.504204   2.799228   3.238345   4.286076   5.941370   
11   4.676858   2.941579   2.462344   3.049246   3.604590   5.325978   
12   4.086959   2.430100   2.080719   2.751142   2.910148   4.669498   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    4.509566   2.257298   2.661412   2.159551   2.042010   2.067002   
2    4.167545   1.990836   2.426529   1.941822   1.786164   1.820696   
3    2.997742   0.900719   1.443146   1.005912   0.772454   0.776727   
4    3.049169   0.933153   1.555945   1.074787   0.740366   0.864699   
5    3.141074   0.713564   1.089974   0.501237   0.559149   0.676002   
6    2.811650   0.235781   0.560913  -0.094475   0.305317   0.217470   
7    3.525833   0.892004   1.256843   0.517657   0.967340   0.859519   
8    3.838070   1.246256   1.699413   0.972094   1.228657   1.168202   
9    5.119317   2.571257   3.114169   2.412617   2.445760   2.476612   
10   5.765309   3.302676   3.824802   3.180460   3.094188   3.161137   
11   5.231377   2.908443   3.379492   2.843907   2.700437   2.749836   
12   4.644410   2.437409   2.936161   2.464632   2.183094   2.246230   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1    2.581375   5.993913  
2    2.311451   5.744486  
3    1.238657   4.744479  
4    1.294404   4.812115  
5    1.050301   4.382158  
6    0.541082   3.805492  
7    1.206430   4.485050  
8    1.564987   4.887234  
9    2.983268   6.343093  
10   3.707911   7.086912  
11   3.217918   6.636896  
12   2.740677   6.223072  , 'WINDSPD_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    2.059312   2.130022   1.943555   1.758524   1.503031   1.740401   
2    2.071931   2.124089   1.925563   1.728280   1.559707   1.782179   
3    1.976048   2.026410   1.909802   1.794179   1.555298   1.727175   
4    1.755627   1.785508   1.683840   1.582761   1.449465   1.571505   
5    1.213505   1.262129   1.234266   1.207165   1.022193   1.103391   
6    0.941658   0.997374   0.992990   0.988967   0.749600   0.817503   
7    0.622041   0.674850   0.661259   0.647750   0.512832   0.568567   
8    0.761816   0.808196   0.779429   0.750896   0.622486   0.684166   
9    1.329461   1.353904   1.269816   1.186110   1.105294   1.192705   
10   1.690257   1.730929   1.647628   1.565237   1.282794   1.427790   
11   2.036230   2.099175   1.974463   1.851025   1.480603   1.686991   
12   2.158969   2.237056   2.078554   1.921300   1.582067   1.818161   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    1.905723   1.905598   1.719866   1.598852   1.219165   1.459177   
2    1.932670   1.925228   1.727202   1.584349   1.285693   1.517324   
3    1.851412   1.886960   1.770605   1.688556   1.293727   1.485622   
4    1.656485   1.663998   1.562381   1.481905   1.270245   1.400245   
5    1.170786   1.168027   1.139962   1.113032   0.997866   1.045827   
6    0.883877   0.884484   0.879859   0.883028   0.753558   0.767043   
7    0.611149   0.556257   0.542238   0.536615   0.586987   0.583788   
8    0.729176   0.685477   0.656710   0.651850   0.637088   0.655265   
9    1.244983   1.210864   1.126706   1.063443   0.987473   1.070930   
10   1.531309   1.568570   1.486108   1.434385   0.990226   1.162210   
11   1.838548   1.888964   1.765323   1.698336   1.113368   1.344765   
12   1.985083   2.004307   1.846392   1.749322   1.254759   1.501799   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    1.633888   1.631620   1.630624   1.579816   1.363666   1.553947   
2    1.685069   1.675859   1.667598   1.598810   1.390274   1.575357   
3    1.635985   1.669800   1.704624   1.680378   1.408168   1.570575   
4    1.499916   1.506168   1.513237   1.475718   1.296644   1.410191   
5    1.087082   1.083127   1.079718   1.059980   0.963855   1.020015   
6    0.782833   0.781979   0.781486   0.781997   0.693558   0.720083   
7    0.574049   0.518377   0.462868   0.437454   0.464264   0.470894   
8    0.665213   0.620550   0.576235   0.561990   0.526809   0.556137   
9    1.128561   1.093012   1.057957   1.011206   0.963562   1.039942   
10   1.299867   1.335033   1.371152   1.362039   1.072304   1.223262   
11   1.527036   1.575249   1.624935   1.623721   1.225207   1.419861   
12   1.687238   1.704284   1.722757   1.693323   1.376754   1.577534   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1    1.645734   1.670867  
2    1.667917   1.687921  
3    1.674265   1.728315  
4    1.490609   1.518001  
5    1.090942   1.108068  
6    0.771315   0.785095  
7    0.496535   0.463220  
8    0.607073   0.588868  
9    1.102377   1.093977  
10   1.332069   1.388392  
11   1.541397   1.611093  
12   1.686382   1.729903  }
WRF
     48.78125
   -121.96875
1   16.246235
2   13.491062
3   11.649133
4    8.666093
5    5.989942
6    5.477842
7    2.818112
8    2.939492
9    4.751792
10  10.144897
11  15.690995
12  16.126103
Obs
     48.78125
   -121.96875
1   10.446364
2    8.065380
3    6.180434
4    4.171380
5    3.675608
6    2.873251
7    1.412996
8    2.198308
9    3.832240
10   8.123347
11   8.671735
12  11.115098
LivBCWRF = Local Correction Factor
{'PRECIP_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    1.555205   1.312502   1.135985   1.202662   1.343859   1.170480   
2    1.672712   1.423598   1.271726   1.304109   1.525992   1.263092   
3    1.884841   1.609824   1.370005   1.380164   1.664649   1.469164   
4    2.077512   1.857882   1.652831   1.550220   2.055656   1.867245   
5    1.629646   1.964637   1.943215   1.688000   1.324599   1.452084   
6    1.906496   1.786993   1.638473   1.561718   1.774762   1.629132   
7    1.994424   1.687336   1.541184   1.323346   1.304764   1.445946   
8    1.337161   1.229111   1.165070   1.122198   1.321313   1.279604   
9    1.239952   1.109319   1.014277   1.027453   1.256846   1.081451   
10   1.248857   1.072364   0.962403   1.047684   1.189831   0.974402   
11   1.809441   1.514989   1.279813   1.234669   1.454073   1.375575   
12   1.450829   1.224130   1.074244   1.138759   1.282512   1.086233   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    1.188901   1.200626   1.600851   1.422228   0.941618   1.117805   
2    1.279077   1.303622   1.694968   1.485071   1.057814   1.249854   
3    1.468565   1.465887   1.744666   1.566470   1.123112   1.262468   
4    1.807233   1.727046   1.860717   1.641250   1.453746   1.624277   
5    1.905986   1.517861   1.779904   1.555437   1.809022   1.898645   
6    1.675087   1.639105   1.853952   1.583767   2.072408   2.115181   
7    1.615403   1.495087   1.460411   1.232629   1.842132   2.037223   
8    1.207417   1.172222   1.346890   1.165087   1.744984   1.775776   
9    1.085541   1.086504   1.308778   1.157138   1.153629   1.271886   
10   0.984740   1.019265   1.362259   1.230174   0.978926   1.102315   
11   1.402176   1.344189   1.527965   1.353011   0.989225   1.072144   
12   1.090157   1.125076   1.515188   1.338354   0.910455   1.042653   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    0.958953   1.535966   0.874698   1.410050   0.844208   1.305639   
2    1.054606   1.655649   0.869171   1.420254   0.930420   1.320195   
3    1.144519   1.721262   0.976645   1.529000   0.951363   1.450818   
4    1.528463   1.952782   1.045321   1.588284   1.274216   1.650346   
5    2.027227   2.092300   1.487154   1.487306   1.464946   1.814150   
6    1.868731   1.865467   1.250501   1.548787   1.746103   1.860709   
7    1.869988   1.669291   0.993630   1.175459   1.813993   1.712203   
8    1.596785   1.404037   0.920854   1.129572   1.573326   1.509606   
9    1.112101   1.371355   0.770588   1.172951   1.028854   1.247422   
10   0.922685   1.380901   0.779578   1.254788   0.837825   1.188735   
11   1.022268   1.542284   0.886308   1.329186   0.795532   1.301082   
12   0.904367   1.477229   0.830733   1.321481   0.777068   1.223278   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1    1.323640   0.858044  
2    1.340597   0.827516  
3    1.479106   0.957319  
4    1.694715   1.050273  
5    1.840806   1.470680  
6    1.815096   1.205307  
7    1.510260   1.003388  
8    1.319289   0.887672  
9    1.304857   0.799014  
10   1.221931   0.764721  
11   1.327860   0.879219  
12   1.248549   0.828064  , 'TMAX_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    0.390201  -0.512126  -0.971185  -0.687356  -0.042665   1.486356   
2   -1.847893  -2.633587  -2.677754  -2.016529  -2.088114  -0.513819   
3   -3.989439  -4.597234  -4.171354  -3.128964  -4.071708  -2.447049   
4   -5.540628  -5.791579  -4.819481  -3.294579  -5.547175  -3.665038   
5   -5.358033  -5.222152  -4.373570  -3.079910  -5.785500  -3.290116   
6   -4.292060  -4.250273  -3.929005  -3.110104  -5.146301  -2.611005   
7   -3.965674  -4.542295  -4.249233  -3.452068  -3.872015  -2.092951   
8   -3.490487  -4.414627  -4.038059  -3.276319  -2.891237  -1.577800   
9   -2.020585  -2.880984  -2.554863  -1.875770  -1.710705  -0.286836   
10  -0.749974  -1.517060  -1.486335  -0.996071  -0.866510   0.674511   
11   0.101525  -0.716568  -1.114454  -0.743268  -0.266492   1.341186   
12   0.787610  -0.126393  -0.665828  -0.364812   0.380434   1.904141   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    0.879635  -1.037922  -1.608757  -0.993971  -0.006288   1.517292   
2   -0.910290  -2.552159  -2.745618  -1.903854  -1.875473  -0.274655   
3   -2.621544  -3.958371  -3.712655  -2.656441  -3.606293  -1.915362   
4   -3.537508  -4.594481  -3.848148  -2.611601  -4.827470  -2.804322   
5   -2.703580  -4.132988  -3.570666  -2.510106  -4.036531  -1.787647   
6   -1.836339  -3.588372  -3.509628  -2.711109  -2.342055  -0.728792   
7   -2.014500  -3.799281  -3.781227  -3.032443  -1.961957  -0.668614   
8   -1.951861  -3.707192  -3.648868  -2.906002  -1.984992  -0.701539   
9   -0.575005  -2.285989  -2.298421  -1.521175  -0.957732   0.465650   
10   0.346584  -1.388884  -1.608609  -0.861592  -0.252961   1.227451   
11   0.899180  -1.008087  -1.479437  -0.814989   0.151634   1.696929   
12   1.317964  -0.649402  -1.205849  -0.619238   0.496267   2.040465   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    1.293427  -1.076949  -0.961444  -1.465843  -1.054283  -1.251830   
2   -0.356599  -2.439501  -1.906431  -2.187086  -2.490958  -2.518497   
3   -1.862686  -3.688265  -2.692295  -2.744389  -3.712253  -3.595838   
4   -2.480246  -4.064628  -2.610355  -2.525962  -4.207016  -3.793235   
5   -1.384051  -3.387366  -2.240524  -2.362766  -3.723236  -3.157990   
6   -0.834262  -3.129328  -2.298115  -2.553639  -2.992093  -2.882066   
7   -1.008741  -3.391417  -2.558477  -2.792893  -3.032274  -3.099540   
8   -1.027969  -3.389588  -2.520185  -2.753184  -3.066579  -3.152972   
9    0.259798  -2.043694  -1.149716  -1.435694  -1.917546  -1.932142   
10   1.024627  -1.304897  -0.630058  -0.973628  -1.173168  -1.230513   
11   1.476645  -0.898809  -0.644011  -1.101486  -0.794202  -0.904743   
12   1.811386  -0.579720  -0.501095  -1.050291  -0.492343  -0.676245   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1   -0.900497   2.330291  
2   -2.020952   1.501422  
3   -3.039656   0.791856  
4   -3.205027   0.911552  
5   -2.655235   1.186515  
6   -2.497251   1.110683  
7   -2.742819   0.876896  
8   -2.806520   0.816494  
9   -1.513661   2.118705  
10  -0.831994   2.660746  
11  -0.573770   2.716295  
12  -0.381486   2.814162  , 'TMIN_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    3.021174   2.399402   2.106356   2.527097   2.506716   4.263146   
2    2.358741   1.730569   1.488212   2.024098   1.962768   3.761915   
3    1.089164   0.536975   0.468001   1.113633   0.693427   2.540106   
4    0.729311   0.316077   0.381792   1.123596   0.426913   2.392246   
5    0.772089   0.379281   0.206822   0.627536   0.279646   2.416727   
6    0.979995   0.394530  -0.017066   0.091967   0.309847   2.359464   
7    1.904426   1.102052   0.729186   0.823083   1.642734   3.414109   
8    2.420735   1.547430   1.243215   1.337287   2.371200   3.977652   
9    3.756792   3.005038   2.657164   2.766246   3.438612   5.176290   
10   4.333659   3.611386   3.212036   3.339778   3.912702   5.691962   
11   3.620464   3.063568   2.768579   3.123727   3.022557   4.908836   
12   3.062004   2.528800   2.345891   2.837816   2.462723   4.313215   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    3.963162   2.244257   1.789217   2.430925   2.873215   4.573342   
2    3.562031   1.838967   1.454713   2.117562   2.517789   4.222385   
3    2.368858   0.751222   0.468239   1.206404   1.385531   3.065436   
4    2.275689   0.687180   0.470945   1.207186   1.171481   3.015355   
5    2.416753   0.524400   0.006367   0.599625   1.420196   3.213760   
6    2.334137   0.317082  -0.501361  -0.038104   1.679536   3.139230   
7    3.023797   1.042824   0.177895   0.563612   2.568551   3.935473   
8    3.353559   1.486896   0.643855   1.020238   2.802036   4.218350   
9    4.644519   2.884639   2.112836   2.488956   3.864459   5.400016   
10   5.296029   3.504204   2.799228   3.238345   4.286076   5.941370   
11   4.676858   2.941579   2.462344   3.049246   3.604590   5.325978   
12   4.086959   2.430100   2.080719   2.751142   2.910148   4.669498   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    4.509566   2.257298   2.661412   2.159551   2.042010   2.067002   
2    4.167545   1.990836   2.426529   1.941822   1.786164   1.820696   
3    2.997742   0.900719   1.443146   1.005912   0.772454   0.776727   
4    3.049169   0.933153   1.555945   1.074787   0.740366   0.864699   
5    3.141074   0.713564   1.089974   0.501237   0.559149   0.676002   
6    2.811650   0.235781   0.560913  -0.094475   0.305317   0.217470   
7    3.525833   0.892004   1.256843   0.517657   0.967340   0.859519   
8    3.838070   1.246256   1.699413   0.972094   1.228657   1.168202   
9    5.119317   2.571257   3.114169   2.412617   2.445760   2.476612   
10   5.765309   3.302676   3.824802   3.180460   3.094188   3.161137   
11   5.231377   2.908443   3.379492   2.843907   2.700437   2.749836   
12   4.644410   2.437409   2.936161   2.464632   2.183094   2.246230   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1    2.581375   5.993913  
2    2.311451   5.744486  
3    1.238657   4.744479  
4    1.294404   4.812115  
5    1.050301   4.382158  
6    0.541082   3.805492  
7    1.206430   4.485050  
8    1.564987   4.887234  
9    2.983268   6.343093  
10   3.707911   7.086912  
11   3.217918   6.636896  
12   2.740677   6.223072  , 'WINDSPD_skookum':            0          1          2          3          4          5   \
     48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
   -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
1    2.059312   2.130022   1.943555   1.758524   1.503031   1.740401   
2    2.071931   2.124089   1.925563   1.728280   1.559707   1.782179   
3    1.976048   2.026410   1.909802   1.794179   1.555298   1.727175   
4    1.755627   1.785508   1.683840   1.582761   1.449465   1.571505   
5    1.213505   1.262129   1.234266   1.207165   1.022193   1.103391   
6    0.941658   0.997374   0.992990   0.988967   0.749600   0.817503   
7    0.622041   0.674850   0.661259   0.647750   0.512832   0.568567   
8    0.761816   0.808196   0.779429   0.750896   0.622486   0.684166   
9    1.329461   1.353904   1.269816   1.186110   1.105294   1.192705   
10   1.690257   1.730929   1.647628   1.565237   1.282794   1.427790   
11   2.036230   2.099175   1.974463   1.851025   1.480603   1.686991   
12   2.158969   2.237056   2.078554   1.921300   1.582067   1.818161   

           6          7          8          9          10         11  \
     48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
1    1.905723   1.905598   1.719866   1.598852   1.219165   1.459177   
2    1.932670   1.925228   1.727202   1.584349   1.285693   1.517324   
3    1.851412   1.886960   1.770605   1.688556   1.293727   1.485622   
4    1.656485   1.663998   1.562381   1.481905   1.270245   1.400245   
5    1.170786   1.168027   1.139962   1.113032   0.997866   1.045827   
6    0.883877   0.884484   0.879859   0.883028   0.753558   0.767043   
7    0.611149   0.556257   0.542238   0.536615   0.586987   0.583788   
8    0.729176   0.685477   0.656710   0.651850   0.637088   0.655265   
9    1.244983   1.210864   1.126706   1.063443   0.987473   1.070930   
10   1.531309   1.568570   1.486108   1.434385   0.990226   1.162210   
11   1.838548   1.888964   1.765323   1.698336   1.113368   1.344765   
12   1.985083   2.004307   1.846392   1.749322   1.254759   1.501799   

           12         13         14         15         16         17  \
     48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
   -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
1    1.633888   1.631620   1.630624   1.579816   1.363666   1.553947   
2    1.685069   1.675859   1.667598   1.598810   1.390274   1.575357   
3    1.635985   1.669800   1.704624   1.680378   1.408168   1.570575   
4    1.499916   1.506168   1.513237   1.475718   1.296644   1.410191   
5    1.087082   1.083127   1.079718   1.059980   0.963855   1.020015   
6    0.782833   0.781979   0.781486   0.781997   0.693558   0.720083   
7    0.574049   0.518377   0.462868   0.437454   0.464264   0.470894   
8    0.665213   0.620550   0.576235   0.561990   0.526809   0.556137   
9    1.128561   1.093012   1.057957   1.011206   0.963562   1.039942   
10   1.299867   1.335033   1.371152   1.362039   1.072304   1.223262   
11   1.527036   1.575249   1.624935   1.623721   1.225207   1.419861   
12   1.687238   1.704284   1.722757   1.693323   1.376754   1.577534   

           18         19  
     48.59375   48.59375  
   -122.09375 -122.15625  
1    1.645734   1.670867  
2    1.667917   1.687921  
3    1.674265   1.728315  
4    1.490609   1.518001  
5    1.090942   1.108068  
6    0.771315   0.785095  
7    0.496535   0.463220  
8    0.607073   0.588868  
9    1.102377   1.093977  
10   1.332069   1.388392  
11   1.541397   1.611093  
12   1.686382   1.729903  }

In [68]:
Daily_MET_1915_2011_WRFbc, meta_file = ogh.makebelieve(homedir=homedir,
                                                           mappingfile=mappingfile1,
                                                           BiasCorr=BiasCorr_wrfbc_skook,
                                                           metadata=meta_file,
                                                           start_catalog_label='dailymet_livneh2013',
                                                           end_catalog_label='dailymet_livneh2013_wrfbc', 
                                                           file_start_date=None,
                                                           file_end_date=None,
                                                           data_dir=None,
                                                           dest_dir_suffix='biascorrWRF_liv')


   FID       LAT      LONG_    ELEV  \
0    0  48.78125 -121.96875  1029.0   
1    1  48.78125 -122.03125   740.0   
2    2  48.78125 -122.09375   526.0   
3    3  48.78125 -122.15625   403.0   
4    4  48.71875 -121.90625  1061.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:20
Minimum elevation: 302.0m
Mean elevation: 709.95m
Maximum elevation: 1201.0m
0 station: (0.0, 48.78125, -121.96875)
1 station: (1.0, 48.78125, -122.03125)
2 station: (2.0, 48.78125, -122.09375)
3 station: (3.0, 48.78125, -122.15625)
4 station: (4.0, 48.71875, -121.90625)
5 station: (5.0, 48.71875, -121.96875)
6 station: (6.0, 48.71875, -122.03125)
7 station: (7.0, 48.71875, -122.09375)
8 station: (8.0, 48.71875, -122.15625)
9 station: (9.0, 48.71875, -122.21875)
10 station: (10.0, 48.65625, -121.90625)
11 station: (11.0, 48.65625, -121.96875)
12 station: (12.0, 48.65625, -122.03125)
13 station: (13.0, 48.65625, -122.09375)
14 station: (14.0, 48.65625, -122.15625)
15 station: (15.0, 48.65625, -122.21875)
16 station: (16.0, 48.59375, -121.96875)
17 station: (17.0, 48.59375, -122.03125)
18 station: (18.0, 48.59375, -122.09375)
19 station: (19.0, 48.59375, -122.15625)
mission complete. this device will now self-destruct. just kidding.

Add the bias corrected dataset to the dataframe


In [69]:
ltm_skook = ogh.gridclim_dict(mappingfile=mappingfile,
                               metadata=meta_file,
                               dataset='dailymet_livneh2013_wrfbc',
                               file_start_date=dr1['start_date'], 
                               file_end_date=dr1['end_date'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1],
                               df_dict=ltm_skook)


   FID       LAT      LONG_    ELEV  \
0    0  48.78125 -121.96875  1029.0   
1    1  48.78125 -122.03125   740.0   
2    2  48.78125 -122.09375   526.0   
3    3  48.78125 -122.15625   403.0   
4    4  48.71875 -121.90625  1061.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                           dailymet_livneh2013_wrfbc  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:20
Minimum elevation: 302.0m
Mean elevation: 709.95m
Maximum elevation: 1201.0m
Number of data files within elevation range (302.0:1201.0): 20
PRECIP dataframe reading to start: 0:00:00.034587
PRECIP dataframe complete:0:00:00.285439
TMAX dataframe reading to start: 0:00:00.318484
TMAX dataframe complete:0:00:00.542910
TMIN dataframe reading to start: 0:00:00.576189
TMIN dataframe complete:0:00:00.812898
WINDSPD dataframe reading to start: 0:00:00.846445
WINDSPD dataframe complete:0:00:01.074645
PRECIP_dailymet_livneh2013_wrfbc calculations completed in 0:00:00.031874
TMAX_dailymet_livneh2013_wrfbc calculations completed in 0:00:00.025976
TMIN_dailymet_livneh2013_wrfbc calculations completed in 0:00:00.026208
WINDSPD_dailymet_livneh2013_wrfbc calculations completed in 0:00:00.025294

In [70]:
print(ltm_skook['month_PRECIP_dailywrf_salathe2014'][9])#high elevation
print(ltm_skook['month_PRECIP_dailywrf_salathe2014'][0])#low elevation
print(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][9])#high elevation
print(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][0])#low elevation


     48.71875
   -122.21875
1    9.662200
2    7.986071
3    7.195098
4    5.923792
5    4.099577
6    3.832153
7    1.855494
8    2.022237
9    3.390574
10   6.801036
11   9.812344
12   9.630592
     48.78125
   -121.96875
1   16.246235
2   13.491062
3   11.649133
4    8.666093
5    5.989942
6    5.477842
7    2.818112
8    2.939492
9    4.751792
10  10.144897
11  15.690995
12  16.126103
     48.71875
   -122.21875
1    9.662200
2    7.986070
3    7.195097
4    5.923794
5    4.099577
6    3.832155
7    1.855494
8    2.022238
9    3.390574
10   6.801038
11   9.812346
12   9.630593
     48.78125
   -121.96875
1   16.246234
2   13.491062
3   11.649132
4    8.666093
5    5.989942
6    5.477841
7    2.818111
8    2.939492
9    4.751793
10  10.144894
11  15.690994
12  16.126103

5. Global:

Repeat steps above for Low Elevation Climate Correction

Commercial Break - why use OGH? because calculating all these statistics does not need to be reinvented

Here is how you list all of the variables available because you used ogh.grid_clim_dict()


In [91]:
sorted(ltm_skook.keys())


Out[91]:
['PRECIP_dailymet_livneh2013',
 'PRECIP_dailymet_livneh2013_wrfbc',
 'PRECIP_dailymet_livneh2013_wrfbc_global',
 'PRECIP_dailywrf_salathe2014',
 'TMAX_dailymet_livneh2013',
 'TMAX_dailymet_livneh2013_wrfbc',
 'TMAX_dailymet_livneh2013_wrfbc_global',
 'TMAX_dailywrf_salathe2014',
 'TMIN_dailymet_livneh2013',
 'TMIN_dailymet_livneh2013_wrfbc',
 'TMIN_dailymet_livneh2013_wrfbc_global',
 'TMIN_dailywrf_salathe2014',
 'WINDSPD_dailymet_livneh2013',
 'WINDSPD_dailymet_livneh2013_wrfbc',
 'WINDSPD_dailymet_livneh2013_wrfbc_global',
 'WINDSPD_dailywrf_salathe2014',
 'anom_year_PRECIP_dailymet_livneh2013',
 'anom_year_PRECIP_dailymet_livneh2013_wrfbc',
 'anom_year_PRECIP_dailymet_livneh2013_wrfbc_global',
 'anom_year_PRECIP_dailywrf_salathe2014',
 'anom_year_TMAX_dailymet_livneh2013',
 'anom_year_TMAX_dailymet_livneh2013_wrfbc',
 'anom_year_TMAX_dailymet_livneh2013_wrfbc_global',
 'anom_year_TMAX_dailywrf_salathe2014',
 'anom_year_TMIN_dailymet_livneh2013',
 'anom_year_TMIN_dailymet_livneh2013_wrfbc',
 'anom_year_TMIN_dailymet_livneh2013_wrfbc_global',
 'anom_year_TMIN_dailywrf_salathe2014',
 'anom_year_WINDSPD_dailymet_livneh2013',
 'anom_year_WINDSPD_dailymet_livneh2013_wrfbc',
 'anom_year_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'anom_year_WINDSPD_dailywrf_salathe2014',
 'meanallyear_PRECIP_dailymet_livneh2013',
 'meanallyear_PRECIP_dailymet_livneh2013_wrfbc',
 'meanallyear_PRECIP_dailymet_livneh2013_wrfbc_global',
 'meanallyear_PRECIP_dailywrf_salathe2014',
 'meanallyear_TMAX_dailymet_livneh2013',
 'meanallyear_TMAX_dailymet_livneh2013_wrfbc',
 'meanallyear_TMAX_dailymet_livneh2013_wrfbc_global',
 'meanallyear_TMAX_dailywrf_salathe2014',
 'meanallyear_TMIN_dailymet_livneh2013',
 'meanallyear_TMIN_dailymet_livneh2013_wrfbc',
 'meanallyear_TMIN_dailymet_livneh2013_wrfbc_global',
 'meanallyear_TMIN_dailywrf_salathe2014',
 'meanallyear_WINDSPD_dailymet_livneh2013',
 'meanallyear_WINDSPD_dailymet_livneh2013_wrfbc',
 'meanallyear_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'meanallyear_WINDSPD_dailywrf_salathe2014',
 'meanmonth_PRECIP_dailymet_livneh2013',
 'meanmonth_PRECIP_dailymet_livneh2013_wrfbc',
 'meanmonth_PRECIP_dailymet_livneh2013_wrfbc_global',
 'meanmonth_PRECIP_dailywrf_salathe2014',
 'meanmonth_TMAX_dailymet_livneh2013',
 'meanmonth_TMAX_dailymet_livneh2013_wrfbc',
 'meanmonth_TMAX_dailymet_livneh2013_wrfbc_global',
 'meanmonth_TMAX_dailywrf_salathe2014',
 'meanmonth_TMIN_dailymet_livneh2013',
 'meanmonth_TMIN_dailymet_livneh2013_wrfbc',
 'meanmonth_TMIN_dailymet_livneh2013_wrfbc_global',
 'meanmonth_TMIN_dailywrf_salathe2014',
 'meanmonth_WINDSPD_dailymet_livneh2013',
 'meanmonth_WINDSPD_dailymet_livneh2013_wrfbc',
 'meanmonth_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'meanmonth_WINDSPD_dailywrf_salathe2014',
 'meanyear_PRECIP_dailymet_livneh2013',
 'meanyear_PRECIP_dailymet_livneh2013_wrfbc',
 'meanyear_PRECIP_dailymet_livneh2013_wrfbc_global',
 'meanyear_PRECIP_dailywrf_salathe2014',
 'meanyear_TMAX_dailymet_livneh2013',
 'meanyear_TMAX_dailymet_livneh2013_wrfbc',
 'meanyear_TMAX_dailymet_livneh2013_wrfbc_global',
 'meanyear_TMAX_dailywrf_salathe2014',
 'meanyear_TMIN_dailymet_livneh2013',
 'meanyear_TMIN_dailymet_livneh2013_wrfbc',
 'meanyear_TMIN_dailymet_livneh2013_wrfbc_global',
 'meanyear_TMIN_dailywrf_salathe2014',
 'meanyear_WINDSPD_dailymet_livneh2013',
 'meanyear_WINDSPD_dailymet_livneh2013_wrfbc',
 'meanyear_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'meanyear_WINDSPD_dailywrf_salathe2014',
 'month_PRECIP_dailymet_livneh2013',
 'month_PRECIP_dailymet_livneh2013_wrfbc',
 'month_PRECIP_dailymet_livneh2013_wrfbc_global',
 'month_PRECIP_dailywrf_salathe2014',
 'month_TMAX_dailymet_livneh2013',
 'month_TMAX_dailymet_livneh2013_wrfbc',
 'month_TMAX_dailymet_livneh2013_wrfbc_global',
 'month_TMAX_dailywrf_salathe2014',
 'month_TMIN_dailymet_livneh2013',
 'month_TMIN_dailymet_livneh2013_wrfbc',
 'month_TMIN_dailymet_livneh2013_wrfbc_global',
 'month_TMIN_dailywrf_salathe2014',
 'month_WINDSPD_dailymet_livneh2013',
 'month_WINDSPD_dailymet_livneh2013_wrfbc',
 'month_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'month_WINDSPD_dailywrf_salathe2014',
 'year_PRECIP_dailymet_livneh2013',
 'year_PRECIP_dailymet_livneh2013_wrfbc',
 'year_PRECIP_dailymet_livneh2013_wrfbc_global',
 'year_PRECIP_dailywrf_salathe2014',
 'year_TMAX_dailymet_livneh2013',
 'year_TMAX_dailymet_livneh2013_wrfbc',
 'year_TMAX_dailymet_livneh2013_wrfbc_global',
 'year_TMAX_dailywrf_salathe2014',
 'year_TMIN_dailymet_livneh2013',
 'year_TMIN_dailymet_livneh2013_wrfbc',
 'year_TMIN_dailymet_livneh2013_wrfbc_global',
 'year_TMIN_dailywrf_salathe2014',
 'year_WINDSPD_dailymet_livneh2013',
 'year_WINDSPD_dailymet_livneh2013_wrfbc',
 'year_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'year_WINDSPD_dailywrf_salathe2014']

End of Commerical Break

Generate low elevation global correction factors


In [72]:
global_biascorr_PRECIP=ltm_skook_low['meanmonth_PRECIP_dailymet_livneh2013']/ltm_skook_low['meanmonth_PRECIP_dailywrf_salathe2014']
#print(global_biascorr_PRECIP)

global_biascorr_TMAX=ltm_skook_low['meanmonth_TMAX_dailymet_livneh2013']-ltm_skook_low['meanmonth_TMAX_dailywrf_salathe2014']
#print(global_biascorr_TMAX)

global_biascorr_TMIN=ltm_skook_low['meanmonth_TMIN_dailymet_livneh2013']-ltm_skook_low['meanmonth_TMIN_dailywrf_salathe2014']
#print(global_biascorr_TMIN)

global_wind=[0,0,0,0,0,0,0,0,0,0,0,0]

In [73]:
#Apply the monthly low elevation correction to every grid cell uniformly
#Initialize dictionary
Global_BiasCorr_wrfbc_skook=copy.deepcopy(BiasCorr_wrfbc_skook)

In [74]:
print(global_biascorr_PRECIP)
print(Global_BiasCorr_wrfbc_skook['PRECIP_skookum'][9])


1     0.676824
2     0.653304
3     0.620239
4     0.590418
5     0.623284
6     0.602805
7     0.777815
8     0.825558
9     0.824951
10    0.779727
11    0.713355
12    0.718987
dtype: float64
     48.71875
   -122.21875
1    1.422228
2    1.485071
3    1.566470
4    1.641250
5    1.555437
6    1.583767
7    1.232629
8    1.165087
9    1.157138
10   1.230174
11   1.353011
12   1.338354

In [75]:
for column in Global_BiasCorr_wrfbc_skook['PRECIP_skookum']:
   
    Global_BiasCorr_wrfbc_skook['PRECIP_skookum'].ix[1:12,column]=global_biascorr_PRECIP
    Global_BiasCorr_wrfbc_skook['TMAX_skookum'].ix[1:12,column]=global_biascorr_TMAX
    Global_BiasCorr_wrfbc_skook['TMIN_skookum'].ix[1:12,column]=global_biascorr_TMIN
    Global_BiasCorr_wrfbc_skook['WINDSPD_skookum'].ix[1:12,column]=global_wind
    
ogh.saveDictOfDf('Global_BiasCorr_wrfbc_skookum.json', dictionaryObject=Global_BiasCorr_wrfbc_skook)

In [26]:
#Global_BiasCorr_wrfbc_skook['PRECIP_skookum'][0]

Bias correct LivnehWRFbc to low elevation bias correction

Input: Correction array of 12 values, one per month for low elevation WRF bias, Livneh Time Series corrected to WRF

Output: Corrected Livneh data (livneh2013_wrfbc_global)


In [76]:
Global_BiasCorr_wrfbc_skook


Out[76]:
{'PRECIP_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    0.676824   0.676824   0.676824   0.676824   0.676824   0.676824   
 2    0.653304   0.653304   0.653304   0.653304   0.653304   0.653304   
 3    0.620239   0.620239   0.620239   0.620239   0.620239   0.620239   
 4    0.590418   0.590418   0.590418   0.590418   0.590418   0.590418   
 5    0.623284   0.623284   0.623284   0.623284   0.623284   0.623284   
 6    0.602805   0.602805   0.602805   0.602805   0.602805   0.602805   
 7    0.777815   0.777815   0.777815   0.777815   0.777815   0.777815   
 8    0.825558   0.825558   0.825558   0.825558   0.825558   0.825558   
 9    0.824951   0.824951   0.824951   0.824951   0.824951   0.824951   
 10   0.779727   0.779727   0.779727   0.779727   0.779727   0.779727   
 11   0.713355   0.713355   0.713355   0.713355   0.713355   0.713355   
 12   0.718987   0.718987   0.718987   0.718987   0.718987   0.718987   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    0.676824   0.676824   0.676824   0.676824   0.676824   0.676824   
 2    0.653304   0.653304   0.653304   0.653304   0.653304   0.653304   
 3    0.620239   0.620239   0.620239   0.620239   0.620239   0.620239   
 4    0.590418   0.590418   0.590418   0.590418   0.590418   0.590418   
 5    0.623284   0.623284   0.623284   0.623284   0.623284   0.623284   
 6    0.602805   0.602805   0.602805   0.602805   0.602805   0.602805   
 7    0.777815   0.777815   0.777815   0.777815   0.777815   0.777815   
 8    0.825558   0.825558   0.825558   0.825558   0.825558   0.825558   
 9    0.824951   0.824951   0.824951   0.824951   0.824951   0.824951   
 10   0.779727   0.779727   0.779727   0.779727   0.779727   0.779727   
 11   0.713355   0.713355   0.713355   0.713355   0.713355   0.713355   
 12   0.718987   0.718987   0.718987   0.718987   0.718987   0.718987   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    0.676824   0.676824   0.676824   0.676824   0.676824   0.676824   
 2    0.653304   0.653304   0.653304   0.653304   0.653304   0.653304   
 3    0.620239   0.620239   0.620239   0.620239   0.620239   0.620239   
 4    0.590418   0.590418   0.590418   0.590418   0.590418   0.590418   
 5    0.623284   0.623284   0.623284   0.623284   0.623284   0.623284   
 6    0.602805   0.602805   0.602805   0.602805   0.602805   0.602805   
 7    0.777815   0.777815   0.777815   0.777815   0.777815   0.777815   
 8    0.825558   0.825558   0.825558   0.825558   0.825558   0.825558   
 9    0.824951   0.824951   0.824951   0.824951   0.824951   0.824951   
 10   0.779727   0.779727   0.779727   0.779727   0.779727   0.779727   
 11   0.713355   0.713355   0.713355   0.713355   0.713355   0.713355   
 12   0.718987   0.718987   0.718987   0.718987   0.718987   0.718987   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    0.676824   0.676824  
 2    0.653304   0.653304  
 3    0.620239   0.620239  
 4    0.590418   0.590418  
 5    0.623284   0.623284  
 6    0.602805   0.602805  
 7    0.777815   0.777815  
 8    0.825558   0.825558  
 9    0.824951   0.824951  
 10   0.779727   0.779727  
 11   0.713355   0.713355  
 12   0.718987   0.718987  ,
 'TMAX_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    1.356191   1.356191   1.356191   1.356191   1.356191   1.356191   
 2    2.278853   2.278853   2.278853   2.278853   2.278853   2.278853   
 3    3.037828   3.037828   3.037828   3.037828   3.037828   3.037828   
 4    2.995237   2.995237   2.995237   2.995237   2.995237   2.995237   
 5    2.814513   2.814513   2.814513   2.814513   2.814513   2.814513   
 6    2.924792   2.924792   2.924792   2.924792   2.924792   2.924792   
 7    3.202188   3.202188   3.202188   3.202188   3.202188   3.202188   
 8    3.102685   3.102685   3.102685   3.102685   3.102685   3.102685   
 9    1.751763   1.751763   1.751763   1.751763   1.751763   1.751763   
 10   1.147943   1.147943   1.147943   1.147943   1.147943   1.147943   
 11   1.131971   1.131971   1.131971   1.131971   1.131971   1.131971   
 12   0.958459   0.958459   0.958459   0.958459   0.958459   0.958459   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    1.356191   1.356191   1.356191   1.356191   1.356191   1.356191   
 2    2.278853   2.278853   2.278853   2.278853   2.278853   2.278853   
 3    3.037828   3.037828   3.037828   3.037828   3.037828   3.037828   
 4    2.995237   2.995237   2.995237   2.995237   2.995237   2.995237   
 5    2.814513   2.814513   2.814513   2.814513   2.814513   2.814513   
 6    2.924792   2.924792   2.924792   2.924792   2.924792   2.924792   
 7    3.202188   3.202188   3.202188   3.202188   3.202188   3.202188   
 8    3.102685   3.102685   3.102685   3.102685   3.102685   3.102685   
 9    1.751763   1.751763   1.751763   1.751763   1.751763   1.751763   
 10   1.147943   1.147943   1.147943   1.147943   1.147943   1.147943   
 11   1.131971   1.131971   1.131971   1.131971   1.131971   1.131971   
 12   0.958459   0.958459   0.958459   0.958459   0.958459   0.958459   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    1.356191   1.356191   1.356191   1.356191   1.356191   1.356191   
 2    2.278853   2.278853   2.278853   2.278853   2.278853   2.278853   
 3    3.037828   3.037828   3.037828   3.037828   3.037828   3.037828   
 4    2.995237   2.995237   2.995237   2.995237   2.995237   2.995237   
 5    2.814513   2.814513   2.814513   2.814513   2.814513   2.814513   
 6    2.924792   2.924792   2.924792   2.924792   2.924792   2.924792   
 7    3.202188   3.202188   3.202188   3.202188   3.202188   3.202188   
 8    3.102685   3.102685   3.102685   3.102685   3.102685   3.102685   
 9    1.751763   1.751763   1.751763   1.751763   1.751763   1.751763   
 10   1.147943   1.147943   1.147943   1.147943   1.147943   1.147943   
 11   1.131971   1.131971   1.131971   1.131971   1.131971   1.131971   
 12   0.958459   0.958459   0.958459   0.958459   0.958459   0.958459   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    1.356191   1.356191  
 2    2.278853   2.278853  
 3    3.037828   3.037828  
 4    2.995237   2.995237  
 5    2.814513   2.814513  
 6    2.924792   2.924792  
 7    3.202188   3.202188  
 8    3.102685   3.102685  
 9    1.751763   1.751763  
 10   1.147943   1.147943  
 11   1.131971   1.131971  
 12   0.958459   0.958459  ,
 'TMIN_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1   -2.126564  -2.126564  -2.126564  -2.126564  -2.126564  -2.126564   
 2   -1.838033  -1.838033  -1.838033  -1.838033  -1.838033  -1.838033   
 3   -0.893518  -0.893518  -0.893518  -0.893518  -0.893518  -0.893518   
 4   -0.917639  -0.917639  -0.917639  -0.917639  -0.917639  -0.917639   
 5   -0.369076  -0.369076  -0.369076  -0.369076  -0.369076  -0.369076   
 6    0.211313   0.211313   0.211313   0.211313   0.211313   0.211313   
 7   -0.419721  -0.419721  -0.419721  -0.419721  -0.419721  -0.419721   
 8   -0.878729  -0.878729  -0.878729  -0.878729  -0.878729  -0.878729   
 9   -2.338137  -2.338137  -2.338137  -2.338137  -2.338137  -2.338137   
 10  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678   
 11  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166   
 12  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1   -2.126564  -2.126564  -2.126564  -2.126564  -2.126564  -2.126564   
 2   -1.838033  -1.838033  -1.838033  -1.838033  -1.838033  -1.838033   
 3   -0.893518  -0.893518  -0.893518  -0.893518  -0.893518  -0.893518   
 4   -0.917639  -0.917639  -0.917639  -0.917639  -0.917639  -0.917639   
 5   -0.369076  -0.369076  -0.369076  -0.369076  -0.369076  -0.369076   
 6    0.211313   0.211313   0.211313   0.211313   0.211313   0.211313   
 7   -0.419721  -0.419721  -0.419721  -0.419721  -0.419721  -0.419721   
 8   -0.878729  -0.878729  -0.878729  -0.878729  -0.878729  -0.878729   
 9   -2.338137  -2.338137  -2.338137  -2.338137  -2.338137  -2.338137   
 10  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678   
 11  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166   
 12  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1   -2.126564  -2.126564  -2.126564  -2.126564  -2.126564  -2.126564   
 2   -1.838033  -1.838033  -1.838033  -1.838033  -1.838033  -1.838033   
 3   -0.893518  -0.893518  -0.893518  -0.893518  -0.893518  -0.893518   
 4   -0.917639  -0.917639  -0.917639  -0.917639  -0.917639  -0.917639   
 5   -0.369076  -0.369076  -0.369076  -0.369076  -0.369076  -0.369076   
 6    0.211313   0.211313   0.211313   0.211313   0.211313   0.211313   
 7   -0.419721  -0.419721  -0.419721  -0.419721  -0.419721  -0.419721   
 8   -0.878729  -0.878729  -0.878729  -0.878729  -0.878729  -0.878729   
 9   -2.338137  -2.338137  -2.338137  -2.338137  -2.338137  -2.338137   
 10  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678   
 11  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166   
 12  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1   -2.126564  -2.126564  
 2   -1.838033  -1.838033  
 3   -0.893518  -0.893518  
 4   -0.917639  -0.917639  
 5   -0.369076  -0.369076  
 6    0.211313   0.211313  
 7   -0.419721  -0.419721  
 8   -0.878729  -0.878729  
 9   -2.338137  -2.338137  
 10  -3.072678  -3.072678  
 11  -2.785166  -2.785166  
 12  -2.432165  -2.432165  ,
 'WINDSPD_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1         0.0        0.0        0.0        0.0        0.0        0.0   
 2         0.0        0.0        0.0        0.0        0.0        0.0   
 3         0.0        0.0        0.0        0.0        0.0        0.0   
 4         0.0        0.0        0.0        0.0        0.0        0.0   
 5         0.0        0.0        0.0        0.0        0.0        0.0   
 6         0.0        0.0        0.0        0.0        0.0        0.0   
 7         0.0        0.0        0.0        0.0        0.0        0.0   
 8         0.0        0.0        0.0        0.0        0.0        0.0   
 9         0.0        0.0        0.0        0.0        0.0        0.0   
 10        0.0        0.0        0.0        0.0        0.0        0.0   
 11        0.0        0.0        0.0        0.0        0.0        0.0   
 12        0.0        0.0        0.0        0.0        0.0        0.0   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1         0.0        0.0        0.0        0.0        0.0        0.0   
 2         0.0        0.0        0.0        0.0        0.0        0.0   
 3         0.0        0.0        0.0        0.0        0.0        0.0   
 4         0.0        0.0        0.0        0.0        0.0        0.0   
 5         0.0        0.0        0.0        0.0        0.0        0.0   
 6         0.0        0.0        0.0        0.0        0.0        0.0   
 7         0.0        0.0        0.0        0.0        0.0        0.0   
 8         0.0        0.0        0.0        0.0        0.0        0.0   
 9         0.0        0.0        0.0        0.0        0.0        0.0   
 10        0.0        0.0        0.0        0.0        0.0        0.0   
 11        0.0        0.0        0.0        0.0        0.0        0.0   
 12        0.0        0.0        0.0        0.0        0.0        0.0   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1         0.0        0.0        0.0        0.0        0.0        0.0   
 2         0.0        0.0        0.0        0.0        0.0        0.0   
 3         0.0        0.0        0.0        0.0        0.0        0.0   
 4         0.0        0.0        0.0        0.0        0.0        0.0   
 5         0.0        0.0        0.0        0.0        0.0        0.0   
 6         0.0        0.0        0.0        0.0        0.0        0.0   
 7         0.0        0.0        0.0        0.0        0.0        0.0   
 8         0.0        0.0        0.0        0.0        0.0        0.0   
 9         0.0        0.0        0.0        0.0        0.0        0.0   
 10        0.0        0.0        0.0        0.0        0.0        0.0   
 11        0.0        0.0        0.0        0.0        0.0        0.0   
 12        0.0        0.0        0.0        0.0        0.0        0.0   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1         0.0        0.0  
 2         0.0        0.0  
 3         0.0        0.0  
 4         0.0        0.0  
 5         0.0        0.0  
 6         0.0        0.0  
 7         0.0        0.0  
 8         0.0        0.0  
 9         0.0        0.0  
 10        0.0        0.0  
 11        0.0        0.0  
 12        0.0        0.0  }

In [77]:
Daily_MET_1915_2011_WRFbc_global, meta_file = ogh.makebelieve(homedir=homedir,
                                                           mappingfile=mappingfile1,
                                                           BiasCorr=Global_BiasCorr_wrfbc_skook,
                                                           metadata=meta_file,
                                                           start_catalog_label='dailymet_livneh2013_wrfbc',
                                                           end_catalog_label='dailymet_livneh2013_wrfbc_global', 
                                                           file_start_date=None,
                                                           file_end_date=None,
                                                           data_dir=None,
                                                           dest_dir_suffix='biascorr_WRF_liv_global')


   FID       LAT      LONG_    ELEV  \
0    0  48.78125 -121.96875  1029.0   
1    1  48.78125 -122.03125   740.0   
2    2  48.78125 -122.09375   526.0   
3    3  48.78125 -122.15625   403.0   
4    4  48.71875 -121.90625  1061.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                           dailymet_livneh2013_wrfbc  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:20
Minimum elevation: 302.0m
Mean elevation: 709.95m
Maximum elevation: 1201.0m
0 station: (0.0, 48.78125, -121.96875)
1 station: (1.0, 48.78125, -122.03125)
2 station: (2.0, 48.78125, -122.09375)
3 station: (3.0, 48.78125, -122.15625)
4 station: (4.0, 48.71875, -121.90625)
5 station: (5.0, 48.71875, -121.96875)
6 station: (6.0, 48.71875, -122.03125)
7 station: (7.0, 48.71875, -122.09375)
8 station: (8.0, 48.71875, -122.15625)
9 station: (9.0, 48.71875, -122.21875)
10 station: (10.0, 48.65625, -121.90625)
11 station: (11.0, 48.65625, -121.96875)
12 station: (12.0, 48.65625, -122.03125)
13 station: (13.0, 48.65625, -122.09375)
14 station: (14.0, 48.65625, -122.15625)
15 station: (15.0, 48.65625, -122.21875)
16 station: (16.0, 48.59375, -121.96875)
17 station: (17.0, 48.59375, -122.03125)
18 station: (18.0, 48.59375, -122.09375)
19 station: (19.0, 48.59375, -122.15625)
mission complete. this device will now self-destruct. just kidding.

In [29]:
Daily_MET_1915_2011_WRFbc_global


Out[29]:
'/home/jovyan/work/notebooks/data/e47aabb406bc45a28f34b97a832daa08/e47aabb406bc45a28f34b97a832daa08/data/contents/biascorr_WRF_liv_global'

Add global corrected results to dictionary


In [78]:
ltm_skook = ogh.gridclim_dict(mappingfile=mappingfile1,
                               metadata=meta_file,
                               dataset='dailymet_livneh2013_wrfbc_global',
                               file_start_date=dr1['start_date'], 
                               file_end_date=dr1['end_date'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1],
                               df_dict=ltm_skook)


   FID       LAT      LONG_    ELEV  \
0    0  48.78125 -121.96875  1029.0   
1    1  48.78125 -122.03125   740.0   
2    2  48.78125 -122.09375   526.0   
3    3  48.78125 -122.15625   403.0   
4    4  48.71875 -121.90625  1061.0   

                                 dailymet_livneh2013  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                                dailywrf_salathe2014  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                           dailymet_livneh2013_wrfbc  \
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...   
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...   

                    dailymet_livneh2013_wrfbc_global  
0  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
1  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
2  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
3  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
4  /home/jovyan/work/notebooks/data/e47aabb406bc4...  
Number of gridded data files:20
Minimum elevation: 302.0m
Mean elevation: 709.95m
Maximum elevation: 1201.0m
Number of data files within elevation range (302.0:1201.0): 20
PRECIP dataframe reading to start: 0:00:00.035030
PRECIP dataframe complete:0:00:00.269603
TMAX dataframe reading to start: 0:00:00.302808
TMAX dataframe complete:0:00:00.528778
TMIN dataframe reading to start: 0:00:00.561497
TMIN dataframe complete:0:00:00.789364
WINDSPD dataframe reading to start: 0:00:00.823294
WINDSPD dataframe complete:0:00:01.079520
PRECIP_dailymet_livneh2013_wrfbc_global calculations completed in 0:00:00.031951
TMAX_dailymet_livneh2013_wrfbc_global calculations completed in 0:00:00.025989
TMIN_dailymet_livneh2013_wrfbc_global calculations completed in 0:00:00.026072
WINDSPD_dailymet_livneh2013_wrfbc_global calculations completed in 0:00:00.025581

Check bias correction results


In [79]:
print(ltm_skook['month_PRECIP_dailywrf_salathe2014'][9])#high elevation
print(ltm_skook['month_PRECIP_dailywrf_salathe2014'][0])#low elevation
print(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][9])#high elevation
print(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][0])#low elevation
print(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc_global'][9])#high elevation
print(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc_global'][0])#low elevation


     48.71875
   -122.21875
1    9.662200
2    7.986071
3    7.195098
4    5.923792
5    4.099577
6    3.832153
7    1.855494
8    2.022237
9    3.390574
10   6.801036
11   9.812344
12   9.630592
     48.78125
   -121.96875
1   16.246235
2   13.491062
3   11.649133
4    8.666093
5    5.989942
6    5.477842
7    2.818112
8    2.939492
9    4.751792
10  10.144897
11  15.690995
12  16.126103
     48.71875
   -122.21875
1    9.662200
2    7.986070
3    7.195097
4    5.923794
5    4.099577
6    3.832155
7    1.855494
8    2.022238
9    3.390574
10   6.801038
11   9.812346
12   9.630593
     48.78125
   -121.96875
1   16.246234
2   13.491062
3   11.649132
4    8.666093
5    5.989942
6    5.477841
7    2.818111
8    2.939492
9    4.751793
10  10.144894
11  15.690994
12  16.126103
     48.71875
   -122.21875
1    6.539611
2    5.217334
3    4.462681
4    3.497517
5    2.555198
6    2.310042
7    1.443232
8    1.669473
9    2.797058
10   5.302952
11   6.999690
12   6.924275
     48.78125
   -121.96875
1   10.995844
2    8.813769
3    7.225246
4    5.116619
5    3.733434
6    3.302063
7    2.191969
8    2.426722
9    3.919996
10   7.910244
11  11.193255
12  11.594466

6. Compare Corrected Historic Hydrometeorology

This section performs computations and generates plots of the Livneh 2013, Livneh 2016, and WRF 2014 temperature and precipitation data in order to compare them with each other and observations. The generated plots are automatically downloaded and saved as .png files in the "plots" folder of the user's home directory and inline in the notebook.


In [80]:
Global_BiasCorr_wrfbc_skook


Out[80]:
{'PRECIP_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    0.676824   0.676824   0.676824   0.676824   0.676824   0.676824   
 2    0.653304   0.653304   0.653304   0.653304   0.653304   0.653304   
 3    0.620239   0.620239   0.620239   0.620239   0.620239   0.620239   
 4    0.590418   0.590418   0.590418   0.590418   0.590418   0.590418   
 5    0.623284   0.623284   0.623284   0.623284   0.623284   0.623284   
 6    0.602805   0.602805   0.602805   0.602805   0.602805   0.602805   
 7    0.777815   0.777815   0.777815   0.777815   0.777815   0.777815   
 8    0.825558   0.825558   0.825558   0.825558   0.825558   0.825558   
 9    0.824951   0.824951   0.824951   0.824951   0.824951   0.824951   
 10   0.779727   0.779727   0.779727   0.779727   0.779727   0.779727   
 11   0.713355   0.713355   0.713355   0.713355   0.713355   0.713355   
 12   0.718987   0.718987   0.718987   0.718987   0.718987   0.718987   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    0.676824   0.676824   0.676824   0.676824   0.676824   0.676824   
 2    0.653304   0.653304   0.653304   0.653304   0.653304   0.653304   
 3    0.620239   0.620239   0.620239   0.620239   0.620239   0.620239   
 4    0.590418   0.590418   0.590418   0.590418   0.590418   0.590418   
 5    0.623284   0.623284   0.623284   0.623284   0.623284   0.623284   
 6    0.602805   0.602805   0.602805   0.602805   0.602805   0.602805   
 7    0.777815   0.777815   0.777815   0.777815   0.777815   0.777815   
 8    0.825558   0.825558   0.825558   0.825558   0.825558   0.825558   
 9    0.824951   0.824951   0.824951   0.824951   0.824951   0.824951   
 10   0.779727   0.779727   0.779727   0.779727   0.779727   0.779727   
 11   0.713355   0.713355   0.713355   0.713355   0.713355   0.713355   
 12   0.718987   0.718987   0.718987   0.718987   0.718987   0.718987   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    0.676824   0.676824   0.676824   0.676824   0.676824   0.676824   
 2    0.653304   0.653304   0.653304   0.653304   0.653304   0.653304   
 3    0.620239   0.620239   0.620239   0.620239   0.620239   0.620239   
 4    0.590418   0.590418   0.590418   0.590418   0.590418   0.590418   
 5    0.623284   0.623284   0.623284   0.623284   0.623284   0.623284   
 6    0.602805   0.602805   0.602805   0.602805   0.602805   0.602805   
 7    0.777815   0.777815   0.777815   0.777815   0.777815   0.777815   
 8    0.825558   0.825558   0.825558   0.825558   0.825558   0.825558   
 9    0.824951   0.824951   0.824951   0.824951   0.824951   0.824951   
 10   0.779727   0.779727   0.779727   0.779727   0.779727   0.779727   
 11   0.713355   0.713355   0.713355   0.713355   0.713355   0.713355   
 12   0.718987   0.718987   0.718987   0.718987   0.718987   0.718987   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    0.676824   0.676824  
 2    0.653304   0.653304  
 3    0.620239   0.620239  
 4    0.590418   0.590418  
 5    0.623284   0.623284  
 6    0.602805   0.602805  
 7    0.777815   0.777815  
 8    0.825558   0.825558  
 9    0.824951   0.824951  
 10   0.779727   0.779727  
 11   0.713355   0.713355  
 12   0.718987   0.718987  ,
 'TMAX_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    1.356191   1.356191   1.356191   1.356191   1.356191   1.356191   
 2    2.278853   2.278853   2.278853   2.278853   2.278853   2.278853   
 3    3.037828   3.037828   3.037828   3.037828   3.037828   3.037828   
 4    2.995237   2.995237   2.995237   2.995237   2.995237   2.995237   
 5    2.814513   2.814513   2.814513   2.814513   2.814513   2.814513   
 6    2.924792   2.924792   2.924792   2.924792   2.924792   2.924792   
 7    3.202188   3.202188   3.202188   3.202188   3.202188   3.202188   
 8    3.102685   3.102685   3.102685   3.102685   3.102685   3.102685   
 9    1.751763   1.751763   1.751763   1.751763   1.751763   1.751763   
 10   1.147943   1.147943   1.147943   1.147943   1.147943   1.147943   
 11   1.131971   1.131971   1.131971   1.131971   1.131971   1.131971   
 12   0.958459   0.958459   0.958459   0.958459   0.958459   0.958459   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    1.356191   1.356191   1.356191   1.356191   1.356191   1.356191   
 2    2.278853   2.278853   2.278853   2.278853   2.278853   2.278853   
 3    3.037828   3.037828   3.037828   3.037828   3.037828   3.037828   
 4    2.995237   2.995237   2.995237   2.995237   2.995237   2.995237   
 5    2.814513   2.814513   2.814513   2.814513   2.814513   2.814513   
 6    2.924792   2.924792   2.924792   2.924792   2.924792   2.924792   
 7    3.202188   3.202188   3.202188   3.202188   3.202188   3.202188   
 8    3.102685   3.102685   3.102685   3.102685   3.102685   3.102685   
 9    1.751763   1.751763   1.751763   1.751763   1.751763   1.751763   
 10   1.147943   1.147943   1.147943   1.147943   1.147943   1.147943   
 11   1.131971   1.131971   1.131971   1.131971   1.131971   1.131971   
 12   0.958459   0.958459   0.958459   0.958459   0.958459   0.958459   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    1.356191   1.356191   1.356191   1.356191   1.356191   1.356191   
 2    2.278853   2.278853   2.278853   2.278853   2.278853   2.278853   
 3    3.037828   3.037828   3.037828   3.037828   3.037828   3.037828   
 4    2.995237   2.995237   2.995237   2.995237   2.995237   2.995237   
 5    2.814513   2.814513   2.814513   2.814513   2.814513   2.814513   
 6    2.924792   2.924792   2.924792   2.924792   2.924792   2.924792   
 7    3.202188   3.202188   3.202188   3.202188   3.202188   3.202188   
 8    3.102685   3.102685   3.102685   3.102685   3.102685   3.102685   
 9    1.751763   1.751763   1.751763   1.751763   1.751763   1.751763   
 10   1.147943   1.147943   1.147943   1.147943   1.147943   1.147943   
 11   1.131971   1.131971   1.131971   1.131971   1.131971   1.131971   
 12   0.958459   0.958459   0.958459   0.958459   0.958459   0.958459   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    1.356191   1.356191  
 2    2.278853   2.278853  
 3    3.037828   3.037828  
 4    2.995237   2.995237  
 5    2.814513   2.814513  
 6    2.924792   2.924792  
 7    3.202188   3.202188  
 8    3.102685   3.102685  
 9    1.751763   1.751763  
 10   1.147943   1.147943  
 11   1.131971   1.131971  
 12   0.958459   0.958459  ,
 'TMIN_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1   -2.126564  -2.126564  -2.126564  -2.126564  -2.126564  -2.126564   
 2   -1.838033  -1.838033  -1.838033  -1.838033  -1.838033  -1.838033   
 3   -0.893518  -0.893518  -0.893518  -0.893518  -0.893518  -0.893518   
 4   -0.917639  -0.917639  -0.917639  -0.917639  -0.917639  -0.917639   
 5   -0.369076  -0.369076  -0.369076  -0.369076  -0.369076  -0.369076   
 6    0.211313   0.211313   0.211313   0.211313   0.211313   0.211313   
 7   -0.419721  -0.419721  -0.419721  -0.419721  -0.419721  -0.419721   
 8   -0.878729  -0.878729  -0.878729  -0.878729  -0.878729  -0.878729   
 9   -2.338137  -2.338137  -2.338137  -2.338137  -2.338137  -2.338137   
 10  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678   
 11  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166   
 12  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1   -2.126564  -2.126564  -2.126564  -2.126564  -2.126564  -2.126564   
 2   -1.838033  -1.838033  -1.838033  -1.838033  -1.838033  -1.838033   
 3   -0.893518  -0.893518  -0.893518  -0.893518  -0.893518  -0.893518   
 4   -0.917639  -0.917639  -0.917639  -0.917639  -0.917639  -0.917639   
 5   -0.369076  -0.369076  -0.369076  -0.369076  -0.369076  -0.369076   
 6    0.211313   0.211313   0.211313   0.211313   0.211313   0.211313   
 7   -0.419721  -0.419721  -0.419721  -0.419721  -0.419721  -0.419721   
 8   -0.878729  -0.878729  -0.878729  -0.878729  -0.878729  -0.878729   
 9   -2.338137  -2.338137  -2.338137  -2.338137  -2.338137  -2.338137   
 10  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678   
 11  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166   
 12  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1   -2.126564  -2.126564  -2.126564  -2.126564  -2.126564  -2.126564   
 2   -1.838033  -1.838033  -1.838033  -1.838033  -1.838033  -1.838033   
 3   -0.893518  -0.893518  -0.893518  -0.893518  -0.893518  -0.893518   
 4   -0.917639  -0.917639  -0.917639  -0.917639  -0.917639  -0.917639   
 5   -0.369076  -0.369076  -0.369076  -0.369076  -0.369076  -0.369076   
 6    0.211313   0.211313   0.211313   0.211313   0.211313   0.211313   
 7   -0.419721  -0.419721  -0.419721  -0.419721  -0.419721  -0.419721   
 8   -0.878729  -0.878729  -0.878729  -0.878729  -0.878729  -0.878729   
 9   -2.338137  -2.338137  -2.338137  -2.338137  -2.338137  -2.338137   
 10  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678  -3.072678   
 11  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166  -2.785166   
 12  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165  -2.432165   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1   -2.126564  -2.126564  
 2   -1.838033  -1.838033  
 3   -0.893518  -0.893518  
 4   -0.917639  -0.917639  
 5   -0.369076  -0.369076  
 6    0.211313   0.211313  
 7   -0.419721  -0.419721  
 8   -0.878729  -0.878729  
 9   -2.338137  -2.338137  
 10  -3.072678  -3.072678  
 11  -2.785166  -2.785166  
 12  -2.432165  -2.432165  ,
 'WINDSPD_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1         0.0        0.0        0.0        0.0        0.0        0.0   
 2         0.0        0.0        0.0        0.0        0.0        0.0   
 3         0.0        0.0        0.0        0.0        0.0        0.0   
 4         0.0        0.0        0.0        0.0        0.0        0.0   
 5         0.0        0.0        0.0        0.0        0.0        0.0   
 6         0.0        0.0        0.0        0.0        0.0        0.0   
 7         0.0        0.0        0.0        0.0        0.0        0.0   
 8         0.0        0.0        0.0        0.0        0.0        0.0   
 9         0.0        0.0        0.0        0.0        0.0        0.0   
 10        0.0        0.0        0.0        0.0        0.0        0.0   
 11        0.0        0.0        0.0        0.0        0.0        0.0   
 12        0.0        0.0        0.0        0.0        0.0        0.0   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1         0.0        0.0        0.0        0.0        0.0        0.0   
 2         0.0        0.0        0.0        0.0        0.0        0.0   
 3         0.0        0.0        0.0        0.0        0.0        0.0   
 4         0.0        0.0        0.0        0.0        0.0        0.0   
 5         0.0        0.0        0.0        0.0        0.0        0.0   
 6         0.0        0.0        0.0        0.0        0.0        0.0   
 7         0.0        0.0        0.0        0.0        0.0        0.0   
 8         0.0        0.0        0.0        0.0        0.0        0.0   
 9         0.0        0.0        0.0        0.0        0.0        0.0   
 10        0.0        0.0        0.0        0.0        0.0        0.0   
 11        0.0        0.0        0.0        0.0        0.0        0.0   
 12        0.0        0.0        0.0        0.0        0.0        0.0   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1         0.0        0.0        0.0        0.0        0.0        0.0   
 2         0.0        0.0        0.0        0.0        0.0        0.0   
 3         0.0        0.0        0.0        0.0        0.0        0.0   
 4         0.0        0.0        0.0        0.0        0.0        0.0   
 5         0.0        0.0        0.0        0.0        0.0        0.0   
 6         0.0        0.0        0.0        0.0        0.0        0.0   
 7         0.0        0.0        0.0        0.0        0.0        0.0   
 8         0.0        0.0        0.0        0.0        0.0        0.0   
 9         0.0        0.0        0.0        0.0        0.0        0.0   
 10        0.0        0.0        0.0        0.0        0.0        0.0   
 11        0.0        0.0        0.0        0.0        0.0        0.0   
 12        0.0        0.0        0.0        0.0        0.0        0.0   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1         0.0        0.0  
 2         0.0        0.0  
 3         0.0        0.0  
 4         0.0        0.0  
 5         0.0        0.0  
 6         0.0        0.0  
 7         0.0        0.0  
 8         0.0        0.0  
 9         0.0        0.0  
 10        0.0        0.0  
 11        0.0        0.0  
 12        0.0        0.0  }

In [81]:
BiasCorr_wrfbc_skook


Out[81]:
{'PRECIP_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    1.555205   1.312502   1.135985   1.202662   1.343859   1.170480   
 2    1.672712   1.423598   1.271726   1.304109   1.525992   1.263092   
 3    1.884841   1.609824   1.370005   1.380164   1.664649   1.469164   
 4    2.077512   1.857882   1.652831   1.550220   2.055656   1.867245   
 5    1.629646   1.964637   1.943215   1.688000   1.324599   1.452084   
 6    1.906496   1.786993   1.638473   1.561718   1.774762   1.629132   
 7    1.994424   1.687336   1.541184   1.323346   1.304764   1.445946   
 8    1.337161   1.229111   1.165070   1.122198   1.321313   1.279604   
 9    1.239952   1.109319   1.014277   1.027453   1.256846   1.081451   
 10   1.248857   1.072364   0.962403   1.047684   1.189831   0.974402   
 11   1.809441   1.514989   1.279813   1.234669   1.454073   1.375575   
 12   1.450829   1.224130   1.074244   1.138759   1.282512   1.086233   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    1.188901   1.200626   1.600851   1.422228   0.941618   1.117805   
 2    1.279077   1.303622   1.694968   1.485071   1.057814   1.249854   
 3    1.468565   1.465887   1.744666   1.566470   1.123112   1.262468   
 4    1.807233   1.727046   1.860717   1.641250   1.453746   1.624277   
 5    1.905986   1.517861   1.779904   1.555437   1.809022   1.898645   
 6    1.675087   1.639105   1.853952   1.583767   2.072408   2.115181   
 7    1.615403   1.495087   1.460411   1.232629   1.842132   2.037223   
 8    1.207417   1.172222   1.346890   1.165087   1.744984   1.775776   
 9    1.085541   1.086504   1.308778   1.157138   1.153629   1.271886   
 10   0.984740   1.019265   1.362259   1.230174   0.978926   1.102315   
 11   1.402176   1.344189   1.527965   1.353011   0.989225   1.072144   
 12   1.090157   1.125076   1.515188   1.338354   0.910455   1.042653   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    0.958953   1.535966   0.874698   1.410050   0.844208   1.305639   
 2    1.054606   1.655649   0.869171   1.420254   0.930420   1.320195   
 3    1.144519   1.721262   0.976645   1.529000   0.951363   1.450818   
 4    1.528463   1.952782   1.045321   1.588284   1.274216   1.650346   
 5    2.027227   2.092300   1.487154   1.487306   1.464946   1.814150   
 6    1.868731   1.865467   1.250501   1.548787   1.746103   1.860709   
 7    1.869988   1.669291   0.993630   1.175459   1.813993   1.712203   
 8    1.596785   1.404037   0.920854   1.129572   1.573326   1.509606   
 9    1.112101   1.371355   0.770588   1.172951   1.028854   1.247422   
 10   0.922685   1.380901   0.779578   1.254788   0.837825   1.188735   
 11   1.022268   1.542284   0.886308   1.329186   0.795532   1.301082   
 12   0.904367   1.477229   0.830733   1.321481   0.777068   1.223278   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    1.323640   0.858044  
 2    1.340597   0.827516  
 3    1.479106   0.957319  
 4    1.694715   1.050273  
 5    1.840806   1.470680  
 6    1.815096   1.205307  
 7    1.510260   1.003388  
 8    1.319289   0.887672  
 9    1.304857   0.799014  
 10   1.221931   0.764721  
 11   1.327860   0.879219  
 12   1.248549   0.828064  ,
 'TMAX_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    0.390201  -0.512126  -0.971185  -0.687356  -0.042665   1.486356   
 2   -1.847893  -2.633587  -2.677754  -2.016529  -2.088114  -0.513819   
 3   -3.989439  -4.597234  -4.171354  -3.128964  -4.071708  -2.447049   
 4   -5.540628  -5.791579  -4.819481  -3.294579  -5.547175  -3.665038   
 5   -5.358033  -5.222152  -4.373570  -3.079910  -5.785500  -3.290116   
 6   -4.292060  -4.250273  -3.929005  -3.110104  -5.146301  -2.611005   
 7   -3.965674  -4.542295  -4.249233  -3.452068  -3.872015  -2.092951   
 8   -3.490487  -4.414627  -4.038059  -3.276319  -2.891237  -1.577800   
 9   -2.020585  -2.880984  -2.554863  -1.875770  -1.710705  -0.286836   
 10  -0.749974  -1.517060  -1.486335  -0.996071  -0.866510   0.674511   
 11   0.101525  -0.716568  -1.114454  -0.743268  -0.266492   1.341186   
 12   0.787610  -0.126393  -0.665828  -0.364812   0.380434   1.904141   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    0.879635  -1.037922  -1.608757  -0.993971  -0.006288   1.517292   
 2   -0.910290  -2.552159  -2.745618  -1.903854  -1.875473  -0.274655   
 3   -2.621544  -3.958371  -3.712655  -2.656441  -3.606293  -1.915362   
 4   -3.537508  -4.594481  -3.848148  -2.611601  -4.827470  -2.804322   
 5   -2.703580  -4.132988  -3.570666  -2.510106  -4.036531  -1.787647   
 6   -1.836339  -3.588372  -3.509628  -2.711109  -2.342055  -0.728792   
 7   -2.014500  -3.799281  -3.781227  -3.032443  -1.961957  -0.668614   
 8   -1.951861  -3.707192  -3.648868  -2.906002  -1.984992  -0.701539   
 9   -0.575005  -2.285989  -2.298421  -1.521175  -0.957732   0.465650   
 10   0.346584  -1.388884  -1.608609  -0.861592  -0.252961   1.227451   
 11   0.899180  -1.008087  -1.479437  -0.814989   0.151634   1.696929   
 12   1.317964  -0.649402  -1.205849  -0.619238   0.496267   2.040465   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    1.293427  -1.076949  -0.961444  -1.465843  -1.054283  -1.251830   
 2   -0.356599  -2.439501  -1.906431  -2.187086  -2.490958  -2.518497   
 3   -1.862686  -3.688265  -2.692295  -2.744389  -3.712253  -3.595838   
 4   -2.480246  -4.064628  -2.610355  -2.525962  -4.207016  -3.793235   
 5   -1.384051  -3.387366  -2.240524  -2.362766  -3.723236  -3.157990   
 6   -0.834262  -3.129328  -2.298115  -2.553639  -2.992093  -2.882066   
 7   -1.008741  -3.391417  -2.558477  -2.792893  -3.032274  -3.099540   
 8   -1.027969  -3.389588  -2.520185  -2.753184  -3.066579  -3.152972   
 9    0.259798  -2.043694  -1.149716  -1.435694  -1.917546  -1.932142   
 10   1.024627  -1.304897  -0.630058  -0.973628  -1.173168  -1.230513   
 11   1.476645  -0.898809  -0.644011  -1.101486  -0.794202  -0.904743   
 12   1.811386  -0.579720  -0.501095  -1.050291  -0.492343  -0.676245   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1   -0.900497   2.330291  
 2   -2.020952   1.501422  
 3   -3.039656   0.791856  
 4   -3.205027   0.911552  
 5   -2.655235   1.186515  
 6   -2.497251   1.110683  
 7   -2.742819   0.876896  
 8   -2.806520   0.816494  
 9   -1.513661   2.118705  
 10  -0.831994   2.660746  
 11  -0.573770   2.716295  
 12  -0.381486   2.814162  ,
 'TMIN_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    3.021174   2.399402   2.106356   2.527097   2.506716   4.263146   
 2    2.358741   1.730569   1.488212   2.024098   1.962768   3.761915   
 3    1.089164   0.536975   0.468001   1.113633   0.693427   2.540106   
 4    0.729311   0.316077   0.381792   1.123596   0.426913   2.392246   
 5    0.772089   0.379281   0.206822   0.627536   0.279646   2.416727   
 6    0.979995   0.394530  -0.017066   0.091967   0.309847   2.359464   
 7    1.904426   1.102052   0.729186   0.823083   1.642734   3.414109   
 8    2.420735   1.547430   1.243215   1.337287   2.371200   3.977652   
 9    3.756792   3.005038   2.657164   2.766246   3.438612   5.176290   
 10   4.333659   3.611386   3.212036   3.339778   3.912702   5.691962   
 11   3.620464   3.063568   2.768579   3.123727   3.022557   4.908836   
 12   3.062004   2.528800   2.345891   2.837816   2.462723   4.313215   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    3.963162   2.244257   1.789217   2.430925   2.873215   4.573342   
 2    3.562031   1.838967   1.454713   2.117562   2.517789   4.222385   
 3    2.368858   0.751222   0.468239   1.206404   1.385531   3.065436   
 4    2.275689   0.687180   0.470945   1.207186   1.171481   3.015355   
 5    2.416753   0.524400   0.006367   0.599625   1.420196   3.213760   
 6    2.334137   0.317082  -0.501361  -0.038104   1.679536   3.139230   
 7    3.023797   1.042824   0.177895   0.563612   2.568551   3.935473   
 8    3.353559   1.486896   0.643855   1.020238   2.802036   4.218350   
 9    4.644519   2.884639   2.112836   2.488956   3.864459   5.400016   
 10   5.296029   3.504204   2.799228   3.238345   4.286076   5.941370   
 11   4.676858   2.941579   2.462344   3.049246   3.604590   5.325978   
 12   4.086959   2.430100   2.080719   2.751142   2.910148   4.669498   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    4.509566   2.257298   2.661412   2.159551   2.042010   2.067002   
 2    4.167545   1.990836   2.426529   1.941822   1.786164   1.820696   
 3    2.997742   0.900719   1.443146   1.005912   0.772454   0.776727   
 4    3.049169   0.933153   1.555945   1.074787   0.740366   0.864699   
 5    3.141074   0.713564   1.089974   0.501237   0.559149   0.676002   
 6    2.811650   0.235781   0.560913  -0.094475   0.305317   0.217470   
 7    3.525833   0.892004   1.256843   0.517657   0.967340   0.859519   
 8    3.838070   1.246256   1.699413   0.972094   1.228657   1.168202   
 9    5.119317   2.571257   3.114169   2.412617   2.445760   2.476612   
 10   5.765309   3.302676   3.824802   3.180460   3.094188   3.161137   
 11   5.231377   2.908443   3.379492   2.843907   2.700437   2.749836   
 12   4.644410   2.437409   2.936161   2.464632   2.183094   2.246230   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    2.581375   5.993913  
 2    2.311451   5.744486  
 3    1.238657   4.744479  
 4    1.294404   4.812115  
 5    1.050301   4.382158  
 6    0.541082   3.805492  
 7    1.206430   4.485050  
 8    1.564987   4.887234  
 9    2.983268   6.343093  
 10   3.707911   7.086912  
 11   3.217918   6.636896  
 12   2.740677   6.223072  ,
 'WINDSPD_skookum':            0          1          2          3          4          5   \
      48.78125   48.78125   48.78125   48.78125   48.71875   48.71875   
    -121.96875 -122.03125 -122.09375 -122.15625 -121.90625 -121.96875   
 1    2.059312   2.130022   1.943555   1.758524   1.503031   1.740401   
 2    2.071931   2.124089   1.925563   1.728280   1.559707   1.782179   
 3    1.976048   2.026410   1.909802   1.794179   1.555298   1.727175   
 4    1.755627   1.785508   1.683840   1.582761   1.449465   1.571505   
 5    1.213505   1.262129   1.234266   1.207165   1.022193   1.103391   
 6    0.941658   0.997374   0.992990   0.988967   0.749600   0.817503   
 7    0.622041   0.674850   0.661259   0.647750   0.512832   0.568567   
 8    0.761816   0.808196   0.779429   0.750896   0.622486   0.684166   
 9    1.329461   1.353904   1.269816   1.186110   1.105294   1.192705   
 10   1.690257   1.730929   1.647628   1.565237   1.282794   1.427790   
 11   2.036230   2.099175   1.974463   1.851025   1.480603   1.686991   
 12   2.158969   2.237056   2.078554   1.921300   1.582067   1.818161   
 
            6          7          8          9          10         11  \
      48.71875   48.71875   48.71875   48.71875   48.65625   48.65625   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.90625 -121.96875   
 1    1.905723   1.905598   1.719866   1.598852   1.219165   1.459177   
 2    1.932670   1.925228   1.727202   1.584349   1.285693   1.517324   
 3    1.851412   1.886960   1.770605   1.688556   1.293727   1.485622   
 4    1.656485   1.663998   1.562381   1.481905   1.270245   1.400245   
 5    1.170786   1.168027   1.139962   1.113032   0.997866   1.045827   
 6    0.883877   0.884484   0.879859   0.883028   0.753558   0.767043   
 7    0.611149   0.556257   0.542238   0.536615   0.586987   0.583788   
 8    0.729176   0.685477   0.656710   0.651850   0.637088   0.655265   
 9    1.244983   1.210864   1.126706   1.063443   0.987473   1.070930   
 10   1.531309   1.568570   1.486108   1.434385   0.990226   1.162210   
 11   1.838548   1.888964   1.765323   1.698336   1.113368   1.344765   
 12   1.985083   2.004307   1.846392   1.749322   1.254759   1.501799   
 
            12         13         14         15         16         17  \
      48.65625   48.65625   48.65625   48.65625   48.59375   48.59375   
    -122.03125 -122.09375 -122.15625 -122.21875 -121.96875 -122.03125   
 1    1.633888   1.631620   1.630624   1.579816   1.363666   1.553947   
 2    1.685069   1.675859   1.667598   1.598810   1.390274   1.575357   
 3    1.635985   1.669800   1.704624   1.680378   1.408168   1.570575   
 4    1.499916   1.506168   1.513237   1.475718   1.296644   1.410191   
 5    1.087082   1.083127   1.079718   1.059980   0.963855   1.020015   
 6    0.782833   0.781979   0.781486   0.781997   0.693558   0.720083   
 7    0.574049   0.518377   0.462868   0.437454   0.464264   0.470894   
 8    0.665213   0.620550   0.576235   0.561990   0.526809   0.556137   
 9    1.128561   1.093012   1.057957   1.011206   0.963562   1.039942   
 10   1.299867   1.335033   1.371152   1.362039   1.072304   1.223262   
 11   1.527036   1.575249   1.624935   1.623721   1.225207   1.419861   
 12   1.687238   1.704284   1.722757   1.693323   1.376754   1.577534   
 
            18         19  
      48.59375   48.59375  
    -122.09375 -122.15625  
 1    1.645734   1.670867  
 2    1.667917   1.687921  
 3    1.674265   1.728315  
 4    1.490609   1.518001  
 5    1.090942   1.108068  
 6    0.771315   0.785095  
 7    0.496535   0.463220  
 8    0.607073   0.588868  
 9    1.102377   1.093977  
 10   1.332069   1.388392  
 11   1.541397   1.611093  
 12   1.686382   1.729903  }

In [82]:
print('WRF')
print(ltm_skook['month_TMAX_dailywrf_salathe2014'][0])
print('Obs')
print(ltm_skook['month_TMAX_dailymet_livneh2013'][0])
print('LivBCWRF = Local Correction Factor')
print(BiasCorr_wrfbc_skook ['TMAX_skookum'][0])
print('LivBCWRF result')
print(ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc'][0])
print('WRF bc Livneh Low Elev = Global  Correction Factor')
print(Global_BiasCorr_wrfbc_skook['TMAX_skookum'][0])
print('LivBCWRF+ WRFbcLivLow= Local+Global result')
print(ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc_global'][0])
print('Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m')


WRF
     48.78125
   -121.96875
1   -0.907737
2   -0.128787
3    0.505944
4    2.991481
5    7.008080
6   10.701858
7   14.471835
8   14.930497
9   13.090087
10   8.122808
11   2.604350
12  -0.101475
Obs
     48.78125
   -121.96875
1   -1.297938
2    1.719106
3    4.495383
4    8.532109
5   12.366113
6   14.993918
7   18.437509
8   18.420984
9   15.110672
10   8.872782
11   2.502825
12  -0.889085
LivBCWRF = Local Correction Factor
     48.78125
   -121.96875
1    0.390201
2   -1.847893
3   -3.989439
4   -5.540628
5   -5.358033
6   -4.292060
7   -3.965674
8   -3.490487
9   -2.020585
10  -0.749974
11   0.101525
12   0.787610
LivBCWRF result
     48.78125
   -121.96875
1   -0.907738
2   -0.128794
3    0.505983
4    2.991509
5    7.008113
6   10.701818
7   14.471809
8   14.930484
9   13.090072
10   8.122782
11   2.604325
12  -0.101485
WRF bc Livneh Low Elev = Global  Correction Factor
     48.78125
   -121.96875
1    1.356191
2    2.278853
3    3.037828
4    2.995237
5    2.814513
6    2.924792
7    3.202188
8    3.102685
9    1.751763
10   1.147943
11   1.131971
12   0.958459
LivBCWRF+ WRFbcLivLow= Local+Global result
     48.78125
   -121.96875
1    0.448462
2    2.150106
3    3.543783
4    5.986709
5    9.822613
6   13.626618
7   17.674009
8   18.033184
9   14.841872
10   9.270682
11   3.736325
12   0.857015
Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m

In [ ]:
meta_file

In [84]:
%matplotlib inline

import matplotlib.pyplot as plt

cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']

In [85]:
plt.figure(figsize=(13,5))
plt.rcParams.update({'font.size': 11}) 

plt.subplot(1,2,1)
plt.title('TMAX')
plt.plot(ltm_skook['month_TMAX_dailywrf_salathe2014'][0])
plt.plot(ltm_skook['month_TMAX_dailymet_livneh2013'][0])
plt.plot(ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc'][0])
plt.plot(ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc_global'][0])
plt.legend(['WRF', 'livneh','local','global'])
plt.xlabel('Month')
plt.ylabel('Temperature (Degree C)')
#plt.legend()

plt.subplot(1,2,2)
plt.title('Correction Factor')
plt.plot(BiasCorr_wrfbc_skook['TMAX_skookum'][0])
plt.plot(Global_BiasCorr_wrfbc_skook['TMAX_skookum'][0])
plt.legend(['Local Correction Factor','Global  Correction Factor'])
#print('Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m')
plt.savefig('./monthly_bc_tmax.png',dpi=400)



In [86]:
plt.figure(figsize=(13,5))
plt.rcParams.update({'font.size': 11}) 

plt.subplot(1,2,1)
plt.title('TMAX')
plt.plot(ltm_skook['month_TMAX_dailywrf_salathe2014'][9])
plt.plot(ltm_skook['month_TMAX_dailymet_livneh2013'][9])
plt.plot(ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc'][9])
plt.plot(ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc_global'][9])
plt.legend(['WRF', 'livneh','local','global'])
plt.xlabel('Month')
plt.ylabel('Temperature (Degree C)')
#plt.legend()

plt.subplot(1,2,2)
plt.title('Correction Factor')
plt.plot(BiasCorr_wrfbc_skook['TMAX_skookum'][9])
plt.plot(Global_BiasCorr_wrfbc_skook['TMAX_skookum'][9])
plt.legend(['Local Correction Factor','Global  Correction Factor'])
#print('Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m')
plt.savefig('./monthly_bc_tmax.png',dpi=400)



In [87]:
plt.figure(figsize=(13,5))
plt.rcParams.update({'font.size': 11}) 

plt.subplot(1,2,1)
plt.title('PRECIP')
plt.plot(ltm_skook['month_PRECIP_dailywrf_salathe2014'][0])
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013'][0])
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][0])
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc_global'][0])
plt.legend(['WRF', 'livneh','local','global'])
#plt.legend()

plt.subplot(1,2,2)
plt.title('Correction Factor')
plt.plot(BiasCorr_wrfbc_skook['PRECIP_skookum'][0])
plt.plot(Global_BiasCorr_wrfbc_skook['PRECIP_skookum'][0])
plt.legend(['Local Correction Factor','Global  Correction Factor'])
#print('Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m')
plt.savefig('./monthly_bc_precip.png',dpi=400)



In [88]:
plt.figure(figsize=(13,5))
plt.rcParams.update({'font.size': 11}) 

plt.subplot(1,3,1)
plt.title('PRECIP')
plt.plot(ltm_skook['month_PRECIP_dailywrf_salathe2014'][9], linewidth=5)
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013'][9], linewidth=5)
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][9])
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc_global'][9])
plt.legend(['WRF', 'livneh','local','global'])

#plt.legend()
plt.subplot(1,3,2)
plt.title('PRECIP')
plt.plot(ltm_skook['month_PRECIP_dailywrf_salathe2014'][0], linewidth=5)
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013'][0], linewidth=5)
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc'][0])
plt.plot(ltm_skook['month_PRECIP_dailymet_livneh2013_wrfbc_global'][0])
plt.legend(['WRF', 'livneh','local','global'])
#plt.legend()



plt.subplot(1,3,3)
plt.title('Correction Factor')
plt.plot(BiasCorr_wrfbc_skook['PRECIP_skookum'][0])
plt.plot(BiasCorr_wrfbc_skook['PRECIP_skookum'][9])
plt.plot(Global_BiasCorr_wrfbc_skook['PRECIP_skookum'][9])
plt.legend(['Local Correction Factor','Global  Correction Factor'])
#print('Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m')
plt.savefig('./monthly_bc_precip.png',dpi=400)



In [89]:
plt.figure(figsize=(13,5))
plt.rcParams.update({'font.size': 11}) 

plt.subplot(1,2,1)
plt.title('TMIN')
plt.plot(ltm_skook['month_TMIN_dailywrf_salathe2014'][0])
plt.plot(ltm_skook['month_TMIN_dailymet_livneh2013'][0])
plt.plot(ltm_skook['month_TMIN_dailymet_livneh2013_wrfbc'][0])
plt.plot(ltm_skook['month_TMIN_dailymet_livneh2013_wrfbc_global'][0])
plt.legend(['WRF', 'livneh','local','global'])
#plt.legend()

plt.subplot(1,2,2)
plt.title('Correction Factor')
plt.plot(BiasCorr_wrfbc_skook['TMIN_skookum'][0])
plt.plot(Global_BiasCorr_wrfbc_skook['TMIN_skookum'][0])
plt.legend(['Local Correction Factor','Global  Correction Factor'])
#print('Precipitation values are a ratio of WRF_m/Liv_m and Temperature values are the difference between WRF_m-Liv_m')
plt.savefig('./monthly_bc_tmin.png',dpi=400)



In [ ]:


In [90]:
sorted(ltm_skook.keys())


Out[90]:
['PRECIP_dailymet_livneh2013',
 'PRECIP_dailymet_livneh2013_wrfbc',
 'PRECIP_dailymet_livneh2013_wrfbc_global',
 'PRECIP_dailywrf_salathe2014',
 'TMAX_dailymet_livneh2013',
 'TMAX_dailymet_livneh2013_wrfbc',
 'TMAX_dailymet_livneh2013_wrfbc_global',
 'TMAX_dailywrf_salathe2014',
 'TMIN_dailymet_livneh2013',
 'TMIN_dailymet_livneh2013_wrfbc',
 'TMIN_dailymet_livneh2013_wrfbc_global',
 'TMIN_dailywrf_salathe2014',
 'WINDSPD_dailymet_livneh2013',
 'WINDSPD_dailymet_livneh2013_wrfbc',
 'WINDSPD_dailymet_livneh2013_wrfbc_global',
 'WINDSPD_dailywrf_salathe2014',
 'anom_year_PRECIP_dailymet_livneh2013',
 'anom_year_PRECIP_dailymet_livneh2013_wrfbc',
 'anom_year_PRECIP_dailymet_livneh2013_wrfbc_global',
 'anom_year_PRECIP_dailywrf_salathe2014',
 'anom_year_TMAX_dailymet_livneh2013',
 'anom_year_TMAX_dailymet_livneh2013_wrfbc',
 'anom_year_TMAX_dailymet_livneh2013_wrfbc_global',
 'anom_year_TMAX_dailywrf_salathe2014',
 'anom_year_TMIN_dailymet_livneh2013',
 'anom_year_TMIN_dailymet_livneh2013_wrfbc',
 'anom_year_TMIN_dailymet_livneh2013_wrfbc_global',
 'anom_year_TMIN_dailywrf_salathe2014',
 'anom_year_WINDSPD_dailymet_livneh2013',
 'anom_year_WINDSPD_dailymet_livneh2013_wrfbc',
 'anom_year_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'anom_year_WINDSPD_dailywrf_salathe2014',
 'meanallyear_PRECIP_dailymet_livneh2013',
 'meanallyear_PRECIP_dailymet_livneh2013_wrfbc',
 'meanallyear_PRECIP_dailymet_livneh2013_wrfbc_global',
 'meanallyear_PRECIP_dailywrf_salathe2014',
 'meanallyear_TMAX_dailymet_livneh2013',
 'meanallyear_TMAX_dailymet_livneh2013_wrfbc',
 'meanallyear_TMAX_dailymet_livneh2013_wrfbc_global',
 'meanallyear_TMAX_dailywrf_salathe2014',
 'meanallyear_TMIN_dailymet_livneh2013',
 'meanallyear_TMIN_dailymet_livneh2013_wrfbc',
 'meanallyear_TMIN_dailymet_livneh2013_wrfbc_global',
 'meanallyear_TMIN_dailywrf_salathe2014',
 'meanallyear_WINDSPD_dailymet_livneh2013',
 'meanallyear_WINDSPD_dailymet_livneh2013_wrfbc',
 'meanallyear_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'meanallyear_WINDSPD_dailywrf_salathe2014',
 'meanmonth_PRECIP_dailymet_livneh2013',
 'meanmonth_PRECIP_dailymet_livneh2013_wrfbc',
 'meanmonth_PRECIP_dailymet_livneh2013_wrfbc_global',
 'meanmonth_PRECIP_dailywrf_salathe2014',
 'meanmonth_TMAX_dailymet_livneh2013',
 'meanmonth_TMAX_dailymet_livneh2013_wrfbc',
 'meanmonth_TMAX_dailymet_livneh2013_wrfbc_global',
 'meanmonth_TMAX_dailywrf_salathe2014',
 'meanmonth_TMIN_dailymet_livneh2013',
 'meanmonth_TMIN_dailymet_livneh2013_wrfbc',
 'meanmonth_TMIN_dailymet_livneh2013_wrfbc_global',
 'meanmonth_TMIN_dailywrf_salathe2014',
 'meanmonth_WINDSPD_dailymet_livneh2013',
 'meanmonth_WINDSPD_dailymet_livneh2013_wrfbc',
 'meanmonth_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'meanmonth_WINDSPD_dailywrf_salathe2014',
 'meanyear_PRECIP_dailymet_livneh2013',
 'meanyear_PRECIP_dailymet_livneh2013_wrfbc',
 'meanyear_PRECIP_dailymet_livneh2013_wrfbc_global',
 'meanyear_PRECIP_dailywrf_salathe2014',
 'meanyear_TMAX_dailymet_livneh2013',
 'meanyear_TMAX_dailymet_livneh2013_wrfbc',
 'meanyear_TMAX_dailymet_livneh2013_wrfbc_global',
 'meanyear_TMAX_dailywrf_salathe2014',
 'meanyear_TMIN_dailymet_livneh2013',
 'meanyear_TMIN_dailymet_livneh2013_wrfbc',
 'meanyear_TMIN_dailymet_livneh2013_wrfbc_global',
 'meanyear_TMIN_dailywrf_salathe2014',
 'meanyear_WINDSPD_dailymet_livneh2013',
 'meanyear_WINDSPD_dailymet_livneh2013_wrfbc',
 'meanyear_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'meanyear_WINDSPD_dailywrf_salathe2014',
 'month_PRECIP_dailymet_livneh2013',
 'month_PRECIP_dailymet_livneh2013_wrfbc',
 'month_PRECIP_dailymet_livneh2013_wrfbc_global',
 'month_PRECIP_dailywrf_salathe2014',
 'month_TMAX_dailymet_livneh2013',
 'month_TMAX_dailymet_livneh2013_wrfbc',
 'month_TMAX_dailymet_livneh2013_wrfbc_global',
 'month_TMAX_dailywrf_salathe2014',
 'month_TMIN_dailymet_livneh2013',
 'month_TMIN_dailymet_livneh2013_wrfbc',
 'month_TMIN_dailymet_livneh2013_wrfbc_global',
 'month_TMIN_dailywrf_salathe2014',
 'month_WINDSPD_dailymet_livneh2013',
 'month_WINDSPD_dailymet_livneh2013_wrfbc',
 'month_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'month_WINDSPD_dailywrf_salathe2014',
 'year_PRECIP_dailymet_livneh2013',
 'year_PRECIP_dailymet_livneh2013_wrfbc',
 'year_PRECIP_dailymet_livneh2013_wrfbc_global',
 'year_PRECIP_dailywrf_salathe2014',
 'year_TMAX_dailymet_livneh2013',
 'year_TMAX_dailymet_livneh2013_wrfbc',
 'year_TMAX_dailymet_livneh2013_wrfbc_global',
 'year_TMAX_dailywrf_salathe2014',
 'year_TMIN_dailymet_livneh2013',
 'year_TMIN_dailymet_livneh2013_wrfbc',
 'year_TMIN_dailymet_livneh2013_wrfbc_global',
 'year_TMIN_dailywrf_salathe2014',
 'year_WINDSPD_dailymet_livneh2013',
 'year_WINDSPD_dailymet_livneh2013_wrfbc',
 'year_WINDSPD_dailymet_livneh2013_wrfbc_global',
 'year_WINDSPD_dailywrf_salathe2014']

In [38]:
print(ltm_skook['meanyear_PRECIP_dailymet_livneh2013'].max(axis=0))
print(ltm_skook['meanyear_PRECIP_dailywrf_salathe2014'].max(axis=0))


8.834777400547946
10.526569863013702

In [ ]:


In [ ]:

Save to hydroshare


In [ ]:
from hs_restclient import HydroShare
hs = HydroShare()
hs_up = hydroshare.hydroshare()
notebook_file = './OGH_skookum_hybrid_20200302.ipynb'

In [ ]:
# write meta data such as abstract, title, keywords, resource type
#abstract = 'Notebook for Puyallup Bias-correction'
##title = 'Jupyter notebook Puyallup BC'
#keywords = ('OGH', 'Puyallup', 'notebook') # currently you need to include at least two keywords or the upload will fail
#resource_type = 'genericresource'
#files = notebook_file, # yes, you do need the comma after the file here. It's a python thing (tuple)

7. Apply Hybrid Bias to Future Data (Livneh2013MACA)


In [ ]:
#maptable.columns[8:]
maptable['bcc-csm1-1-m__rcp45']

In [ ]:
meta_MACA_file['CSIRO-Mk3-6-0__rcp45']['date_range']['start']

In [ ]:
for eachcol in maptable.columns[8:]:
    #if eachcol == 'bcc-csm1-1-m__rcp45'
    start_catalog_label1=eachcol
    end_catalog_label1=eachcol+'_wrfbc'
    dest_dir1=eachcol+'_wrfbc'
    Daily_MET_1915_2011_WRFbc, meta_file = ogh.makebelieve(homedir=homedir,
                                                           mappingfile=mappingfile1,
                                                           BiasCorr=BiasCorr_wrfbc_skook,
                                                           metadata=meta_MACA_file,
                                                           start_catalog_label=start_catalog_label1,
                                                           end_catalog_label=end_catalog_label1, 
                                                           file_start_date=meta_MACA_file[start_catalog_label1]['date_range']['start'],
                                                           file_end_date=meta_MACA_file[start_catalog_label1]['date_range']['end'],
                                                           data_dir=None,
                                                           dest_dir_suffix=dest_dir1)
    start_catalog_label2=end_catalog_label1
    end_catalog_label2=eachcol+'_wrfbc_global'
    dest_dir2=eachcol+'_wrfbc_global'
    Daily_MET_1915_2011_WRFbc_global, meta_file = ogh.makebelieve(homedir=homedir,
                                                           mappingfile=mappingfile1,
                                                           BiasCorr=Global_BiasCorr_wrfbc_skook,
                                                           metadata=meta_MACA_file,
                                                           start_catalog_label=start_catalog_label2,
                                                           end_catalog_label=end_catalog_label2, 
                                                           file_start_date=meta_MACA_file[start_catalog_label2]['date_range']['start'],
                                                           file_end_date=meta_MACA_file[start_catalog_label2]['date_range']['end'],
                                                           data_dir=None,
                                                           dest_dir_suffix=dest_dir2)

In [ ]:
for each2map in ['IPSL-CM5A-MR__rcp45','IPSL-CM5A-MR__rcp45_wrfbc','IPSL-CM5A-MR__rcp45_wrfbc_global']:
    ltm_skook = ogh.gridclim_dict(mappingfile=mappingfile1,
                               metadata=meta_file,
                               dataset=each2map,
                               file_start_date=meta_MACA_file[start_catalog_label2]['date_range']['start'],
                               file_end_date=meta_MACA_file[start_catalog_label2]['date_range']['end'],
                               file_time_step=dr1['temporal_resolution'],
                               subset_start_date=dr[0],
                               subset_end_date=dr[1],
                               df_dict=ltm_skook)

8. Compare Corrected Future Hydrometeorology to Historic percent correction


In [ ]:


In [ ]:

9. Make Beautiful Maps


In [ ]:
# graphical control libraries
import matplotlib as mpl
# mpl.use('agg')
import matplotlib.pyplot as plt


# shape and layer libraries
import fiona
import shapely.ops
from shapely.geometry import MultiPolygon, shape, point, box
from descartes import PolygonPatch
from matplotlib.collections import PatchCollection
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.axes_grid1 import make_axes_locatable
import geopandas as gpd

def renderValuesInPoints_scale(vardf, vardf_dateindex, vardfmin, vardfmax, shapefile, outfilepath, plottitle, colorbar_label,
                         spatial_resolution=1/16, margin=0.5, epsg=3857,
                         basemap_image='Canvas/World_Dark_Gray_Base', cmap='coolwarm'):
    """
    A function to render the dynamics across gridded cell centroids on the spatial landscape
    
    vardf: (dataframe) a time-series dataframe for a variable with time-points (rows) and gridded cell centroids (column)
    vardf_dateindex: (datetime or float) a datetime identifier to extract a row of data for visualization
    shapefile: (dir) the path to a shapefile
    outfilepath: (dir) the path for the output image file
    plottitle: (str) the title of the plot
    colorbar_label: (str) the label for the colorbar
    spatial_resolution: (float) the degree of longitude-latitude separation between gridded cell centroids, e.g., 1/16
    margin: (float) the fraction of width and height to view outside of the watershed shapefile
    epsg: (int) the epsg code for regional projection, e.g. 3857
    basemap_image: (str) the basemap arcgis service e.g., 'Canvas/World_Dark_Gray_Base' or 'ESRI_Imagery_World_2D'
    cmap: (str) the code for matplotlib colormaps, e.g. 'coolwarm',
    """
    
    # generate the figure axis
    fig = plt.figure(figsize=(2,2), dpi=500)
    ax1 = plt.subplot2grid((1,1),(0,0))

    # generate the polygon color-scheme
    cmap = mpl.cm.get_cmap(cmap)
    norm = mpl.colors.Normalize(vardfmin, vardfmax)
    color_producer = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)

    # calculate bounding box based on the watershed shapefile
    watershed = fiona.open(shapefile)
    minx, miny, maxx, maxy = watershed.bounds
    w, h = maxx - minx, maxy - miny
    watershed.close()
    
    # generate basemap
    m = Basemap(projection='merc', epsg=epsg, resolution='h', ax=ax1,
                llcrnrlon=minx-margin*w, llcrnrlat=miny-margin*h, urcrnrlon=maxx+margin*w, urcrnrlat=maxy+margin*h)
    m.arcgisimage(service=basemap_image, xpixels=500)
                         
    # watershed
    m.readshapefile(shapefile=shapefile.replace('.shp',''), name='watershed', drawbounds=True, color='k')
    
    # variable dataframe
    midpt=spatial_resolution/2
    crs={'init':'epsg:{0}'.format(epsg)}
    cat=vardf.T.reset_index(level=[1,2]).rename(columns={'level_1':'LAT','level_2':'LONG_'})
    geometry = cat.apply(lambda x: 
                         shapely.ops.transform(m, box(x['LONG_']-midpt, x['LAT']-midpt, 
                                                      x['LONG_']+midpt, x['LAT']+midpt)), axis=1)
    cat = gpd.GeoDataFrame(cat, crs=crs, geometry=geometry).reset_index(drop=True)

    # geopandas print
    cat.plot(column=vardf_dateindex, cmap=cmap, alpha=0.4, ax=ax1,
             vmin=vardfmin, vmax=vardfmax)

    # assimilate the shapes to plot
    patches = []
    for ind, eachpol in cat.iterrows():
        patches.append(PolygonPatch(eachpol['geometry'], linewidth=0, zorder=5.0,
                                    fc=color_producer.to_rgba(eachpol[vardf_dateindex])))

    # assimilate shapes into a patch collection
    coll = PatchCollection(patches, cmap=cmap, match_original=True, zorder=10.0)
    
    # generate colorbar
    coll.set_array(vardf.values.flatten())
    coll.set_clim([vardfmin, vardfmax])
    cbar = plt.colorbar(coll, shrink=0.5)
    cbar.ax.set_ylabel(colorbar_label, rotation=270, size=3, labelpad=5) # colorbar label
    cbar.ax.tick_params(labelsize=3) # colorbar tick fontsize

    # save image
    plt.title(plottitle, fontsize=3)
    plt.savefig(outfilepath)
    plt.show()

In [ ]:
def renderValuesInPoints(vardf, vardf_dateindex, shapefile, outfilepath, plottitle, colorbar_label,
                         vmin=None, vmax=None, spatial_resolution=1/16, margin=0.5, gridcell_alpha=0.5, epsg=3857,
                         basemap_image='Canvas/World_Dark_Gray_Base', cmap='coolwarm', figsize=(2, 2)):
    """
    A function to render the dynamics across gridded cell centroids on the spatial landscape
    vardf: (dataframe) a time-series dataframe for a variable with time-points (rows) and gridded cell centroids (column)
    vardf_dateindex: (datetime or float) a datetime identifier to extract a row of data for visualization
    shapefile: (dir) the path to a shapefile
    outfilepath: (dir) the path for the output image file
    plottitle: (str) the title of the plot
    colorbar_label: (str) the label for the colorbar
    spatial_resolution: (float) the degree of longitude-latitude separation between gridded cell centroids, e.g., 1/16
    margin: (float) the fraction of width and height to view outside of the watershed shapefile
    epsg: (int) the epsg code for regional projection, e.g. 3857
    basemap_image: (str) the basemap arcgis service e.g., 'Canvas/World_Dark_Gray_Base' or 'ESRI_Imagery_World_2D'
    cmap: (str) the code for matplotlib colormaps, e.g. 'coolwarm',
    """
    # generate the figure axis
    fig = plt.figure(figsize=figsize, dpi=500)
    ax1 = plt.subplot2grid((1, 1), (0, 0))

    # set params
    if isinstance(vmin, type(None)):
        vmin = vardf.values.flatten().min()

    if isinstance(vmax, type(None)):
        vmax = vardf.values.flatten().max()

    # generate the polygon color-scheme
    cmap = mpl.cm.get_cmap(cmap)
    norm = mpl.colors.Normalize(vmin, vmax)
    color_producer = mpl.cm.ScalarMappable(norm=norm, cmap=cmap)

    # calculate bounding box based on the watershed shapefile
    watershed = fiona.open(shapefile)
    minx, miny, maxx, maxy = watershed.bounds
    w, h = maxx - minx, maxy - miny
    watershed.close()

    # generate basemap
    m = Basemap(projection='merc', epsg=epsg, resolution='h', ax=ax1,
                llcrnrlon=minx-margin*w, llcrnrlat=miny-margin*h, urcrnrlon=maxx+margin*w, urcrnrlat=maxy+margin*h)
    m.arcgisimage(service=basemap_image, xpixels=500)

    # watershed
    m.readshapefile(shapefile=shapefile.replace('.shp', ''), name='watershed', drawbounds=True, linewidth=1, color='m')

    # variable dataframe
    midpt = spatial_resolution/2
    crs = {'init': 'epsg:{0}'.format(epsg)}
    cat = vardf.T.reset_index(level=[1, 2]).rename(columns={'level_1': 'LAT', 'level_2': 'LONG_'})
    geometry = cat.apply(lambda x: shapely.ops.transform(m, box(x['LONG_'] - midpt, x['LAT'] - midpt,
                                                                x['LONG_'] + midpt, x['LAT'] + midpt)), axis=1)
    cat = gpd.GeoDataFrame(cat, crs=crs, geometry=geometry).reset_index(drop=True)

    # geopandas print
    cat.plot(column=vardf_dateindex, cmap=cmap, alpha=gridcell_alpha, ax=ax1, vmin=vmin, vmax=vmax)

    # assimilate the shapes to plot
    patches = []
    for ind, eachpol in cat.iterrows():
        patches.append(PolygonPatch(eachpol['geometry'], linewidth=0, zorder=5.0,
                                    fc=color_producer.to_rgba(eachpol[vardf_dateindex])))

    # assimilate shapes into a patch collection
    coll = PatchCollection(patches, cmap=cmap, match_original=True, zorder=10.0)

    # generate colorbar
    coll.set_array(vardf.values.flatten())
    coll.set_clim([vmin, vmax])
    cbar = plt.colorbar(coll, shrink=0.5)
    cbar.ax.set_ylabel(colorbar_label, rotation=270, size=3, labelpad=3)  # colorbar label
    cbar.ax.tick_params(labelsize=2)  # colorbar tick fontsize
    cbar.outline.set_visible(False)  # colorbar outline

    # save image
    plt.title(plottitle, fontsize=3)
    plt.savefig(outfilepath)
    plt.show()

Precipitation


In [ ]:
for eachdict, region, shp in zip([ltm_skook], ['Skookum'],[skookum]):
    for eachdf, product in zip(['PRECIP_IPSL-CM5A-MR__rcp45','PRECIP_IPSL-CM5A-MR__rcp45_wrfbc', 'PRECIP_IPSL-CM5A-MR__rcp45_wrfbc_global','PRECIP_dailymet_livneh2013'], 
                               ['IPSL-CM5A-MR__rcp45','IPSL-CM5A-MR__rcp45_Hybrid-1','IPSL-CM5A-MR__rcp45_Hydrid','OBS']):
        
        # variable time-series
        ts = eachdict[eachdf].groupby(pd.TimeGrouper("A")).sum().mean(axis=0)
        eachdict['mean_annualsum_'+eachdf] = pd.DataFrame(ts).T
        
        # generate spatial map for mean annual sum P
        renderValuesInPoints(vardf=eachdict['mean_annualsum_'+eachdf],
                             vardf_dateindex=0,
                             shapefile=shp,
                             outfilepath=os.path.join(homedir, '{0}{1}Precip.png'.format(region,product)),
                             plottitle=region+' Watershed'+'\n Mean Annual Precipitation - ' + product,
                             colorbar_label='Mean annual precipitation (mm)',
                             spatial_resolution=1/16, margin=0.15, epsg=3857,
                             basemap_image='Elevation/World_Hillshade',
                             cmap='viridis_r')

In [ ]:
for eachdict, region, shp,vmin, vmax in zip([ltm_skook], ['Skookum'],[skookum]): 
                                           [1000,1000,1000],[5000,5000,5000]):
    for eachdf, product in zip(['PRECIP_IPSL-CM5A-MR__rcp45','PRECIP_IPSL-CM5A-MR__rcp45_wrfbc', 'PRECIP_IPSL-CM5A-MR__rcp45_wrfbc_global','PRECIP_dailymet_livneh2013','PRECIP_dailymet_livneh2013_wrfbc_global'], 
                               ['IPSL-CM5A-MR__rcp45','IPSL-CM5A-MR__rcp45_Hybrid-1','IPSL-CM5A-MR__rcp45_Hydrid','OBS','Historical Hybrid']):
        
        # variable time-series
        ts = eachdict[eachdf].groupby(pd.TimeGrouper("A")).sum().mean(axis=0)
        eachdict['mean_annualsum_'+eachdf] = pd.DataFrame(ts).T
        
        # generate spatial map for mean annual sum P
        renderValuesInPoints_scale(vardf=eachdict['mean_annualsum_'+eachdf],
                             vardf_dateindex=0,
                             vardfmin=vmin,
                             vardfmax=vmax,
                             shapefile=shp,
                             outfilepath=os.path.join(homedir, '{0}{1}Precip.png'.format(region,product)),
                             plottitle=region+' Watershed'+'\n Mean Annual Precipitation - ' + product,
                             colorbar_label='Mean annual precipitation (mm)',
                             spatial_resolution=1/16, margin=0.15, epsg=3857,
                             basemap_image='Elevation/World_Hillshade',
                             cmap='viridis_r')

In [ ]:
for eachdict, region, shp in zip([ltm_skook], ['Skookum'], [skookum]):
    for eachdf, product in zip(['PRECIP_dailywrf_salathe2014', 'PRECIP_dailymet_livneh2013', 'PRECIP_dailymet_livneh2013_wrfbc', 'PRECIP_dailymet_livneh2013_wrfbc_global' ], ['WRF', 'OBS','Hybrid-1','Hydrid-!!']):
        
        # variable time-series
        ts = eachdict[eachdf].groupby(pd.TimeGrouper("Y")).sum().mean(axis=0)
        eachdict['mean_annualsum_'+eachdf] = pd.DataFrame(ts).T
        
        # generate spatial map for mean annual sum P
        renderValuesInPoints(vardf=eachdict['mean_annualsum_'+eachdf],
                             vardf_dateindex=0,
                             shapefile=shp,
                             outfilepath=os.path.join(homedir, '{0}{1}Precip.png'.format(region,product)),
                             plottitle=region+' Watershed'+'\n Mean Annual Precipitation - ' + product,
                             colorbar_label='Mean annual precipitation (mm)',
                             spatial_resolution=1/16, margin=0.15, epsg=3857,
                             basemap_image='Elevation/World_Hillshade',
                             cmap='viridis_r')
plt.savefig('\mean_annual_precipitation.png')

In [ ]:
for eachdict, region, shp in zip([ltm_skook, ltm_skook, ltm_skook], ['Skookum','Skookum','Skookum'], [skagit, sauk, upperforks]):
    for eachdf, product in zip(['PRECIP_dailywrf_salathe2014', 'PRECIP_dailymet_livneh2013'], ['WRF', 'OBS']):
        
        # variable time-series
        ts = eachdict[eachdf].groupby(pd.TimeGrouper("Y")).sum().mean(axis=0)
        eachdict['mean_annualsum_'+eachdf] = pd.DataFrame(ts).T
        
        # generate spatial map for mean annual sum P
        renderValuesInPoints_scale(vardf=eachdict['mean_annualsum_'+eachdf],
                             vardf_dateindex=0,
                             vardfmin=vmin,
                             vardfmax=vmax,
                             shapefile=shp,
                             outfilepath=os.path.join(homedir, '{0}{1}Precip.png'.format(region,product)),
                             plottitle=region+' Watershed'+'\n Mean Annual Precipitation - ' + product,
                             colorbar_label='Mean annual precipitation (mm)',
                             spatial_resolution=1/16, margin=0.15, epsg=3857,
                             basemap_image='Elevation/World_Hillshade',
                             cmap='viridis_r')

In [ ]:
for eachdict, region, shp, vmin, vmax in zip([ltm_skagit],
                                             ['Puyallup'], 
                                             [puyallup],
                                             [700,1400,2000],
                                             [5304,3500,3500]):
    for eachdf, product in zip(['PRECIP_dailywrf_salathe2014', 'PRECIP_dailymet_livneh2013', 'PRECIP_dailymet_livneh2013_wrfbc', 'PRECIP_dailymet_livneh2013_wrfbc_global'], ['WRF', 'OBS','Hybrid-1','Hydrid-!!']):
        
        # variable time-series
        ts = eachdict[eachdf].groupby(pd.TimeGrouper("Y")).sum().mean(axis=0)
        eachdict['mean_annualsum_'+eachdf] = pd.DataFrame(ts).T
        
        # generate spatial map for mean annual sum P
        renderValuesInPoints_scale(vardf=eachdict['mean_annualsum_'+eachdf],
                             vardf_dateindex=0,
                             vardfmin=vmin,
                             vardfmax=vmax,
                             shapefile=shp,
                             outfilepath=os.path.join(homedir, '{0}{1}Precip.png'.format(region,product)),
                             plottitle=region+' Watershed'+'\n Mean Annual Precipitation - ' + product,
                             colorbar_label='Mean annual precipitation (mm)',
                             spatial_resolution=1/16, margin=0.15, epsg=3857,
                             basemap_image='Elevation/World_Hillshade',
                             cmap='viridis_r')

plt.savefig('../../../../../../puyallup/mean_annual_precipitation_bc.png')

In [ ]:
for eachdict, region, shp, vmin, vmax in zip([ltm_skagit, ltm_sauk, ltm_upperforks],
                                             ['Skagit','Sauk','Upperforks'], 
                                             [skagit, sauk, upperforks],
                                             [700,1400,2000],
                                             [5304,3500,3500]):
    for eachdf, product in zip(['PRECIP_dailywrf_salathe2014', 'PRECIP_dailymet_livneh2013'], ['WRF', 'OBS']):
        
        # variable time-series
        ts = eachdict[eachdf].groupby(pd.TimeGrouper("Y")).sum().mean(axis=0)
        eachdict['mean_annualsum_'+eachdf] = pd.DataFrame(ts).T
        
        # generate spatial map for mean annual sum P
        renderValuesInPoints_scale(vardf=eachdict['mean_annualsum_'+eachdf],
                             vardf_dateindex=0,
                             vardfmin=vmin,
                             vardfmax=vmax,
                             shapefile=shp,
                             outfilepath=os.path.join(homedir, '{0}{1}Precip.png'.format(region,product)),
                             plottitle=region+' Watershed'+'\n Mean Annual Precipitation - ' + product,
                             colorbar_label='Mean annual precipitation (mm)',
                             spatial_resolution=1/16, margin=0.15, epsg=3857,
                             basemap_image='Elevation/World_Hillshade',
                             cmap='viridis_r')

Temperature


In [ ]:
for eachdict, region, shp in zip([ltm_skagit],['Skookum'],[skookum]):
    for eachdf, product in zip(['month_TMAX_dailywrf_salathe2014', 'month_TMAX_dailymet_livneh2013', 'month_TMAX_dailymet_livneh2013_wrfbc', 'month_TMAX_dailymet_livneh2013_wrfbc_global'], ['WRF', 'OBS','Hydrid-1','Hydbrid-!!']):
        
        month=11
        monthlabel = pd.datetime.strptime(str(month), '%m')
        renderValuesInPoints(vardf=eachdict[eachdf],
                         vardf_dateindex=month,
                         shapefile=shp,
                         outfilepath=os.path.join(homedir, '{0}{1}TMAX.png'.format(region,product)),
                         plottitle=region+' Watershed'+'\nTemperature Max in '+ monthlabel.strftime('%B')+'-'+product,
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')
            
plt.savefig('../../../../../../puyallup/avg_dail_max_temp.png')

In [ ]:
for eachdict, region, shp in zip([ltm_skagit, ltm_sauk, ltm_upperforks], ['Skagit','Sauk','Upperforks'], [skagit, sauk, upperforks]):
    for eachdf, product in zip(['month_TMAX_dailywrf_salathe2014', 'month_TMAX_dailymet_livneh2013'], ['WRF', 'OBS']):
        
        month=11
        monthlabel = pd.datetime.strptime(str(month), '%m')
        renderValuesInPoints(vardf=eachdict[eachdf],
                         vardf_dateindex=month,
                         shapefile=shp,
                         outfilepath=os.path.join(homedir, '{0}{1}TMAX.png'.format(region,product)),
                         plottitle=region+' Watershed'+'\nTemperature Max in '+ monthlabel.strftime('%B')+'-'+product,
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

In [ ]:
month=11
# print(ltm_skagit['month_TMAX_dailymet_livneh2013'].max(axis=1))  #11C
# print(ltm_skagit['month_TMAX_dailywrf_salathe2014'].max(axis=1))
# print(ltm_sauk['month_TMAX_dailymet_livneh2013'].max(axis=1))  #9C
# print(ltm_sauk['month_TMAX_dailywrf_salathe2014'].max(axis=1))
# print(ltm_upperforks['month_TMAX_dailymet_livneh2013'].max(axis=1))  #6C
# print(ltm_upperforks['month_TMAX_dailywrf_salathe2014'].max(axis=1))

# print(ltm_skagit['month_TMAX_dailymet_livneh2013'].max(axis=1))  #11C
# print(ltm_skagit['month_TMAX_dailywrf_salathe2014'].max(axis=1))
# print(ltm_skagit['month_TMAX_dailymet_livneh2013_wrfbc'].max(axis=1))  #11C
# print(ltm_skagit['month_TMAX_dailymet_livneh2013_wrfbc_global'].max(axis=1))


print(ltm_skagit['month_TMAX_dailymet_livneh2013'].min(axis=1))  #11C
print(ltm_skagit['month_TMAX_dailywrf_salathe2014'].min(axis=1))
print(ltm_skagit['month_TMAX_dailymet_livneh2013_wrfbc'].min(axis=1))  #11C
print(ltm_skagit['month_TMAX_dailymet_livneh2013_wrfbc_global'].min(axis=1))

In [ ]:
for eachdict, region, shp, vmin, vmax in zip([ltm_skook],
                                             ['Skookum'], 
                                             [skookum],
                                             [-6,-6,-2],
                                             [14,9,6]):
    for eachdf, product in zip(['month_TMAX_dailywrf_salathe2014', 'month_TMAX_dailymet_livneh2013', 'month_TMAX_dailymet_livneh2013_wrfbc', 'month_TMAX_dailymet_livneh2013_wrfbc_global'], ['WRF', 'OBS','Hydrid-1','Hydbrid-!!']):
            month=11
            monthlabel = pd.datetime.strptime(str(month), '%m')
            renderValuesInPoints_scale(vardf=eachdict[eachdf],
                         vardf_dateindex=month,
                         vardfmin=vmin,
                         vardfmax=vmax,
                         shapefile=shp,
                         outfilepath=os.path.join(homedir, '{0}{1}TMAX.png'.format(region,product)),
                         plottitle=region+' Watershed'+'\nTemperature Max in '+ monthlabel.strftime('%B')+'-'+product,
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')
            
plt.savefig('avg_dail_max_temp_bc.png')

In [ ]:
for eachdict, region, shp, vmin, vmax in zip([ltm_skagit, ltm_sauk, ltm_upperforks],
                                             ['Skagit','Sauk','Upperforks'], 
                                             [skagit, sauk, upperforks],
                                             [-6,-6,-2],
                                             [11,9,6]):
    for eachdf, product in zip(['month_TMAX_dailywrf_salathe2014', 'month_TMAX_dailymet_livneh2013'], ['WRF', 'OBS']):
        
     
        month=11
        monthlabel = pd.datetime.strptime(str(month), '%m')
        renderValuesInPoints_scale(vardf=eachdict[eachdf],
                         vardf_dateindex=month,
                         vardfmin=vmin,
                         vardfmax=vmax,
                         shapefile=shp,
                         outfilepath=os.path.join(homedir, '{0}{1}TMAX.png'.format(region,product)),
                         plottitle=region+' Watershed'+'\nTemperature Max in '+ monthlabel.strftime('%B')+'-'+product,
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

Calculate number of grid cells below 0C (snowy on average)


In [ ]:
ltm_skook['month_TMAX_dailywrf_salathe2014']
for eachdict, region, shp, vmin, vmax in zip([ltm_skook],
                                             ['skookum'], 
                                             [skookum],
                                             [-6,-6,-2],
                                             [11,9,6]):
    for eachdf, product in zip(['month_TMAX_dailywrf_salathe2014', 'month_TMAX_dailymet_livneh2013', 'month_TMAX_dailymet_livneh2013_wrfbc','month_TMAX_dailymet_livneh2013_wrfbc_global'], ['WRF', 'OBS','Hybrid-1','Hybrid-!!']):
                  temp = eachdict[eachdf].copy()
                  temp[temp>=0] = 0 # temperatures over 0
                  temp[temp<0] = 1 # temperatures under 0

                  # count each month average with T<0 FOR EACH MONTH
                  eachdict['freeze_month_'+eachdf] = temp.sum(axis=1)

In [ ]:
ltm_skook['month_TMIN_dailywrf_salathe2014']
for eachdict, region, shp, vmin, vmax in zip([ltm_skook],
                                             ['skookum'], 
                                             [skookum],
                                             [-6,-6,-2],
                                             [11,9,6]):
    for eachdf, product in zip(['month_TMIN_dailywrf_salathe2014', 'month_TMIN_dailymet_livneh2013', 'month_TMIN_dailymet_livneh2013_wrfbc','month_TMIN_dailymet_livneh2013_wrfbc_global'], ['WRF', 'OBS','Hybrid-1','Hybrid-!!']):
                  temp = eachdict[eachdf].copy()
                  temp[temp>=-1] = 0 # temperatures over 0
                  temp[temp<-1] = 1 # temperatures under 0

                  # count each month average with T<0 FOR EACH MONTH
                  eachdict['freeze_'+eachdf] = temp.sum(axis=1)

In [ ]:
sorted(ltm_skook.keys())#['freeze_month_TMAX_dailywrf_salathe2014']  
#ltm_skook['month_TMAX_dailywrf_salathe2014']
#ltm_skook['month_TMAX_dailymet_livneh2013']
#ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc']
#ltm_skook['month_TMAX_dailymet_livneh2013_wrfbc_global']
#ltm_skook['freeze_month_month_TMAX_dailywrf_salathe2014']
ltm_skook['freeze_month_TMIN_dailywrf_salathe2014']

In [ ]:
sorted(ltm_skook.keys())#['freeze_month_TMIN_dailywrf_salathe2014']
print(ltm_skook['freeze_month_TMIN_dailywrf_salathe2014'][11]/241)
print(ltm_skook['freeze_month_TMIN_dailymet_livneh2013'][11]/241)
print(ltm_skook['freeze_month_TMIN_dailymet_livneh2013_wrfbc'][11]/241)
print(ltm_skook['freeze_month_TMIN_dailymet_livneh2013_wrfbc_global'][11]/241)
#Results for TMIN Snow at 0
0.709543568465
0.879668049793
0.709543568465
0.883817427386
#Results for TMIN Snow at -1
0.643153526971
0.850622406639
0.643153526971
0.780082987552

In [ ]:
sorted(ltm_skagit.keys())#['freeze_month_TMAX_dailywrf_salathe2014']
print(ltm_skagit['freeze_month_month_TMAX_dailywrf_salathe2014'][11]/241)
print(ltm_skagit['freeze_month_month_TMAX_dailymet_livneh2013'][11]/241)
print(ltm_skagit['freeze_month_month_TMAX_dailymet_livneh2013_wrfbc'][11]/241)
print(ltm_skagit['freeze_month_month_TMAX_dailymet_livneh2013_wrfbc_global'][11]/241)
#Results for TMAX Snow at 0
# 0.327800829876
# 0.352697095436
# 0.327800829876
# 0.0912863070539
#Results for TMAX Snow at -1
0.149377593361
0.248962655602
0.149377593361
0.0

Not sure if needed


In [ ]:
year=2006
yearlabel = pd.datetime.strptime(str(year), '%Y')
renderValuesInPoints(vardf=ltm_skagit['year_PRECIP_dailymet_livneh2013'],
                         vardf_dateindex=year,
                         shapefile=skagit,
                         outfilepath=os.path.join(homedir, 'skagitPrecip{0}.png'.format(yearlabel.strftime('%Y'))),
                         plottitle='Skagit Watershed'+'\nPrecipitation in '+ yearlabel.strftime('%Y'),
                         colorbar_label='Average daily precipitation (mm)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic_r')
year=2006
yearlabel = pd.datetime.strptime(str(year), '%Y')
renderValuesInPoints(vardf=ltm_sauk['year_PRECIP_dailymet_livneh2013'],
                         vardf_dateindex=year,
                         shapefile=sauk,
                         outfilepath=os.path.join(homedir, 'SaukPrecip{0}.png'.format(yearlabel.strftime('%Y'))),
                         plottitle='Skagit Watershed'+'\nPrecipitation in '+ yearlabel.strftime('%Y'),
                         colorbar_label='Average daily precipitation (mm)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic_r')
year=2006
yearlabel = pd.datetime.strptime(str(year), '%Y')
renderValuesInPoints(vardf=ltm_upperforks['year_PRECIP_dailymet_livneh2013'],
                         vardf_dateindex=year,
                         shapefile=upperforks,
                         outfilepath=os.path.join(homedir, 'upperforksPrecip{0}.png'.format(yearlabel.strftime('%Y'))),
                         plottitle='Skagit Watershed'+'\nPrecipitation in '+ yearlabel.strftime('%Y'),
                         colorbar_label='Average daily precipitation (mm)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic_r')

In [ ]:
month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=scale_df,
                         vardf_dateindex=month,
                         shapefile=skagit,
                         outfilepath=os.path.join(homedir, 'SkagitLivTmax{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Skagit Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_sauk['month_TMAX_dailymet_livneh2013'],
                         vardf_dateindex=month,
                         shapefile=sauk,
                         outfilepath=os.path.join(homedir, 'SaukLivTmax{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Sauk-Suiattle Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_upperforks['month_TMAX_dailymet_livneh2013'],
                         vardf_dateindex=month,
                         shapefile=upperforks,
                         outfilepath=os.path.join(homedir, 'UpperforkLivTmax{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Upper Sauk Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

In [ ]:
month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_skagit['month_TMAX_dailywrf_salathe2014'],
                         vardf_dateindex=month,
                         shapefile=skagit,
                         outfilepath=os.path.join(homedir, 'SkagitWRFTmax{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Skagit Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_sauk['month_TMAX_dailywrf_salathe2014'],
                         vardf_dateindex=month,
                         shapefile=sauk,
                         outfilepath=os.path.join(homedir, 'SaukWRFTmax{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Sauk-Suiattle Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_upperforks['month_TMAX_dailywrf_salathe2014'],
                         vardf_dateindex=month,
                         shapefile=upperforks,
                         outfilepath=os.path.join(homedir, 'UpperforkWRFTmax{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Upper Sauk Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily max temperature (C)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic')

In [ ]:
sorted(ltm_skagit.keys())

In [ ]:
ltm_skagit['PRECIP_dailywrf_salathe2014']

In [ ]:
ltm_sauk['PRECIP_dailywrf_salathe2014'].mean(axis=1).plot()

In [ ]:
sorted(ltm_skagit.keys())

In [ ]:
for eachdict, region in zip([ltm_skagit, ltm_sauk, ltm_upperforks], ['skagit','sauk','upperforks']):
    for eachdf in ['PRECIP_dailywrf_salathe2014', 'PRECIP_dailymet_livneh2013','PRECIP_dailymet_livneh2013_wrfbc','PRECIP_dailymet_livneh2013_wrfbc_global']:
        
        # variable time-series
        ts = eachdict[eachdf].mean(axis=1).reset_index().rename(columns={0:'var', 'index':'date'})

        # adjust time-series into dataframe
        ts['year'] = ts.date.apply(lambda x: x.year)
        ts['month'] = ts.date.apply(lambda x: x.month)
        ts['day'] = ts.date.apply(lambda x: x.day)
        ts = ts[['year','month','day','var']]

        # output the file
        ts.to_csv(os.path.join(homedir, region+'_'+eachdf+'.txt'), sep='\t', header=False, index=False)
        
        print('DONE: '+ region+'_'+eachdf+'.txt')
        
sorted(os.listdir(homedir))

In [ ]:
for eachdict, region in zip([ltm_skagit, ltm_sauk, ltm_upperforks], ['skagit','sauk','upperforks']):
    for eachdf in ['PRECIP_dailywrf_salathe2014', 'PRECIP_dailymet_livneh2013']:
        
        # variable time-series
        ts = eachdict[eachdf].mean(axis=1).reset_index().rename(columns={0:'var', 'index':'date'})

        # adjust time-series into dataframe
        ts['year'] = ts.date.apply(lambda x: x.year)
        ts['month'] = ts.date.apply(lambda x: x.month)
        ts['day'] = ts.date.apply(lambda x: x.day)
        ts = ts[['year','month','day','var']]

        # output the file
        ts.to_csv(os.path.join(homedir, region+'_'+eachdf+'.txt'), sep='\t', header=False, index=False)
        
        print('DONE: '+ region+'_'+eachdf+'.txt')
        
sorted(os.listdir(homedir))

In [ ]:
month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_skagit['month_PRECIP_dailywrf_salathe2014'],
                         vardf_dateindex=month,
                         shapefile=skagit,
                         outfilepath=os.path.join(homedir, 'SkagitWRFPrecip{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Skagit Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily precipitation (mm)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic_r')

month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_sauk['month_PRECIP_dailywrf_salathe2014'],
                         vardf_dateindex=month,
                         shapefile=sauk,
                         outfilepath=os.path.join(homedir, 'SaukWRFPrecip{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Sauk-Suiattle Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily precipitation (mm)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic_r')

month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_upperforks['month_PRECIP_dailywrf_salathe2014'],
                         vardf_dateindex=month,
                         shapefile=upperforks,
                         outfilepath=os.path.join(homedir, 'UpperForksWRFPrecip{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Upper Sauk Watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average daily precipitation (mm)',
                         spatial_resolution=1/16, margin=0.15, epsg=3857,
                         basemap_image='Elevation/World_Hillshade',
                         cmap='seismic_r')

In [ ]:
month=11
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_sauk['month_PRECIP_dailymet_livneh2013'],
                         vardf_dateindex=month,
                         shapefile=sauk.replace('.shp','_2.shp'), 
                         outfilepath=os.path.join(homedir, 'SaukPrecip{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Sauk-Suiattle watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average monthly precipitation (meters)',
                         spatial_resolution=1/16, margin=0.5, epsg=3857,
                         basemap_image='Demographics/USA_Social_Vulnerability_Index',
                         cmap='gray_r')

month=6
monthlabel = pd.datetime.strptime(str(month), '%m')
renderValuesInPoints(vardf=ltm_sauk['month_PRECIP_dailymet_livneh2013'],
                         vardf_dateindex=month,
                         shapefile=sauk.replace('.shp','_2.shp'), 
                         outfilepath=os.path.join(homedir, 'SaukPrecip{0}.png'.format(monthlabel.strftime('%b'))),
                         plottitle='Sauk-Suiattle watershed'+'\nPrecipitation in '+ monthlabel.strftime('%B'),
                         colorbar_label='Average monthly precipitation (meters)',
                         spatial_resolution=1/16, margin=0.5, epsg=3857,
                         basemap_image='ESRI_StreetMap_World_2D',
                         cmap='gray_r')

In [ ]:
for month in [3, 6, 9, 12]:
    monthlabel = pd.datetime.strptime(str(month), '%m')
    outfile='SkookumLivnehPrecip{0}.png'.format(monthlabel.strftime('%b'))
    
    ax1 = renderValuesInPoints(vardf=ltm_skook['month_PRECIP_dailymet_livneh2013'],
                                   vardf_dateindex=month,
                                   shapefile=shp, 
                                   basemap_image='ESRI_Imagery_World_2D',
                                   cmap='seismic_r',
                                   plottitle='Skookum Creek watershed'+'\nPrecipitation in '+monthlabel.strftime('%B'),
                                   colorbar_label='Average monthly precipitation (meters)',
                                   outfilepath=os.path.join(homedir, outfile))

In [ ]:
comp = [['meanmonth_TMAX_dailymet_livneh2013','meanmonth_TMAX_dailywrf_salathe2014'],
        ['meanmonth_PRECIP_dailymet_livneh2013','meanmonth_PRECIP_dailywrf_salathe2014']]
wy_numbers=[10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9]
month_strings=[ 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']


fig = plt.figure(figsize=(20,5), dpi=500)

ax1 = plt.subplot2grid((2, 2), (0, 0), colspan=1)
ax2 = plt.subplot2grid((2, 2), (1, 0), colspan=1)


# monthly
for eachsumm in df_obj.columns:
    ax1.plot(df_obj[eachsumm])
    

ax1.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=2, fontsize=10)
plt.show()

In [ ]:
df_obj[each].index.apply(lambda x: x+2)

In [ ]:
fig, ax = plt.subplots()
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

lws=[3, 10, 3, 3]
styles=['b--','go-','y--','ro-']

for col, style, lw in zip(comp, styles, lws):
    panel_obj.xs(key=(minElevStation[0][0], minElevStation[0][1], minElevStation[0][2]), axis=2)[col].plot(style=style, lw=lw, ax=ax, legend=True)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=2)
fig.show()
    

    
    
fig, ax = plt.subplots()
lws=[3, 10, 3, 3]
styles=['b--','go-','y--','ro-']

for col, style, lw in zip(comp, styles, lws):
    panel_obj.xs(key=(maxElevStation[0][0], maxElevStation[0][1], maxElevStation[0][2]), 
                 axis=2)[col].plot(style=style, lw=lw, ax=ax, legend=True)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=2)
fig.show()

10. Save the results back into HydroShare

Using the hs_utils library, the results of the Geoprocessing steps above can be saved back into HydroShare. First, define all of the required metadata for resource creation, i.e. title, abstract, keywords, content files. In addition, we must define the type of resource that will be created, in this case genericresource.

Note: Make sure you save the notebook at this point, so that all notebook changes will be saved into the new HydroShare resource.


In [ ]:
#execute this cell to list the content of the directory
!ls -lt
!pwd
printdir = hs.getContentPath('e47aabb406bc45a28f34b97a832daa08')
printdir
os.chdir(printdir)
!pwd

In [ ]:
#monthlabel.strftime('%B')
filename_local='bcc-csm1-1-m__rcp45'+'_wrfbc'
filename_local_tar='bcc-csm1-1-m__rcp45'+'_wrfbc_tar'
print(filename_local)
print(filename_local_tar)
!tar -zcf {filename_local_tar} 'bcc-csm1-1-m__rcp45_wrfbc'

In [ ]:
for each in ['bcc-csm1-1-m__rcp45','CanESM2__rcp45','CSIRO-Mk3-6-0__rcp45','CCSM4__rcp45','CNRM-CM5__rcp45','HadGEM2-CC365__rcp45','HadGEM2-ES365__rcp45','IPSL-CM5A-MR__rcp45','NorESM1-M__rcp45','MIROC5__rcp45','bcc-csm1-1-m__rcp85','CanESM2__rcp85','CSIRO-Mk3-6-0__rcp85','CCSM4__rcp85','CNRM-CM5__rcp85','HadGEM2-CC365__rcp85','HadGEM2-ES365__rcp85','IPSL-CM5A-MR__rcp85','NorESM1-M__rcp85','MIROC5__rcp85']:
    filename_local=each+'_wrfbc'
    filename_global=each+'_wrfbc_global'
    filename_local_tar=each+'_wrfbc.tar'
    filename_global_tar=each+'_wrfbc_global.tar'
    !tar -zcf {filename_local_tar} {filename_local}
    !tar -zcf {filename_global_tar} {filename_global}

In [ ]:
for each in ['bcc-csm1-1-m','CanESM2','CSIRO-Mk3-6-0','CCSM4','CNRM-CM5','HadGEM2-CC365','HadGEM2-ES365','IPSL-CM5A-MR','NorESM1-M','MIROC5']:
    !mkdir {each}
    !cp {each}*.tar {each}
    !cp {each}*.tar.gz {each}
    filename_tar=each+'.tar'
    !tar -zcf {filename_tar} {each}

In [ ]:
ThisNotebook='Observatory_biascorrection_04192018_1828.ipynb' #check name for consistency
climate2013_tar = 'livneh2013.tar.gz'
climate2013_local ='biascorrWRF_liv.tar.gz'
climate2013_global = 'biascorrWRF_global.tar.gz'
wrf_tar = 'salathe2014.tar.gz'
mappingfile = 'Sauk_mappingfile.csv'
bcccsm11m_tar = 'bcc-csm1-1-m.tar'
CanESM2_tar='CanESM2.tar'
CSIROMk360_tar='CSIRO-Mk3-6-0.tar'
CCSM4_tar='CCSM4.tar'
CNRMCM5_tar='CNRM-CM5.tar'
HadGEM2CC365_tar='HadGEM2-CC365.tar'
HadGEM2ES365_tar='HadGEM2-ES365.tar'
IPSLCM5AMR_tar='IPSL-CM5A-MR.tar'
NorESM1M_tar='NorESM1-M.tar'
MIROC5_tar='MIROC5.tar'

files=[ThisNotebook, mappingfile, climate2013_tar, climate2013_local,climate2013_global , wrf_tar,bcccsm11m_tar,CanESM2_tar,CSIROMk360_tar,CCSM4_tar,CNRMCM5_tar,HadGEM2CC365_tar,HadGEM2ES365_tar,IPSLCM5AMR_tar,NorESM1M_tar,MIROC5_tar]

In [ ]:
# for each file downloaded onto the server folder, move to a new HydroShare Generic Resource
import os
from utilities import hydroshare
hs = hydroshare.hydroshare()
title = 'Skookum Hybrid Bias Correction using Livneh and WRF datasets'
abstract = 'This the output from the vias correction notebook. Results for historic and future models are included'
keywords = ['Skookum', 'climate', 'Landlab','hydromet','watershed'] 
rtype = 'genericresource'  

# create the new resource
resource_id = hs.createHydroShareResource(abstract, 
                                          title,
                                          keywords=keywords, 
                                          resource_type=rtype, 
                                          content_files=files, 
                                          public=False)

In [4]:
import types
def imports():
    for name, val in globals().items():
        if isinstance(val, types.ModuleType):
            yield val.__name__
list(imports())


Out[4]:
['builtins',
 'builtins',
 'os',
 'pandas',
 'numpy',
 'dask',
 'json',
 'utilities.hydroshare.hydroshare',
 'geopandas',
 'warnings',
 'copy',
 'ogh',
 'types']

In [5]:
import pkg_resources
import types
def get_imports():
    for name, val in globals().items():
        
        if isinstance(val, types.ModuleType):
            # Split ensures you get root package, 
            # not just imported function
            name = val.__name__.split(".")[0]

        elif isinstance(val, type):
            name = val.__module__.split(".")[0]

        # Some packages are weird and have different
        # imported names vs. system/pip names. Unfortunately,
        # there is no systematic way to get pip names from
        # a package's imported name. You'll have to had
        # exceptions to this list manually!
        poorly_named_packages = {
            "PIL": "Pillow",
            "sklearn": "scikit-learn"
        }
        if name in poorly_named_packages.keys():
            name = poorly_named_packages[name]

        yield name
imports = list(set(get_imports()))

# The only way I found to get the version of the root package
# from only the name of the package is to cross-check the name

In [11]:
ogh.__version__


Out[11]:
'0.1.6-alpha'

In [ ]:


In [ ]: