Hi,
Most likely I am overlooking something obvious, but I cannot figure out what.
I am working with this dataset and have calculated averages over NUTS regions. This is how my data array now looks like:
<xarray.DataArray 'number_of_days' (nuts: 37, time: 100)> dask.array<xarray-number_of_days, shape=(37, 100), dtype=float32, chunksize=(37, 48), chunktype=numpy.ndarray> Coordinates: height float64 ... * time (time) datetime64[ns] 1986-01-01 1987-01-01 ... 2085-01-01 * nuts (nuts) object 'ES' 'FI' 'IS' 'FR' 'HR' ... 'ME' 'MK' 'MT' 'NL' 'NO' Attributes: ...
So far, so good.
Next I want to select a single year. I want to get rid of the time dimension because otherwise I end up with a time slider in my live map, which I don't want. So I thought I could use ct.cube.select(...) but no matter what I try, the time dimension persists even if I use the keyword drop=True
:
darray_sub = ct.cube.select(darray,time='1987', drop=True) <xarray.DataArray 'number_of_days' (nuts: 37, time: 1)> dask.array<xarray-number_of_days, shape=(37, 1), dtype=float32, chunksize=(37, 1), chunktype=numpy.ndarray> Coordinates: height float64 ... * nuts (nuts) object 'ES' 'FI' 'IS' 'FR' 'HR' ... 'ME' 'MK' 'MT' 'NL' 'NO' Dimensions without coordinates: time Attributes: units: day long_name: Ensemble members average of VBD season_len... type: real valid_min: 0.0 conventions: CF-1.6 _cds_toolbox_aux_wms_layer: nuts:nuts__level_0__resolution_medium__yea... _cds_toolbox_aux_wms_fids: [] _cds_toolbox_aux_wms_filters: {} _cds_toolbox_wms_attr_map: nuts:NUTS_ID
However, if I use ct.cube.index_select(...) the time dimension disappears even if I add the keyword drop=False
:
darray_sub = ct.cube.index_select(darray,time=0,drop=False) <xarray.DataArray 'number_of_days' (nuts: 37)> array([ 98.37596 , 0.442497, 20.3601 , 143.63914 , 94.37917 , 42.43064 , 102.53675 , 25.354486, 130.1956 , 46.885483, 45.356785, 75.993004, 26.926882, 82.430275, 72.13661 , 7.306597, 100.75709 , 152.26291 , 34.79379 , 154.937 , 21.72802 , 51.965862, 5.821461, 59.158653, 12.273589, 63.25718 , 131.57185 , 117.382095, 16.603952, 13.528408, 107.88156 , 12.062992, 44.698086, 26.043186, 41.21859 , 123.48304 , 6.420299], dtype=float32) Coordinates: height float64 ... time datetime64[ns] ... * nuts (nuts) object 'ES' 'FI' 'IS' 'FR' 'HR' ... 'ME' 'MK' 'MT' 'NL' 'NO' Attributes: units: day long_name: Ensemble members average of VBD season_len... type: real valid_min: 0.0 conventions: CF-1.6 _cds_toolbox_aux_wms_layer: nuts:nuts__level_0__resolution_medium__yea... _cds_toolbox_aux_wms_fids: [] _cds_toolbox_aux_wms_filters: {} _cds_toolbox_wms_attr_map: nuts:NUTS_ID
Although I could, of course, just use the index_select(...) method, I'm somewhat confused by the fact that in neither case adding drop=True
or drop=False
seems to make any difference at all. Why is that?
Also, I would have to work out the correct index myself which is more prone to error Is there an alternative way of getting rid of the time dimension of length 1, similar to xarray's squeeze method?
Thanks!
Rutger
1 Comment
Vivien MAVEL
Dear Rutger,
The drop option in ct.cube.select and ct.cube.index_select only drops the coordinates associated to the dimension not the dimension itself.
As far as I am aware if you really need to drop the dimension you need to use ct.cube.index_select. The index should not be an issue if you have a singleton dimension.
Regards.
Vivien