Questions tagged [xarray]

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

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

How to visualize a NetCDF Dataset

Suppose I have a rather large NetCDF file that I open as a dataset using xarray. import xarray nc_in = r"....\D_P_WGS84_comp.nc" nc_ds = xarray.open_dataset(nc_in) It is composed of ...
1
vote
1answer
32 views

Adding compression to a NetCDF file using xarray

I have a raster that I am trying to compress and convert to a NetCDF format with compression level = 9 using the xarray package. I assume that the compression is added using the encoding parameter as ...
0
votes
0answers
20 views

Loading Open Data Cube data to match a raster with geographic coordinates?

I would like to load a raster from a GeoTIFF file, and then load a time series of data from the Open Data Cube into the same CRS and resolution so I can use the raster as a mask. I can use the raster'...
0
votes
1answer
31 views

Unable to read GRIB datas with XArray

I used this code to read grib data import os import numpy as np import pandas as pd import xarray as xr path = "gfsanl_4_2019101000.g2" os.chdir(path) ds = xr.open_dataset('...
1
vote
1answer
52 views

CRS Error when clipping NetCDF using a shapefile

When trying to mask a NetCDF (a daily time series of 31 days) with the code below, I get the following error related to the part of writing the CRS to the rio NetCDF data: CRSError: The WKT could not ...
1
vote
0answers
20 views

overlaying xarray data with shapefile using

import xarray import xshape import matplotlib.pyplot as plt da.xshape.overlay(shapefile,colors=['b', 'orange', 'g', 'r', 'c', 'm', 'y', 'grey', 'Brown', 'ForestGreen'],levels =10) I tried to plot ...
2
votes
3answers
705 views

Mask xarray dataset using a shapefile [closed]

I have used xarray on some satellite data that I'd like to mask it using a shapefile. I have previously been doing this using a combination of PIL, numpy and gdal, but it would be cleaner to do this ...
1
vote
2answers
70 views

Find closest point to shapefile coastline in Python

I have a xarray (674 lats & 488 Lons) and want to find the closest distance for each point to the coastline in meters. I found this solution: Finding closest point to shapefile coastline Python ...
4
votes
1answer
406 views

Indexing coordinates in order to get a value by coordinates from xarray

Firstly, I am a super rookie and just recently started working with GIS. Therefore I am not sure how to ask/word the question, or even if it makes sense. So bear with me. I have some NetCDF files, ...
0
votes
2answers
413 views

Extract latitude and longitude from rotated coordinate system

I'm new to working with geographic data so please bear with me. I have the following data: bnds,projection_x_coordinate,projection_y_coordinate,realization,fog_area_fraction,...
0
votes
1answer
51 views

Output GeoTIFF file is wrongly rotated to 90 degrees/ -90 degrees using xarray and rioxarray with NotGeoreferencedWarning warning

I am using this file. I wrote this code. import rioxarray import xarray xds = xarray.open_dataset("LIS_HIST_201401010000.d01 copy.nc") floodFraction = xds.FloodedFrac_tavg.transpose('...
3
votes
2answers
462 views

Opening EOS netCDF4/HDF5 file with correct format using xarray?

I am using xarray (version 0.12.2) to work with the MODIS/Terra+Aqua MAIAC Land Aerosol Optical Depth dataset (MCD19A2.006). xarray successfully opens that dataset with the correct variables and ...
2
votes
1answer
128 views

How to save a clipped NetCDF data as a new NetCDF file in Python?

I have used xarray to clip my NetCDF file‌ (it can be downloaded here) by a shapefile (it can be downloaded from here). Here is the code: import xarray import rioxarray import geopandas from shapely....
3
votes
1answer
506 views

Using Rioxarray / QGIS Projection

For the past couple weeks I have been trying to view GOES17 data from netCDF files (converted to geotif) in QGIS 3.10 but cannot get the projection to work correctly. I have attempted numerous ...
0
votes
1answer
81 views

Accessing Numpy Array found within an XArray from Satpy

dask.array<shape=(76, 76), dtype=float32, chunksize=(76, 76)> Coordinates: crs object +proj=utm +datum=WGS84 +ellps=WGS84 +no_defs +units=m +zone=33.0 +type=crs * y (y) float64 ...
-1
votes
1answer
185 views

cartopy and xarray issues

I'm beginning to use netCDF4 data and therefore I have downloaded xarray and also cartopy (with pip). I have downloaded data from the climate data store and want to plot these data. I have a notebook ...
1
vote
2answers
82 views

How can I merge two bands with different sizes using Rioxarray?

I have two images that I want to combine as follows Expected result: I tried to use the function rioxarray.merge.merge_arrays() in the following way but I got this error that I can't understand: >&...
2
votes
0answers
27 views

Extract time series for features from large masked xarrays

I have done this before with GDAL and Python, but was hoping to be able to use xarray to scale things up. Let's say I have three datasets: 1. A large multiband geotiff where each band is a different ...
0
votes
1answer
144 views

Clip global data by polygon using rioxarray fails (off by 180 longitude)

I want to extract CMIP6 climate data within polygons defined by a selection of the Large Marine Ecosystems of the world. The data(CMIP6) are found in ranges from 0 to 360 degrees longitude, while my ...
6
votes
1answer
1k views

Extracting data within geometry (shape)

I have a NetCDF dataset which I normally call using the xarray function. I have recently been doing some transect analysis on the dataset, which looks something like this (the area between the ...
1
vote
2answers
481 views

How to clip an xarray to a smaller extent given the lat/lon coordinates?

I have a netcdf file showing elevation over Europe derived from GTopo30. Turns out that the extent of this raster file is too big to combine it with other layers, so I would like to crop it to a given ...
4
votes
1answer
119 views

Converting NOAA's World Ocean Database NetCDF files to tabular data using Python

I'm trying to convert variables from NetCDF files to tabular data, but can't understand how to group observations by some index or key variable. For example, when loading data from WOD queries using ...
2
votes
0answers
65 views

How to slice a reduced gaussian gridded grib with xarray?

I want: to get list of coordinates of points within the specified area (ideal would be geopandas from shapefile or something like this) I don't want to interpolate the grib, just extract points by ...
1
vote
1answer
75 views

NetCDF hourly data to year raster layers (using Python)

Having a NetCDF with a 'time', 'lat' and 'lon' dimension, where time is hourly during a year and the variable to extract is temperature, how do I calculate mean temperature throughout the year using ...
1
vote
0answers
29 views

Cannot visualize xarray dataframe after converting to NetCDF

I am trying to convert sample.csv dataframe - link no NetCDF here is what I did import xarray as xr import pandas as pd dfcsv=pd.read_csv('sample.csv') dfcsv=dfcsv.set_index(['latitude','longitude','...
2
votes
1answer
654 views

Using xarray to resample and merge two datasets

I have one dataset of satellite based solar induced fluorescence (SIF) and one of modeled precipitation. I want to compare precipitation to SIF on a per pixel basis in my study area. My two datasets ...
1
vote
1answer
55 views

NetCDF: Why store coordinates as matrix

I am reading the documentation of Python library xarray After having opened multiple NetCDFs and explored their contents, I see that some files store their coordinates as a matrix and some store ...
1
vote
0answers
121 views

Calculating the area of each cell of a Dataarray (or Raster) using Python? [closed]

I would like to compute the area of each respective cell of a raster. The pixels are in degree coordinates, so it is not trivial to calculate the area of each one "manually". In R I know there is a ...
5
votes
1answer
638 views

GDAL crashes with segmentation fault when trying to open a NetCDF subdataset with time dimension

I am trying to create a NetCDF file which is compliant with the NetCDF Conventions CF-1.4. The dimensions of the file are (TIME, Y, X) where Y and X are the polar stereographic grid. The file that I ...
-1
votes
1answer
2k views

How to change Numpy array shape [closed]

I have an array (Numpy of shape (100, 256, 256). How can I change this to (100, 256, 256,3)? I tried doing reshape but it doesn't work, Can anyone help me.
6
votes
1answer
3k views

xarray slicing across the antimeridian

I'm just starting with using xarray for working with n-dimensional NetCDF datasets. I particularly like the techniques for slicing using both indexes and labels (isel and sel): import xarray as xr ds ...