Dataset Slicing
annual_mean(ds, n_year_days=360, first_day=1)
Returns dataset ds
with variables being the average over all years i.e. time dimension of ds
will now be from
0.5 to 359.5 if a year has 360 days.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
Dataset for particular experiment. |
required |
n_year_days
|
int
|
Number of days in a year used for the simulation.
This depends on the |
360
|
first_day
|
int
|
Day used in starting date for the simulation.
It is equal to the third number in the |
1
|
Returns:
Type | Description |
---|---|
Dataset
|
Dataset containing the annual average of each variable |
Source code in isca_tools/utils/ds_slicing.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
annual_time_slice(ds, include_months=None, include_days=None, month_days=30, year_months=12, first_day=1)
Slices dataset ds
so only contains data corresponding to given months or days for each year.
Examples:
ds_summer = annual_time_slice(ds, [6, 7, 8])
This return a dataset containing data corresponding to
June, July and August in each year i.e. only northern hemisphere summer.
ds_day = annual_time_slice(ds, include_days = [36])
This will return a dataset containing data corresponding to the 36th day of the year for each year
of the simulation. The length of the time dimension will be the number of years of the simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
Dataset for particular experiment. |
required |
include_months
|
Optional[List[int]]
|
|
None
|
include_days
|
Optional[List[int]]
|
|
None
|
month_days
|
int
|
Number of days in each month used for the simulation.
This depends on the |
30
|
year_months
|
int
|
Number of months in a year. I think this is always likely to be |
12
|
first_day
|
int
|
Day used in starting date for the simulation.
It is equal to the third number in the |
1
|
Returns:
Type | Description |
---|---|
Dataset
|
Dataset only including certain months/days for each year. |
Source code in isca_tools/utils/ds_slicing.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
anom_from_annual_mean(ds, combine_lon=False, n_year_days=360, first_day=1)
For each lat, lon and pressure; this computes the annual mean of each variable. It then subtracts it from the initial dataset, to give the anomaly relative to the annual mean value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
Dataset for particular experiment. |
required |
combine_lon
|
bool
|
If |
False
|
n_year_days
|
int
|
Number of days in a year used for the simulation.
This depends on the |
360
|
first_day
|
int
|
Day used in starting date for the simulation.
It is equal to the third number in the |
1
|
Returns:
Type | Description |
---|---|
Dataset
|
Dataset with same |
Dataset
|
annual average. |
Source code in isca_tools/utils/ds_slicing.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
area_weight_mean_lat(ds)
For all variables in ds
, an area weighted mean is taken over all latitudes in the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
Dataset for particular experiment. |
required |
Returns:
Type | Description |
---|---|
Dataset
|
Dataset containing averaged variables with no latitude dependence. |
Source code in isca_tools/utils/ds_slicing.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
lat_lon_coord_slice(ds, lat, lon)
Returns dataset, ds
, keeping only data at the coordinate indicated by (lat[i], lon[i])
for all i
.
If ds
contained t_surf
then the returned dataset would contain t_surf
as a function of the variables
time
and location
with each value of location
corresponding to a specific (lat, lon)
combination.
For the original ds
, it would be a function of time
, lat
and lon
.
This is inspired from a stack overflow post.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
Dataset for particular experiment. |
required |
lat
|
ndarray
|
|
required |
lon
|
ndarray
|
|
required |
Returns:
Type | Description |
---|---|
Dataset
|
Dataset only including the desired coordinates. |
Source code in isca_tools/utils/ds_slicing.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
lat_lon_range_slice(ds, lat_min=None, lat_max=None, lon_min=None, lon_max=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Union[Dataset, DataArray]
|
|
required |
lat_min
|
Optional[float]
|
|
None
|
lat_max
|
Optional[float]
|
|
None
|
lon_min
|
Optional[float]
|
|
None
|
lon_max
|
Optional[float]
|
|
None
|
Returns:
Source code in isca_tools/utils/ds_slicing.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
lat_lon_rolling(ds, window_lat, window_lon)
This creates a rolling averaged version of the dataset or data-array in the spatial dimension.
Returned data will have first np.ceil((window_lat-1)/2)
and last np.floor((window_lat-1)/2)
values as nan
in latitude dimension.
The averaging also does not take account of area weighting in latitude dimension.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Union[Dataset, DataArray]
|
Dataset or DataArray to find rolling mean of. |
required |
window_lat
|
int
|
Size of window for rolling average in latitude dimension [number of grid points] |
required |
window_lon
|
int
|
Size of window for rolling average in longitude dimension [number of grid points]. |
required |
Returns:
Type | Description |
---|---|
Union[Dataset, DataArray]
|
Rolling averaged dataset or DataArray. |
Source code in isca_tools/utils/ds_slicing.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
time_rolling(ds, window_time, wrap=True)
This creates a rolling averaged version of the dataset or data-array in the time dimension. Useful for when have annual average dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Union[Dataset, DataArray]
|
Dataset or DataArray to find rolling mean of. |
required |
window_time
|
int
|
Size of window for rolling average in time dimension [number of time units e.g. days] |
required |
wrap
|
bool
|
If first time comes immediately after last time i.e. for annual mean data |
True
|
Returns:
Type | Description |
---|---|
Union[Dataset, DataArray]
|
Rolling averaged dataset or DataArray. |
Source code in isca_tools/utils/ds_slicing.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|