Dataset¶
- class spy4cast.dataset.Dataset(name: str, folder: str = '.', chunks: Any | None = None)¶
Bases:
objectThis class enables you to load, slice and save the data in a netcdf4 file confortably.
It is concatenable, meaning that the output of most methods is the object itself so that you can concatenate methods easily.
- Parameters:
name (str, default='') – Directory where the dataset you want to use is located
folder (str, default='dataset.nc') – Name of the dataset
chunks (xarray.core.types.T_Chunks, optional) – Argument passed when loading the datasets (see chunks in dask library)
Example
>>> Dataset( ... 'example.nc', 'data/' ... ).open('var').slice( ... Region(-20, 20, -10, 0, Month.JAN, Month.FEB, 1870, 2000) ... ).save_nc('data-sliced.nc')
Attributes Summary
Returns the data contained
Returns the latitude variable of the data evaluated.
Returns the latitude variable of the data evaluated.
Returns the actual region of the data
Returns the shape variable of the data evaluated.
Returns the time variable of the data evaluated.
Initial timestamp of the data
Final timestamp of the data
Return the variable used.
Methods Summary
from_xrarray(array)Create a dataset from a xarray
open([var, region])Opens dataset without loading it into memory
save_nc(name[, folder])Saves the data as a netcdf4 file
slice(region[, skip])Method that slices the dataset accorging to a Region.
Attributes Documentation
- data¶
Returns the data contained
- lat¶
Returns the latitude variable of the data evaluated. They key used is recognised automatically
- lon¶
Returns the latitude variable of the data evaluated. They key used is recognised automatically
- region¶
Returns the actual region of the data
- shape¶
Returns the shape variable of the data evaluated.
- time¶
Returns the time variable of the data evaluated. They key used is recognised automatically
- timestamp0¶
Initial timestamp of the data
- timestampf¶
Final timestamp of the data
- var¶
Return the variable used.
- Raises:
ValueError – If the dataset has not been opened yet
Methods Documentation
- open(var: str | None = None, region: Region | None = None) _T¶
Opens dataset without loading it into memory
Warning
If the dataset says that the dataset starts from a year smaller than 1678 (minimum for pandas), it will be loaded with initial year = 2000
- Parameters:
var (optional, str) – Variable that can be specified. If not it is detected automatically
region (optional, Region) – Fill in this field the dataset is already sliced and you want to specify a certain region
- Raises:
errors.DatasetError – If there is an error while opening the dataset
errors.DatasetNotFoundError – If the dataset name or folder is not valid
errors.VariableSelectionError – If teh variable selected does not exist or can not be inferred
- save_nc(name: str, folder: str = '.') _T¶
Saves the data as a netcdf4 file
- slice(region: Region, skip: int = 0) _T¶
Method that slices the dataset accorging to a Region.
- Parameters:
region (spy4cast.stypes.Region) – spy4cast.stypes.Region to use
skip (int) – Amount of points to skip in the matrix
Note
It first calls check_region method
Note
If the season contains months from different years (NOV-DEC-JAN-FEB for example) the initial year is applied to the month which comes at last (FEB). In this example, the data that will be used for NOV is on year before the initial year so keep this in mind if your dataset doesn’t contain that specific year.
See also
stypes.Region