python-xarray

Update raster values using Python

Update raster values using Python Question: I’m trying to read in a raster file. It’s a 32-bit float raster, with either values 1 or no data. I want to update the values of 1 to 10, and write it out again (probably as a UNIT8 data type?). Here is my attempt: import rioxarray import numpy …

Total answers: 1

printing the uploading progress using `xarray.Dataset.to_zarr` function

printing the uploading progress using `xarray.Dataset.to_zarr` function Question: I’m trying to upload an xarray dataset to GCP using the function ds.to_zarr(store=store), and it works perfect. However, I would like to show the progress of big datasets. Is there any option to chunk my dataset in a way I can use tqdm or someting like that …

Total answers: 1

How do I create a Data Variable in an xarray.DataArray?

How do I create a Data Variable in an xarray.DataArray? Question: How do I assign data to or create a ‘Data Variable’ in a xarray.DataArray or finally in the nc-file when saving the DataArray? When creating the xarray.DataArray, it simply stores the data as an array but not as a ‘Data Variable’ as one is …

Total answers: 2

Merging several variables of an xarray.Dataset into one using a new dimension

Merging several variables of an xarray.Dataset into one using a new dimension Question: I have a Dataset with several variables that named something like t1, t2, t3, etc. I’m looking for a simple function to merge them all into one variable t through the use an extra dimension. Basically I want the output that I’m …

Total answers: 1

xarray dataset extract values select

xarray dataset extract values select Question: I have a xarray dataset from which I would like to extract points based on their coordinates. When sel is used for two coordinates it returns a 2D array. Sometimes this is what I want and it is the intended behavior, but I would like to extract a line …

Total answers: 1

plot data interactive as rgb

plot data interactive as rgb Question: I have a bunch of pictures I’d like to plot with hvplot.rgb. The user should be able to switch between the pictures with a widget like a slider. My problem is, that i don’t know how to use the hvplot.rgb()-function for interactive dataframes. here’s what i have so far: …

Total answers: 1

Trouble plotting quivers from netcdf file

Trouble plotting quivers from netcdf file Question: I am trying to plot wind quivers from a NetCDF file, however, I can only plot one line of quivers, straight across the base map, as seen in the image. The code is below. Thank you very much for any help 🙂 data is here, please replace with …

Total answers: 1

How to add a constant to negative values in array

How to add a constant to negative values in array Question: Given the xarray below, I would like to add 10 to all negative values (i.e, -5 becomes 5, -4 becomes 6 … -1 becomes 9, all values remain unchanged). a = xr.DataArray(np.arange(25).reshape(5, 5)-5, dims=("x", "y")) I tried: a[a<0]=10+a[a<0], but it returns 2-dimensional boolean indexing …

Total answers: 2

How to replace 'for' loop by 'xarray.apply_ufunc' to performing linear regression between "x" and "y" for a 11-day moving-window for a xr.Dataset?

How to replace 'for' loop by 'xarray.apply_ufunc' to performing linear regression between "x" and "y" for a 11-day moving-window for a xr.Dataset? Question: Estimate the linear slope between ‘x’ and ‘y’ for each 11-day moving window by 1-day stride. from sklearn import linear_model import numpy as np import xarray as xr import pandas as pd …

Total answers: 2

Xarray clip or mask dataset with another dataset

Xarray clip or mask dataset with another dataset Question: Goal: Replace values of a dataset by NaNs if the values of another, smaller dataset, are non-nan. Context: I have 1 netcdf file (DEM) that covers a large area. I have another netcdf file (BED) that covers a smaller area included in the bigger dataset. I …

Total answers: 1