Hot answers tagged

20 votes
Accepted

Converting NetCDF dataset array to GeoTiff using rasterio Python

I would recommend looking into rioxarray for your dataset. You can open your dataset like so: import rioxarray import xarray xds = xarray.open_dataset('D:\Weather data\et_01012018.nc') If your CRS ...
snowman2's user avatar
  • 7,301
16 votes
Accepted

Masking NetCDF time series data from shapefile using Python

Here is an example of using rioxarray to mask out data with a shapefile: https://corteva.github.io/rioxarray/stable/examples/clip_geom.html import geopandas import rioxarray import xarray from ...
snowman2's user avatar
  • 7,301
12 votes
Accepted

how to prepare tiffs to create a netcdf file

I found that the easiest way to create a new NetCDF file containing several GeoTIFF files is using GDAL and then using NCO and CDO tools (Provided by unidata) to add the appropriate metadata. First ...
fjboogert's user avatar
  • 413
12 votes
Accepted

xarray slicing across the antimeridian

Xarray is (intentionally) ignorant of coordinate systems, so it has no special handling for cyclic coordinates such as longitude. Because your longitude array has only increasing values, xarray ...
shoyer's user avatar
  • 238
11 votes
Accepted

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

min_lon = -24.995 min_lat = 25.05 max_lon = 45.50 max_lat = 71.55 cropped_ds = ds.sel(lat=slice(min_lat,max_lat), lon=slice(min_lon,max_lon))
Paula's user avatar
  • 126
10 votes

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

You could use rioxarray: https://corteva.github.io/rioxarray/stable/examples/clip_box.html import rioxarray min_lon = -24.995 min_lat = 25.05 max_lon = 45.50 max_lat = 71.55 subset = band.rio....
snowman2's user avatar
  • 7,301
9 votes
Accepted

Extract time series values from a 3D (lon,lat,time) NetCDF file using Python

So you have 3D data (lon,lat,time) in a netcdf file and you want to extract a time-series as a specific location in Python, right? Here's one way using netCDF4: http://nbviewer.jupyter.org/gist/...
Rich Signell's user avatar
  • 2,262
8 votes

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

You can use xarray.where. See: http://xarray.pydata.org/en/stable/indexing.html xds = xarray.open_dataset("TT_199501_daymean.nc") xds.where((xds.lon==5.8252) & (xds.lat==46.9359), drop=...
snowman2's user avatar
  • 7,301
8 votes
Accepted

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

This method worked: with xr.open_dataset(nc_fp, mask_and_scale=True, decode_times=True) as src: ds = src.sel(time="2020-01-01").max('time') ds.rio.write_crs("epsg:4326", ...
JWB's user avatar
  • 564
7 votes

Creating a multiband raster from netcdf in R

Use this to get access to all bands lradin <- brick("lrad_ITPCAS-CMFD_V0106_B-01_197912.nc") Use ?subset or lradin[[1]] to get specific band/s. Use ?getZ to find out the specific date for each ...
mdsumner's user avatar
  • 8,186
7 votes

NetCDF layer (.nc) appears flipped and rotated in QGIS

The QGIS raster import for netcdf uses the GDAL drivers which assume the data follows the CF conventions, and the multidimensional arrays within the data in (...Y,X) order per this: Dimension The ...
Dave X's user avatar
  • 1,639
7 votes
Accepted

Using xarray to resample and merge two datasets

This documentation from xarray outlines quite simply the solution to the problem. xarray allows you to interpolate in multiple dimensions and specify another Dataset's x and y dimensions as the output ...
clifgray's user avatar
  • 409
7 votes
Accepted

Cannot open NetCDF File in QGIS

As stated in the linked thread, QGIS (3.2+) can open the NetCDF file as a mesh layer. (1) Open the file using Layer > Add Layer > Add Mesh Layer. (2) By default, the first variable (...
Kazuhito's user avatar
  • 30.7k
6 votes

R Raster package: write NetCDF with time dimension

I know this is an old question, but if anyone is still looking for an answer on how to do this in R the following code that will make a netCDF with 2 variables (prec, tmax), and 3 dimensions (long, ...
KaanKaant's user avatar
  • 353
6 votes

Merging netcdf files into one using R?

I'd suggest trying NCO again, as it's well suited for this type of operation, and can be done with one command. The tool to concatenate several files along the record dimension (e.g. time) is ncrcat. ...
Mike T's user avatar
  • 42k
6 votes

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

One way is to create a boolean mask for the dataset coordinates using the extent you specified and then using the .where() method on the dataset. Here is one example using a tutorial dataset that ...
Marcelo Villa's user avatar
6 votes

Computing annual spatial (zonal) statistics of a NetCDF file for polygons in shape-file

I used this code to get want I wanted: # import packages import xarray as xr import rasterio as rio import geopandas as gpd import rasterstats as rstats # load and read shp-file with geopandas ...
Jannis's user avatar
  • 99
6 votes
Accepted

How to open NetCDF in QGIS

I've solved my issue with the help of @Kazuhito. Firstly, you need to install the NCO (netCDF Operator). The issue is that NetCDF has sometimes different order of variables and QGIS is not able to ...
Luckasino's user avatar
  • 293
6 votes
Accepted

Adding compression to a NetCDF file using xarray

The error hints at xarray trying to find a variable called "zlib" in your data. The correct structure for the encoding dict would be something like: encode = {"precipitation": {'...
bugmenot123's user avatar
  • 11.3k
5 votes

Displaying netCDF data with correct CRS?

You can use the netCDF operators (NCO) to add spatial reference information that will be understood by QGIS. Essentially, we need to: Create a crs variable that has no associated dimensions Attach ...
dbaston's user avatar
  • 13k
5 votes
Accepted

Raster conversion from netCDF ORCA025 to equirectangular projection

You can run gdalinfo on the netcdf file to see that it has the following subdatasets: SUBDATASET_1_NAME=NETCDF:"BIOMER_FREEGLORYS2V3_20161215_R20170703_gridCHL.nc":nav_lon SUBDATASET_1_DESC=[...
AndreJ's user avatar
  • 76.6k
5 votes
Accepted

Reading d NetCDF4 format climate data observation in R?

These data are not in a netcdf format but, rather a space delimited ASCII format. This data is a bit difficult to deal with because of the lack of headers and any type of unique station identifier. ...
Jeffrey Evans's user avatar
5 votes
Accepted

Mapping a NetCDF in QGIS in the correct location on Earth

This nc file does not store its CRS in itself. So I used OSGeo4W Shell with this command; gdal_translate -a_srs EPSG:4326 -of netCDF erdMBchla1day_8453_6188_94d0.nc erdMBchla1day_8453_6188_94d0_4326....
Kazuhito's user avatar
  • 30.7k
5 votes
Accepted

How do I run Panoply (from NASA GISS) on Windows 10?

You can download Java Runtime Environment 9 from Oracle Download page.
Kadir Şahbaz's user avatar
5 votes
Accepted

Raster conversion from NetCDF to GeoTIFF changes data values

As @user30184 pointed out, there is a scale factor that is applied to the NetCDF when it is read with xarray. When opening the .tiff with rasterio, this scaling factor must be multiplied with the ...
ColinB's user avatar
  • 233
5 votes
Accepted

What is origin of term "network" in Network Common Data Form (NetCDF) format specification

There's some history of netCDF in the NetCDF User's Guide. The term "network" was intended to indicate that the data files could be shared between different types of computers across ...
Ethan Davis's user avatar
4 votes

Which statistical methods to compare the spatial distribution of two different variables in two raster maps?

tl;dr: pick a segregation measure from the seg package, probably the isp() function as an implementation of White (1983). I'd recommend using an entropy segregation measure. Probably you need some ...
Ma Ba's user avatar
  • 71
4 votes

FOSS way of creating space time cube?

If you want to stay in the GIS context, there is feature rich temporal data processing included in GRASS GIS 7. It is free and open source software, available from https://grass.osgeo.org . The ...
markusN's user avatar
  • 13k
4 votes

Set projection for NetCDF4 in Python

I don't know much at all about writing NetCDF files, but the following allowed me to write a NetCDF file that GDAL recognised the CRS. import numpy as np import netCDF4 as nc outfile = r'test.nc' ...
user2856's user avatar
  • 65.4k
4 votes
Accepted

NetCDF to Raster: Dealing with Memory Leak

I am able to reproduce the memory issue; I am on ArcGIS 10.4.1. I have also tried to delete the map layers that are created after each conversion call, but was not able to release the memory. result ...
Alex Tereshenkov's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible