Questions tagged [xarray]

xarray is a Python module for working with N-dimensional arrays

Filter by
Sorted by
Tagged with
1 vote
1 answer
23 views

Increase map size with subplots and Cartopy

I try to make subplot maps with Cartopy using data from xarray tutorial and increase each map in vertical size, but failed. Also making colorbar at each specific subplots. import matplotlib.pyplot as ...
user avatar
  • 171
2 votes
0 answers
16 views

Unable to convert Sentinel-5P NetCDF file to GeoTIFF using xarray python

I am trying to convert Sentinel-5P NetCDF file (available at https://drive.google.com/file/d/1zw8kSPZPRIu_YDxixIlOByPCY19GNMbz/view?usp=sharing) to GeoTIFF using the following code: import xarray ...
user avatar
  • 556
0 votes
1 answer
34 views

Why do rioxarray reprojection and pyproj transform give different values when selecting a pixel by point coordinates?

I'm opening this grib file using rioxarray and reprojecting to WGS84 in the following manner with the goal of grabbing pixel values by coordinates. import rioxarray url = 'https://noaa-hrrr-bdp-pds....
user avatar
  • 433
0 votes
1 answer
25 views

Add projection to rioxarray dataset in Python

I've downloaded a netcdf from the Climate Data Store and would like to write a CRS to it, so I can clip it for a shapefile. However, I get an error when assigning a CRS. Below my script and what is ...
user avatar
  • 111
0 votes
1 answer
31 views

How to stack list of Xarrays

I have a folder with 4 .tiff (GeoTiff) files. Each of these contains two layers (the spectral band and a mask). I'm able to create a list containig each image using xarray.open_rasterio. Now I need to ...
user avatar
  • 343
1 vote
1 answer
75 views

Error trying to open NetCDF file with xarray from s3 bucket

I'm trying to open a .nc file from an S3 bucket using xarray, but I'm getting an error. Here's the method I'm using: import xarray as xr aws_url = 's3://nasanex/NEX-GDDP/BCSD/rcp85/day/atmos/tasmax/...
user avatar
  • 433
0 votes
0 answers
13 views

Xarray mean for climatologies use min_count as in xarray sum

Why there is not implemented in xr.mean() a parameter for minimum count of valid data accross arrays? As in xr.sum() for example. I have a certain situation where I want to compute climatologies and I'...
user avatar
0 votes
1 answer
21 views

Wrong results using xarray groupby to calculte anomalies

I want to compute ten days anomalies based on MODIS NDSI. The data is stored as a GeoTIFF. For this task I have two folders, one with the reference period of 2001-2020 and one with 2001-2022 for which ...
user avatar
1 vote
1 answer
82 views

How to save an xarray.DataArray directly as a Cloud Optimized GeoTIFF?

Is there a good way to produce a cloud-optimized GeoTIFF (https://www.cogeo.org) directly from an xarray.DataArray? At the moment it takes me a couple of steps to produce an intermediate regular ...
user avatar
  • 1,483
0 votes
0 answers
12 views

Plotting Open Data Cube xarray data with two or more measurement parameters in the same axis

How can I plot the two measurement parameters (seasonal cover and permanent water cover) in the same axis as I want to compare them? I have this code: #load the cgls product ds_cgls_builtcover = dc....
user avatar
0 votes
1 answer
12 views

Create new column containing values of a xarray variable selected by point coordinates

I have a xarray and a geodataframe. I want to extract spi_1 values of xarray from point geometries of geodataframe by creating a new column spi_1 in geodataframe. print(xr) <xarray.DataArray '...
user avatar
  • 153
0 votes
0 answers
63 views

xarray NetCDF with groups to GeoTIFF

I am trying to convert NetCDF files, available from this link, to raster or geotiff files using Python 3. After reading the a NetCDF file using the package netcdf4, it appears to have groups: CO2, ...
user avatar
1 vote
0 answers
29 views

Is there a rioxarray version of xarray pad

I have a geocoded raster that I'd like to pad with NaNs to 64 x 64 pixels. I've tested rioxarray.DataArray.pad_box(), which does work, but it's a bit complex to calculate new bounding box corners that ...
user avatar
1 vote
0 answers
61 views

Value error when merging .nc files: xarray could not find any dimension coordinates to use to order the datasets for concatenation

I want to merge multiple .nc files into one. Each of the .nc files corresponds to a timestep which should be added together to have one .nc file with all data for all dates. When I execute the ...
user avatar
1 vote
2 answers
104 views

rio.write_crs() leaves empty crs

I have a dataset ds which looks like this: <xarray.Dataset> Dimensions: (time: 42, long: 1383, lat: 586) Coordinates: * time (time) datetime64[ns] 1979-01-01 1980-01-01 ... 2020-...
user avatar
1 vote
1 answer
185 views

How to add a band to xarray dataset using rioxarray

I have two datasets, both rasters, which I would like to combine into 1 raster. This should not be difficult, but I'm having a hard time.. Both have the same extent/resolution etc. One raster has 231 ...
user avatar
  • 111
0 votes
1 answer
36 views

Transforming GPM Precip Data using rioxarray

I am working with GPM Precip data on a hydrologic study and I am having a hard time figuring out why the netcdf files I downloaded are giving me issues when I try and map the data. I am still learning ...
user avatar
  • 137
0 votes
0 answers
31 views

Convert COG with CRS to dimensions with equal longitude latitude

I have some Cloud Optimized GeoTIFFs exported in a certain CRS. Although the COG was exported in with equal longitude/latitude lengths, its CRS caused the array to have unequal dimensions. (206 lat x ...
user avatar
  • 71
0 votes
0 answers
78 views

How to fix rioxarray.exceptions.DimensionMissingCoordinateError: x missing coordinates?

I'm trying to reproject a NetCDF file without an assigned projection. I was successful in assigning projection. But, while attempting to reproject the file, I receive the following error: rioxarray....
user avatar
  • 375
0 votes
0 answers
208 views

Reading grib file without extension using Xarray

Is it possible to read a file without an extension from Xarray and let Xarray infer the correct datatype? Context: I downloaded files with .Z compression from https://data.eol.ucar.edu/. An example ...
user avatar
  • 375
1 vote
1 answer
379 views

Converting a NetCDF from 0 to 360 to -180 to 180 via xarray

I've got an ERA5 NetCDF that's in 0 to 360 and I'd like to convert it to -180 to 180 before saving it off as a raster. I've got the current workflow set up, but am unsure of how to switch the longs. ...
user avatar
  • 433
2 votes
1 answer
228 views

How to change the dtype of a NetCDF variable and rewrite as a new NetCDF file

I was wondering how to change the dtype of precipitation from int16 to float64 in the following NetCDF file with these dimensions and variables, and rewrite it as new NetCDF file; <class 'netCDF4....
user avatar
1 vote
0 answers
37 views

Merge xarray dataset tiles

I have 15 xarray datasets that represent tiles of big area in x,y dimension. Each dataset has 2-3 GB size with lat, lon and time coordinates. I converted data types from float64 to float32 to ...
user avatar
  • 800
0 votes
0 answers
33 views

Transforms from the same file are different

Reading a NetCDF file in two ways: src = rasterio.open(f'NetCDF:{url}:Rad', 'r') and doing src.transform gives: Affine(2004.017315487541, 0.0, -5434894.700982174, 0.0, -2004.017315487541, 5434894....
user avatar
  • 103
0 votes
0 answers
131 views

Different elevation values between using rasterio, xarray, rioxarray, gdal and QGIS

I am trying to extract elevation values from a DEM raster under array format by using some packages (rasterio, xarray, rioxarray, and gdal). However, they seemed to give me a different results from ...
user avatar
  • 57
2 votes
1 answer
200 views

Mask time series xarray dataset based on the other overlapping dataset?

I have Dataset1 that have time series of vegetation moisture values (fmc_mean) and Dataset2 that have vegetation cover types LC_Type1 (grass - 1, shrub - 2, forest -3) that overlaps with Dataset1. ...
user avatar
  • 800
0 votes
1 answer
378 views

Converting GeoTIFF file into NetCDF file in Python and file is empty [closed]

I am trying to convert a GeoTIFF file into NetCDF file (still remains all the information) using either rioxarray or xarray in python. The file is just empty. But when I checked the GeoTIFF file it ...
user avatar
  • 57
0 votes
1 answer
43 views

Exporting NetCDF file in MODIS sinusoidal grid with xarray

I have 18 TIFF files in the MODIS sinusoidal grid I would like to convert to one file in NetCDF format. I have converted the tifs to an xarray xarray.core.dataset.Dataset format called stacked. At ...
user avatar
0 votes
1 answer
86 views

Rioxarray.merge.merge_datasets unable to merge xarray datasets [closed]

I am working with geospatial data and have been previously using rasterio's merge function to join adjacent tiles together. For memory reasons I have switched from using in-memory rasters to xarray ...
user avatar
1 vote
1 answer
168 views

How to convert GeoTIFF file into NeCDF file in Python Jupyter notebook without changing any information?

I am looking for a way to convert GeoTIFF raster file into NetCDF file using Python Jupyter notebook. I have tried function gdal.translate and xarray (.to_netcdf) (as below), but both of them gave me ...
user avatar
  • 57
1 vote
0 answers
61 views

Voxel layer ArcGIS

This is the Python code to create a NC file using xarray library and NetCDF4. However, when it was loaded as a voxel layer in ArcGIS Pro, it wasn't able to display all the data. Only 4 data points ...
user avatar
  • 11
1 vote
2 answers
2k views

How to change certain values in an xarray depending on the coordinates

I have a Data Array with 4, 5 or 6 representing the classes: bare soil, vegetation and water. cube1 = <xarray.DataArray 'SCL_20m' (time: 5, y: 3, x: 3)> array([[[4., 6., 6.], [4., 4., ...
user avatar
0 votes
1 answer
60 views

How to extract exact values from a raster file (TIFF) using a shapefile, using xarray to open the raster

I have found a link online that extracts the values min mean max and median, this is using the zonal stats function. sjer_tree_heights = rs.zonal_stats(plot_buffer_path, ...
user avatar
  • 1
1 vote
1 answer
1k views

Problem in setting dimension using rioxarray set_spatial_dims()

I am having trouble setting dimensions in a xarray object. I have created a xarray object (data, lats, and lons are 2D ndarray) and set a coordinate system as follows, and it is working. da0 = xr....
user avatar
  • 33
-1 votes
1 answer
300 views

Resample (spatially-average) DataArray / raster to match the grid of another DataArray in Python [closed]

I would like to resample a DataArray / raster object to exactly match the spatial grid of another DataArray / raster object. In particular, the operation I want to perform is a spatial averaging to ...
user avatar
  • 43
1 vote
1 answer
192 views

Difference between `reproject_match` and `interp_like`

I'm pretty new to GIS and I'm trying to understand the difference between the interpolation done with rioxarray reproject_match and xarray interp_like. Assuming I have two rasters da1 and da2 with ...
user avatar
  • 35
1 vote
1 answer
67 views

How to find first temporal occurrence of specific values for each pixel

I have a NetCDF file for a given region in North America. It contains temperature data from 1959 to 2009. I would like to extract the first day on which the temperature exceeds 273 K for each pixel. ...
user avatar
  • 772
0 votes
0 answers
31 views

What parameters of xarray I should set to upload the NetCDF in proper projection?

I save an xarray to NetCDF. I have all parameters of the projection and I can write them to xarray. I tried coord "spacial_ref" and attr 'grid_mapping='spatial_ref' while spatial ref is ...
user avatar
0 votes
0 answers
33 views

How to add to xarray information about projection while saving to NetCDF?

I have a .dat and a .ctl files (resulting of athmospheric model) Using xgrads python package I can read .ctl file dsetPath: geo_etr_d01.dat descPath: geo_etr_d01.ctl indxPath: stnmPath: title: ...
user avatar
4 votes
1 answer
2k views

Using rioxarray to assign spatial reference (EPSG:4326) to NetCDF built from CSV with lat long columns

I am trying to create a NetCDF from a CSV file. The idea comes from the fact that the original CSV comes with many columns, three of these representing: a specific year ("time") the Y ...
user avatar
  • 3,497
1 vote
1 answer
179 views

QGIS 3.10 - NetCDF created with xarray "is not a valid or recognized data source"

I have a xarray DataSet ds created from a Pandas DataFrame whose info are the following: Dimensions: (lat: 144, lon: 140, year: 9) Coordinates: * year (year) object 1980 1985 ...
user avatar
  • 3,497
2 votes
1 answer
398 views

Georeferencing Sentinel-3 LST product

I have been stuck attempting to convert Sentinel-3 LST netCDF data to geotiffs for a while now as part of my master's thesis. Firstly, an introduction to the data. It is packaged as follow: The data ...
user avatar
1 vote
2 answers
442 views

Showing lat long instead of numbered index on spatial data map

I am trying to project meteorological data from a netcdf4 file with its latitude and longitude information and I am not getting how to show lat-long information on the x and y-axis, in the image ...
user avatar
0 votes
2 answers
247 views

How to mask and scale raster using rasterio?

I have been trying to read a raster file in netcdf format which I will later on sample. I need to read using the DatasetReader as float. When I read: ds = rasterio.open(f'netcdf:{file}:AOT_L2_Mean', ...
user avatar
  • 430
0 votes
1 answer
162 views

Polygon Drill on Open Data Cube

I face a crucial problem with ODC. I try to do a spatial join with a shapefile (polygon drill). I have followed the following steps: Read the shapefile and get the first polygon to test Ensure that ...
user avatar
0 votes
0 answers
351 views

Conflicting sizes for dimension 'time' with rioxarray

I've been using rioxarray to convert netcdf files to geotiffs, and up till now, it's worked great. However, when I open a ERA5 reanalysis netcdf dataset, rioxarray appears to find that the data size ...
user avatar
2 votes
2 answers
1k views

Open and plot a large raster with Python xarray

I have an ASCII Esri file of the type: ncols 5201 nrows 4001 xllcorner -65 yllcorner -35 cellsize 0.025 NODATA_value -9999 -9999 -9999 -9999 255 256 -9999 -9999 ... -9999 -9999 -9999 -9999 -9999 -9999 ...
user avatar
  • 133
1 vote
0 answers
427 views

Creating raster stack from xarray in Python

I am trying to create a raster stack from an xarray dataset which I obtained from multiple NetCDF files. import netCDF4 as nc import rasterio as rio import numpy as np import xarray as xr import os ...
user avatar
1 vote
0 answers
65 views

Cut NetCDF files by shapefile [duplicate]

I have a large dataset of global .nc files and I am trying to clip them to a smaller area. I have this area stored as a .shp file. I have tried using GDAL from QGIS but needs to do this by converting ...
user avatar
0 votes
1 answer
588 views

Plotting xarray over background map using cartopy

I am trying to plot an xarray DataArray over a background map using cartopy. When including the background map, the DataArray is not visible, although the map has an appropriate extent. I am adding ...
user avatar
  • 226