xarray
How do I... | Solution |
---|---|
add a DataArray to my dataset as a new variable | my_dataset[varname] = my_dataArray or :pyDataset.assign (see also dictionary_like_methods ) |
add variables from other datasets to my dataset | :pyDataset.merge |
add a new dimension and/or coordinate | :pyDataArray.expand_dims , :pyDataset.expand_dims |
add a new coordinate variable | :pyDataArray.assign_coords |
change a data variable to a coordinate variable | :pyDataset.set_coords |
change the order of dimensions | :pyDataArray.transpose , :pyDataset.transpose |
reshape dimensions | :pyDataArray.stack , :pyDataset.stack , :pyDataset.coarsen.construct , :pyDataArray.coarsen.construct |
remove a variable from my object | :pyDataset.drop_vars , :pyDataArray.drop_vars |
remove dimensions of length 1 or 0 | :pyDataArray.squeeze , :pyDataset.squeeze |
remove all variables with a particular dimension | :pyDataset.drop_dims |
convert non-dimension coordinates to data variables or remove them | :pyDataArray.reset_coords , :pyDataset.reset_coords |
rename a variable, dimension or coordinate | :pyDataset.rename , :pyDataArray.rename , :pyDataset.rename_vars , :pyDataset.rename_dims , |
convert a DataArray to Dataset or vice versa | :pyDataArray.to_dataset , :pyDataset.to_array , :pyDataset.to_stacked_array , :pyDataArray.to_unstacked_dataset |
extract variables that have certain attributes | :pyDataset.filter_by_attrs |
extract the underlying array (e.g. NumPy or Dask arrays) | :pyDataArray.data |
convert to and extract the underlying NumPy array | :pyDataArray.values |
convert to a pandas DataFrame | :pyDataset.to_dataframe |
sort values | :pyDataset.sortby |
find out if my xarray object is wrapping a Dask Array | :pydask.is_dask_collection |
know how much memory my object requires | :pyDataArray.nbytes , :pyDataset.nbytes |
Get axis number for a dimension | :pyDataArray.get_axis_num |
convert a possibly irregularly sampled timeseries to a regularly sampled timeseries | :pyDataArray.resample , :pyDataset.resample (see resampling for more) |
apply a function on all data variables in a Dataset | :pyDataset.map |
write xarray objects with complex values to a netCDF file | :pyDataset.to_netcdf , :pyDataArray.to_netcdf specifying engine="h5netcdf", invalid_netcdf=True |
make xarray objects look like other xarray objects | :py~xarray.ones_like , :py~xarray.zeros_like , :py~xarray.full_like , :pyDataset.reindex_like , :pyDataset.interp_like , :pyDataset.broadcast_like , :pyDataArray.reindex_like , :pyDataArray.interp_like , :pyDataArray.broadcast_like |
Make sure my datasets have values at the same coordinate locations | xr.align(dataset_1, dataset_2, join="exact") |
replace NaNs with other values | :pyDataset.fillna , :pyDataset.ffill , :pyDataset.bfill , :pyDataset.interpolate_na , :pyDataArray.fillna , :pyDataArray.ffill , :pyDataArray.bfill , :pyDataArray.interpolate_na |
extract the year, month, day or similar from a DataArray of time values | obj.dt.month for example where obj is a :py~xarray.DataArray containing datetime64 or cftime values. See dt_accessor for more. |
round off time values to a specified frequency | obj.dt.ceil , obj.dt.floor , obj.dt.round . See dt_accessor for more. |
make a mask that is True where an object contains any of the values in a array |
:pyDataset.isin , :pyDataArray.isin |
Index using a boolean mask | :pyDataset.query , :pyDataArray.query , :pyDataset.where , :pyDataArray.where |
preserve attrs during (most) xarray operations |
xr.set_options(keep_attrs=True) |