nsrdb.tmy.tmy.Tmy

class Tmy(nsrdb_base_fp, years, weights, site_slice=None, supplemental_fp=None)[source]

Bases: object

NSRDB Typical Meteorological Year (TMY) calculation framework.

Parameters:
  • nsrdb_base_fp (str) – Base nsrdb filepath to retrieve annual files from. Must include a single {} format option for the year. Can include * for an NSRDB multi file source.

  • years (iterable) – Iterable of years to include in the TMY calculation.

  • weights (dict) – Lookup of {dset: weight} where dset is a variable h5 dset name and weight is a fractional TMY weighting. All weights must sum to 1.0

  • site_slice (slice) – Sites to consider in this TMY.

  • supplemental_fp (None | dict) – Supplemental data base filepaths including {} for year for uncommon dataset inputs to the TMY calculation. For example: {‘poa’: ‘/projects/pxs/poa_h5_dir/poa_out_{}.h5’}

Methods

calculate_tmy_years()

Calculate the TMY based on the multiple-dataset weights.

get_tmy_timeseries(dset[, unscale])

Get a complete TMY timeseries of data for dset.

get_weighted_fs()

Get the FS metric for all datasets and weight and combine.

persistence_filter(tmy_years_5)

Use persistence of extreme mean temp and daily ghi to filter tmy.

select_fs_years(fs_all[, n])

Select 5 best TMY years for each month based on the FS statistic

sort_years_mm(tmy_years_5)

Sort candidate TMY months/years based on deviation from the multi-year mean and median GHI.

Attributes

daily_mean_temp

Daily mean temperature multi-year timeseries.

daily_time_masks

Get a daily time index mask lookup dict.

daily_total_ghi

Daily GHI multi-year timeseries.

meta

Get the meta data from the current site slice.

my_daily_time_index

Full multi-year time index.

my_time_index

Full multi-year time index.

source_freq

Get the nsrdb source temporal frequency.

time_index

Time index for last TMY year without leap day.

time_masks

Get a time index mask lookup dict.

tmy_years_long

Get a long 8760 array of selected TMY years.

tmy_years_short

Get a short montly array of selected TMY years.

years

Get the list of years included in this multi-year cdf.

property daily_total_ghi

Daily GHI multi-year timeseries.

Returns:

_d_total_ghi (np.ndarray) – Multi-year timeseries of daily total GHI.

property daily_mean_temp

Daily mean temperature multi-year timeseries.

Returns:

_d_mean_temp (np.ndarray) – Multi-year timeseries of daily mean temperature.

property my_time_index

Full multi-year time index.

Returns:

my_time_index (pd.Datetimeindex) – Multi-year datetime index corresponding to multi-year data arrays.

property my_daily_time_index

Full multi-year time index.

Returns:

my_time_index (pd.Datetimeindex) – Multi-year datetime index corresponding to multi-year data arrays.

property time_index

Time index for last TMY year without leap day.

Returns:

time_index (pd.Datetimeindex) – Single-year datetime index corresponding to TMY output.

property tmy_years_short

Get a short montly array of selected TMY years.

Returns:

tmy_years_short (np.ndarray) – Array of best TMY years for every month for every site. Shape is (months, sites).

property tmy_years_long

Get a long 8760 array of selected TMY years.

Returns:

tmy_years_long (np.ndarray) – Array of best TMY years for every month for every site. Shape is (8760, sites).

property time_masks

Get a time index mask lookup dict.

Returns:

masks (dict) – Lookup of boolean masks keyed by month and year integer.

property daily_time_masks

Get a daily time index mask lookup dict.

Returns:

masks (dict) – Lookup of boolean masks for a daily timeseries keyed by month and year integer.

property meta

Get the meta data from the current site slice.

Returns:

meta (pd.DataFrame) – Meta data from the current site slice.

property years

Get the list of years included in this multi-year cdf.

Returns:

years (list) – List of years included in this cdf analysis.

property source_freq

Get the nsrdb source temporal frequency.

Returns:

freq (str) – Pandas datetimeindex frequency string (‘30min’, ‘1h’).

get_weighted_fs()[source]

Get the FS metric for all datasets and weight and combine.

This is part of STEP #1 of the NSRDB TMY.

Returns:

ws (dict) – Dictionary with month keys. Each dict value is a (y, n) array where y is years and n is sites. Each array entry is the summed and weighted FS metric for all datasets in self._weights.

select_fs_years(fs_all, n=5)[source]

Select 5 best TMY years for each month based on the FS statistic

This is part of STEP #1 of the NSRDB TMY.

Parameters:
  • fs_all (dict) – Dictionary with month keys. Each dict value is a (y, n) array where y is years and n is sites. Each array entry is the FS metric.

  • year0 (int | str) – Initial year of the TMY.

  • n (int) – Number of years to select.

Returns:

  • years (dict) – Month-keyed dictionary of arrays of best TMY years for every month for every site. Shape is (n, sites).

  • fs (dict) – Month-keyed dictionary of arrays of min FS statistic for each month for every site corresponding to the 5 years selected. Shape is (n, sites).

sort_years_mm(tmy_years_5)[source]

Sort candidate TMY months/years based on deviation from the multi-year mean and median GHI.

This is STEP #2 of the NSRDB TMY.

Parameters:

tmy_years_5 (dict) – Month-keyed dictionary of arrays of best 5 TMY years for every month for every site. Shape is (5, sites).

Returns:

  • tmy_years_5 (dict) – Month-keyed dictionary of arrays of best 5 TMY years for every month for every site SORTED BY deviation from the multi-year monthly mean and median GHI values.

  • diffs (dict) – Month-keyed dictionary of arrays of shape (n_tmy_years, n_sites) differences for every year

persistence_filter(tmy_years_5)[source]

Use persistence of extreme mean temp and daily ghi to filter tmy.

This is STEP #3 of the NSRDB TMY.

Parameters:

tmy_years_5 (dict) – Month-keyed dictionary of arrays of sorted best 5 TMY years for every month for every site. Shape is (5, sites).

Returns:

  • tmy_years (np.ndarray) – Array of best TMY years for every month for every site. Shape is (months, sites).

  • max_run_len (dict) – Nested dictionary (max_run_len[month][site][tmy_year_index]) of maximum length of a consecutive run.

  • n_runs (dict) – Nested dictionary (max_run_len[month][site][tmy_year_index]) Number of consecutive runs.

calculate_tmy_years()[source]

Calculate the TMY based on the multiple-dataset weights.

Returns:

tmy_years (np.ndarray) – Array of best TMY years for every month for every site. Shape is (months, sites).

get_tmy_timeseries(dset, unscale=True)[source]

Get a complete TMY timeseries of data for dset.

Parameters:
  • dset (str) – Name of the dataset to get data for.

  • unscale (bool) – Flag to unscale data from dset storage dtype to physical dtype. As of 2018, the NSRDB has inconsistent scale factors so unscaling to physical units is onorous but necessary.

Returns:

data (np.ndarray) – (8760 x n_sites) timeseries array of dset with data in each month taken from the selected tmy_year.