1 clim_recal.data_loader
clim_recal.data_loader
1.1 Functions
Name | Description |
---|---|
clip_dataset | Spatially clip xa (a DataArray ) variable via shapefile . |
load_and_merge | Load files into xarrays, select a time range and a variable and merge into a sigle xarray. |
load_data | This function takes a date range and a variable and loads and merges |
reformat_file | Load tif file and reformat xarray into expected format. |
1.1.1 clip_dataset
clim_recal.data_loader.clip_dataset(xa, variable, shapefile)
Spatially clip xa
(a DataArray
) variable via shapefile
.
1.1.1.1 Parameters
Name | Type | Description | Default |
---|---|---|---|
xa |
DataArray | xArray containing a given variable (e.g. rainfall) | required |
variable |
str | A string representing the variable to be loaded | required |
shapefile |
str | Path to a shape file used to clip resulting dataset, must be in the same CRS of the input xArray. | required |
1.1.1.2 Returns
Type | Description |
---|---|
DataArray | A clipped xarray dataset |
1.1.1.3 Examples
1.1.2 load_and_merge
clim_recal.data_loader.load_and_merge(date_range, files, variable, write_crs_format=BRITISH_NATIONAL_GRID_EPSG)
Load files into xarrays, select a time range and a variable and merge into a sigle xarray.
1.1.2.1 Parameters
Name | Type | Description | Default |
---|---|---|---|
date_range |
DateRange | A tuple of datetime objects representing the start and end date | required |
files |
list[str] | List of strings with path to files to be loaded. | required |
variable |
str | A string representing the variable to be loaded | required |
1.1.2.2 Returns
Type | Description |
---|---|
DataArray | An xarray containing all loaded and merged data |
1.1.3 load_data
clim_recal.data_loader.load_data(input_path, date_range, variable, filter_filenames_on_variable=False, run_number=None, filter_filenames_on_run_number=False, use_pr=False, shapefile_path=None, extension='nc')
This function takes a date range and a variable and loads and merges xarrays based on those parameters.
If shapefile is provided it crops the data to that region.
1.1.3.1 Parameters
Name | Type | Description | Default |
---|---|---|---|
input_path |
str | Path to where .nc or .tif files are found | required |
date_range |
DateRange | A tuple of datetime objects representing the start and end date | required |
variable |
str | A string representing the variable to be loaded | required |
filter_filenames_on_variable |
bool | When True, files in the input_path will be filtered based on whether their file name contains “variable” as a substring. When False, filtering does not happen. | False |
run_number |
str | None | A string representing the CPM run number to use (out of 13 CPM runs available in the database). Only files whose file name contains the substring run_number will be used. If None , all files in input_path are parsed, regardless of run number in filename. |
None |
filter_filenames_on_run_number |
bool | When True, files in the input_path will be filtered based on whether their file name contains “2.2km_” followed by “run_number”. When False, filtering does not happen. This should only be used for CPM files. For HADs files this should always be set to False. | False |
use_pr |
bool | If True, replace variable with “pr” string when filtering the file names. | False |
shapefile_path |
str | None | Path to a shape file used to clip resulting dataset. | None |
extension |
str | Extension of the files to be loaded, it can be .nc or .tif files. | 'nc' |
1.1.3.2 Returns
Type | Description |
---|---|
DataArray | A DataArray containing all loaded and merged and clipped data |
1.1.4 reformat_file
clim_recal.data_loader.reformat_file(file, variable, spatial_config=BRITISH_NATIONAL_GRID_EPSG)
Load tif file and reformat xarray into expected format.
1.1.4.1 Parameters
Name | Type | Description | Default |
---|---|---|---|
file |
str | Path as a str to tiff file. |
required |
variable |
str | A string representing the variable to be loaded. | required |
spatial_config |
str | Spatial coordinate configuration for export. | BRITISH_NATIONAL_GRID_EPSG |
1.1.4.2 Returns
Type | Description |
---|---|
DataArray | A formatted xarray |