<jupyter_start><jupyter_text>NREL Resource Extraction Tool (NREL-rex) This notebook demonstrates data slicing for the National Renewable Energy Laboratory (NREL) National Solar Radiation Database (NSRDB) data. The data is provided from Amazon Web Services using the HDF Group's Highly Scalable Data Service (HSDS). These slicing methods would also work with the WIND Toolkit data available via HSDS at /nrel/wtk/For this to work you must first install h5pyd:```pip install --user h5pyd```Next you'll need to configure HSDS:```hsconfigure```and enter at the prompt:```hs_endpoint = https://developer.nrel.gov/api/hsdshs_username = Nonehs_password = <PASSWORD>hs_api_key = <KEY>```*The example API key here is for demonstation and is rate-limited per IP. To get your own API key, visit https://developer.nrel.gov/signup/*You can also add the above contents to a configuration file at ~/.hscfgThis example will also be using NREL's Resource Extraction Tools package [`NREL-rex`](https://github.com/nrel/rex) which can be installed with pip:```pip install NREL-rex```or with conda:```conda install nrel-rex```<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import sys
from rex import NSRDBX, WindX<jupyter_output><empty_output><jupyter_text>NSRSBX<jupyter_code>nsrdb_file = '/nrel/nsrdb/v3/nsrdb_2018.h5'
# NSRDBX is a wrapper on h5py and h5pyd that simplifies extraction of NSRDB data
# It automatically converts the meta data to a pandas DataFrame
# The time_index to a pandas DatatimeIndex
# And unscales NSRDB datasets
# NOTE: the syntax for extracting datasets is different from h5py/h5pyd!!

with NSRDBX(nsrdb_file, hsds=True) as f:
    meta = f.meta
    display(meta.head())
    time_index = f.time_index
    display(time_index)
    dni = f['dni', fc00:e968:6179::de52:7100, :10]

dni.shape
# NSRDBX also allows easy extraction of the nearest site to a desired (lat, lon) location:
coords = (39.741931, -105.169891)
with NSRDBX(nsrdb_file, hsds=True) as f:
    coords_df = f.get_lat_lon_df('dni', coords)
sns.lineplot(x="time_index", y="dni", data=coords_df.reset_index())
plt.show()
# NSRDBX can also filter on differnt meta data columns
region = 'Colorado'
with NSRDBX(nsrdb_file, hsds=True) as f:
    date = '2018-07-04 18:00:00'
    dni_map = f.get_timestep_map('dni', date, region=region,
                                 region_col='state')
dni_map.plot.scatter(x='longitude', y='latitude', c='dni', colormap='YlOrRd')
plt.show()
# NSRDBX can also extract the variables need for SAM
nrel = (39.741931, -105.169891)
with NSRDBX(nsrdb_file, hsds=True) as f:
    nrel_sam_vars = f.get_SAM_lat_lon(nrel)
nrel_sam_vars<jupyter_output><empty_output><jupyter_text>WindX<jupyter_code>wtk_file = '/nrel/wtk/conus/wtk_conus_2014.h5'
# WindX is a wrapper on h5py and h5pyd that simplifies extraction of WIND Toolkit data
# It automatically converts the meta data to a pandas DataFrame
# The time_index to a pandas DatatimeIndex
# And unscales WIND Toolkit datasets
# NOTE: the syntax for extracting datasets is different from h5py/h5pyd!!
with WindX(wtk_file, hsds=True) as f:
    meta = f.meta
    display(meta.head())
    time_index = f.time_index
    display(time_index)
    wspd = f['windspeed_100m', :, :10]

wspd.shape
# WindX will automatically interpolate between hub-heights
with WindX(wtk_file, hsds=True) as f:
    display([ds for ds in f.datasets if ds.startswith('windspeed')]) # Available wind speed heights
    wspd = f['windspeed_90m', :, :10] # 90m windspeed was interpolated from 80m and 100m

wspd.shape
# WindX also allows easy extraction of the nearest site to a desired (lat, lon) location:
coords = (39.741931, -105.169891)
with WindX(wtk_file, hsds=True) as f:
    coords_df = f.get_lat_lon_df('windspeed_100m', coords)
sns.lineplot(x="time_index", y="windspeed_100m", data=coords_df.reset_index())
plt.show()
# WindX can also filter on differnt meta data columns
region = 'Colorado'
with WindX(wtk_file, hsds=True) as f:
    date = '2014-07-04 18:00:00'
    wspd_map = f.get_timestep_map('windspeed_100m', date, region=region,
                                  region_col='state')
wspd_map.plot.scatter(x='longitude', y='latitude', c='windspeed_100m', colormap='PuBuGn')
plt.show()
# WindX can also extract the variables need for SAM
nwtc = (39.913561, -105.222422)
with WindX(wtk_file, hsds=True) as f:
    nrel_sam_vars = f.get_SAM_lat_lon(100, nwtc)
nrel_sam_vars<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10406937958639093, 'fraction_numerical': 0.03669112741827885, 'mean_word_length': 4.879738562091504, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '629875', 'license': 'FSFAP', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1598, 'n_words': 475, 'path': 'notebooks/08_NREL-rex.ipynb', 'repo_name': 'lkilcher/hsds-examples', 'size': '4504'}