Hot answers tagged

16 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 ...
user avatar
  • 6,002
15 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 ...
user avatar
  • 6,002
11 votes
Accepted

how to prepare tiffs to create a netcdf file

I figured out the answer some time ago but I hope this will help other people that are dipping their toes into the NetCDF file format. I found that the easiest way to create a new NetCDF file ...
user avatar
  • 393
11 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 ...
user avatar
  • 228
9 votes

How to extract value from a raster based on lat and lon?

To get the appropriate cell coordinates from your latitude and longitude you need to know the coverage of the netCDF file (for example, the coordinate of the upper left cell and the size of the cells ...
user avatar
  • 15.4k
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/...
user avatar
  • 2,232
7 votes
Accepted

GDAL for Python: extracting subdomains from NetCDF file?

The Norwegian Met office has a THREDDS server at http://thredds.met.no/thredds/ so if you see the forecast you are trying to access there, you can extract just the subset you want from the OPeNDAP URL,...
user avatar
  • 2,232
7 votes

What coordinate system is this netCDF raster?

You can shift the data into the correct position using these GDAL commands: gdal_translate -a_srs EPSG:4326 -a_ullr 0 0 360 -90 NETCDF:"sic_average_nclimate.nc":SIC_Change change360.tif gdalwarp -...
user avatar
  • 75.2k
7 votes
Accepted

How to match a raster NetCDF data with a vector layer in QGIS?

The metadata of the netcdf file includes projection information, which can be identified by QGIS as a custom CRS: +proj=lcc +lat_1=50 +lat_2=50 +lat_0=50 +lon_0=-107 +x_0=5632642.22547 +y_0=4612545....
user avatar
  • 75.2k
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 ...
user avatar
  • 7,907
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 ...
user avatar
  • 1,549
7 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=...
user avatar
  • 6,002
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 (...
user avatar
  • 29.2k
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, ...
user avatar
  • 343
6 votes

NetCDF to Geotiff file conversion

GDAL supports NetCDF: http://www.gdal.org/frmt_netcdf.html gdal_translate input.cdf output.tif
user avatar
  • 8,554
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. ...
user avatar
  • 40.1k
6 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 ...
user avatar
  • 379
5 votes
Accepted

python crashes with returned gdal band object from a function

The dataset is getting dereferenced when you return only the band from your function. The solution is to return the dataset from your function. From the GDAL Python Gotchas page: Python crashes ...
user avatar
  • 53.4k
5 votes

Programs/ languages to process netcdf files "fast"

NetCDF is incredibly general and writing slow code is easy. I routinely deal with tens of thousands of NetCDF files in R, using some combination of packages raster, ncdf, ncdf4, RNetCDF, or rgdal. The ...
user avatar
  • 7,907
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=[...
user avatar
  • 75.2k
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. ...
user avatar
5 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 ...
user avatar
5 votes
Accepted

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....
user avatar
  • 6,002
5 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 ...
user avatar
5 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": {'...
user avatar
  • 8,554
5 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", ...
user avatar
  • 488
4 votes

Speed of various raster data formats

A big question is whether you are going to read the entire raster from the file into memory before processing it, or whether the file is so large that you will process it incrementally, or process ...
user avatar
  • 141
4 votes

Creating WFS from netCDF file(s)

If you have moved on to the netCDF Java API it might be interesting for you to try Python as well. I have worked with Java for a while but find Python for number crunching and data analysis more ...
user avatar
  • 91
4 votes
Accepted

Plotting NetCDF file using lat and lon contained in variables

I guess that my answer from your other StackOverflow question did not lead you in the right direction? Here is a more detailed answer that may nudge you in the right direction. First, we need to ...
user avatar
  • 816
4 votes

Plotting Netcdf data. How to get right projection?

This is not really a raster in longitude latitude, it's just arrays of values (including longitude and latitude). You can deal with these explicitly like this: f <- "F18-SSUSI_EDR-NIGHT-DISK_DD....
user avatar
  • 7,907

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