nsrdb.data_model.albedo.AlbedoVar
- class AlbedoVar(name, var_meta, date, **kwargs)[source]
Bases:
AncillaryVarHandler
Framework for Albedo data extraction.
- Parameters:
name (str) – NSRDB var name.
var_meta (str | pd.DataFrame | None) – CSV file or dataframe containing meta data for all NSRDB variables. Defaults to the NSRDB var meta csv in git repo.
date (datetime.date) – Single day to extract data for.
Methods
exclusions_from_nsrdb
(nsrdb_grid[, margin])Set lat/lon exclusions from NSRDB grid df to minimize data read.
Perform pre-flight checks - source file check.
scale_data
(array)Perform a safe data scaling operation on a source data array.
set_exclusions
([lat_in, lat_ex, lon_in, lon_ex])Set latitude/longitude inclusions/exclusions to minimize data read.
unscale_data
(array)Perform a safe data unscaling operation on a source data array.
Attributes
DEFAULT_DIR
NN_METHOD
Return a dictionary of dataset attributes for HDF5 dataset attrs.
Get the nearest neighbor result cache csv file for this var.
Get the variable's intended storage chunk shape.
Get the data source.
Get the date for this handler
Get the Albedo datestamp corresponding to the specified date
Long variable description.
Get the day of year string e.g. 001 for jan 1 and 365 for Dec 31.
Get the source dataset name for the NSRDB variable.
Get the data type attribute.
Get the elevation correction preference.
Get the file path for the target NSRDB variable name based on the glob self.pattern.
Get the source file set name for the NSRDB variable.
Get the variable's intended storage datatype.
Return the Albedo source coordinates.
Get a boolean mask to locate the current variable in the meta data.
Get the NSRDB variable name.
Get the date after the date for this handler.
Get the file path for the date for the target NSRDB variable name based on the glob self.next_pattern.
Check if file for next date exists
Get the next date source file pattern which is sent to glob().
Get the source file pattern which is sent to glob().
Get the variable's physical maximum value.
Get the variable's physical minimum value.
Get the variable's intended storage scale factor.
Get single day data from the Albedo source file.
Get the source directory containing the variable data files.
Get the spatial interpolation method.
Get the temporal interpolation method.
Get the albedo native time index.
Get the units attribute.
Return the meta data for NSRDB variables.
- property doy
Get the day of year string e.g. 001 for jan 1 and 365 for Dec 31
- Returns:
str
- property date_stamp
Get the Albedo datestamp corresponding to the specified date
- Returns:
date (str) – Date stamp that should be in the NSRDB Albedo file, format is YYYY_DDD where DDD is the one-indexed day of year.
- property pattern
Get the source file pattern which is sent to glob().
- Returns:
str
- pre_flight()[source]
Perform pre-flight checks - source file check.
- Returns:
missing (str) – Look for the source file and return the string if not found. If nothing is missing, return an empty string.
- exclusions_from_nsrdb(nsrdb_grid, margin=0.1)[source]
Set lat/lon exclusions from NSRDB grid df to minimize data read.
- Parameters:
nsrdb_grid (pd.DataFrame) – NSRDB grid dataframe (meta data) with latitude/longitude columns.
margin (float) – Decimal degree margin for exclusion.
- set_exclusions(lat_in=None, lat_ex=None, lon_in=None, lon_ex=None)[source]
Set latitude/longitude inclusions/exclusions to minimize data read.
Only one inclusion or exclusion is used for each latitude or longitude. The protected grid data attribute will be modified based on the inputs.
- Parameters:
lat_in (None | tuple) – Latitude range to include (everything OUTSIDE range is excluded).
lat_ex (None | tuple) – Latitude range to exclude (everything INSIDE range is excluded).
lon_in (None | tuple) – Longitude range to include (everything OUTSIDE range is excluded).
lon_ex (None | tuple) – Longitude range to exclude (everything INSIDE range is excluded).
- property time_index
Get the albedo native time index.
- Returns:
alb_ti (pd.DatetimeIndex) – Pandas datetime index for the current day at the albedo resolution (1-month).
- property source_data
Get single day data from the Albedo source file.
- Returns:
data (np.ndarray) – Flattened albedo data. Note that the data originates as a 2D spatially gridded numpy array with shape (lat x lon).
- property grid
Return the Albedo source coordinates.
- Returns:
self._albedo_grid (dict) – Albedo grid data. The albedo grid (from MODIS) is an ordered lat-lon grid so this dict has two entries ‘latitude’ and ‘longitude’ with 1D arrays for each.
- property attrs
Return a dictionary of dataset attributes for HDF5 dataset attrs.
- Returns:
attrs (dict) – Namespace of attributes to define the dataset.
- property cache_file
Get the nearest neighbor result cache csv file for this var.
- Returns:
_cache_file (False | str) – False for no caching, or a string filename (no path).
- property chunks
Get the variable’s intended storage chunk shape.
- Returns:
chunks (tuple) – Data storage chunk shape (row_chunk, col_chunk).
- property data_source
Get the data source.
- Returns:
data_source (str) – Data source.
- property date
Get the date for this handler
- Returns:
datetime.date
- property description
Long variable description.
- Returns:
description (str) – Description of the variable to provide more info than the sometimes opaque dset names.
- property dset_name
Get the source dataset name for the NSRDB variable. This is typically the netcdf or h5 source dataset name for the variable such as T2M or TOTANGSTR (for MERRA temp and alpha)
- Returns:
str
- property dtype
Get the data type attribute.
- Returns:
dtype (str) – Intended NSRDB disk data type.
- property elevation_correct
Get the elevation correction preference.
- Returns:
elevation_correct (bool) – Whether or not to use elevation correction for the current var.
- property file
Get the file path for the target NSRDB variable name based on the glob self.pattern.
- Returns:
str
- property file_set
Get the source file set name for the NSRDB variable. This is typically used for MERRA source filesets such as tavg1_2d_aer_Nx or tavg1_2d_slv_Nx (for MERRA)
- Returns:
str
- property final_dtype
Get the variable’s intended storage datatype.
- Returns:
dtype (str) – Data type for the current variable.
- property mask
Get a boolean mask to locate the current variable in the meta data.
- property name
Get the NSRDB variable name.
- property next_date
Get the date after the date for this handler. This is used to get the data for the next date for temporal interpolation
- Returns:
datetime.date
- property next_file
Get the file path for the date for the target NSRDB variable name based on the glob self.next_pattern. The file is used to get the data for the next date for temporal interpolation
- Returns:
str
- property next_file_exists
Check if file for next date exists
- property next_pattern
Get the next date source file pattern which is sent to glob().
- Returns:
str | None
- property physical_max
Get the variable’s physical maximum value.
- Returns:
physical_max (float) – Physical maximum value for the variable. Variable range can be truncated at this value. Must be consistent with the final dtype and scale factor.
- property physical_min
Get the variable’s physical minimum value.
- Returns:
physical_min (float) – Physical minimum value for the variable. Variable range can be truncated at this value. Must be consistent with the final dtype and scale factor.
- scale_data(array)
Perform a safe data scaling operation on a source data array.
- Steps:
Enforce physical range limits
Apply scale factor (mulitply)
Round if integer
Enforce dtype bit range limits
Perform dtype conversion
Return manipulated array
- Parameters:
array (np.ndarray) – Source data array with full precision (likely float32).
- Returns:
array (np.ndarray) – Source data array with final datatype.
- property scale_factor
Get the variable’s intended storage scale factor.
- Returns:
scale_factor (float) – Scale factor for the current variable. Data is multiplied by this scale factor before being stored.
- property source_dir
Get the source directory containing the variable data files.
- Returns:
source_dir (str) – Directory containing source data files (with possible sub folders).
- property spatial_method
Get the spatial interpolation method.
- Returns:
spatial_method (str) – NN or IDW
- property temporal_method
Get the temporal interpolation method.
- Returns:
temporal_method (str) – linear or nearest
- property units
Get the units attribute.
- Returns:
units (str) – NSRDB variable units.
- unscale_data(array)
Perform a safe data unscaling operation on a source data array.
- Parameters:
array (np.ndarray) – Scaled source data array with integer precision.
- Returns:
array (np.ndarray) – Unscaled source data array with float32 precision.
- property var_meta
Return the meta data for NSRDB variables.
- Returns:
_var_meta (pd.DataFrame) – Meta data for NSRDB variables.