Questions tagged [netcdf4]

Questions related to NetCDF (Network Common Data Form) format and corresponding libraries/implementations may have this tag.

In 2008, the netCDF4 format was added to support per-variable compression, multiple unlimited dimensions, more complex data types, and better performance, by layering an enhanced netCDF access interface on top of the HDF5 format.

At the same time, a fourth format variant, netCDF-4 classic model format, was added for users who needed the performance benefits of the new format (such as compression) without the complexity of a new programming interface or enhanced data mode.

Every netCDF-4 or netCDF-4 classic model file can be read or written by the HDF5 library version 1.8 or later, so in that respect netCDF-4 files are already HDF5 files and need no conversion.

According to netCDF FAQ installing the netCDF4 is required for any of the following situations:

  • you need to access netCDF data that makes use of netCDF-4 compression or chunking
  • you need to access data in all netCDF formats including netCDF-4 or netCDF-4 classic model formats
  • you need to write non-record variables larger than 4GiB or record variables with more than 4GiB per record
  • you are installing netCDF to support other software packages that require netCDF-4 features
  • you want to write data that takes advantage of compression, chunking, or other netCDF-4 features
  • you want to be able to read netCDF-4 classic model data with no changes to your current software except relinking with the new library
  • you want to benchmark your current applications with the new libraries to determine whether the benefits are significant enough to justify the upgrade
  • you need to use parallel I/O with netCDF-4 or netCDF-4 classic files
651 questions
2
votes
1 answer

Use latitude & longitude to determine which "cell" I am located in (NETCDF4)

Background I have a NETCDF4 file with grid size 0.125x0.125. The latitudes go from 90 to -90 and longitudes go from 0 to 360. The full table size is therefore 1441 x 2880 (latitudes x longitudes). I am taking my location coordinates (lat lon in…
pookie
  • 3,796
  • 6
  • 49
  • 105
2
votes
1 answer

Extracting value form netCDF for location and across time-range

Is there a netCDF4 equaivalent of the xarray function to select values from a netCDF file for a lat lon and for a specific time-range: hndl_nc.sel(time=slice(start_date, end_date)).sel(lon=lon, lat=lat, method='nearest') I do not want to use cdo or…
user308827
  • 21,227
  • 87
  • 254
  • 417
2
votes
0 answers

ImportError: DLL load failed: The specified module could not be found. Windows 10

I recently installed the last version of Python (3.6) in my new laptop and I got this error when I tried to import netCDF4 ImportError: DLL load failed: The specified module could not be found. I´m using Windows 10. Any idea about the solution?
palito28
  • 21
  • 2
2
votes
2 answers

Writing to a NetCDF3 file using module netcdf4 in python

I'm having a issue writing to a netcdf3 file using the netcdf4 functions. I tried using the create variable function but it gives me this error: NetCDF: Attempting netcdf-4 operation on netcdf-3 file nc =…
EagleTamer
  • 47
  • 8
2
votes
2 answers

How to append new data into existing netcdf file

I have a multivariable ncdf that I created and wanted to add additional data to each variable. the lat and long dimensions will remain the same but I want to extend the time dimension by appending new data to each variable. The new data set has the…
Yami
  • 21
  • 1
  • 3
2
votes
2 answers

OSError with libnetcdf-fortran: undefined symbol

I had to update some Anaconda/Python packages on my Linux (Ubuntu 15.10), and as a result I get now the following error message which I have never seen before: OSError: /usr/lib/x86_64-linux-gnu/libnetcdff.so.6: undefined symbol:nc_rename_grp The…
Jannis
  • 173
  • 2
  • 6
2
votes
3 answers

Change _FillValue in netCDF file

Is there a python netCDF4 command/example to change the global metadata _FillValue in a netCDF file? I have tried replacing all -ve values in a netCDF file, but till the time the _FillValue attribute is set, that does not work
user308827
  • 21,227
  • 87
  • 254
  • 417
2
votes
1 answer

"ValueError: chunksize cannot exceed dimension size" when trying to write xarray to netcdf

I got the following error when trying to write a xarray object to netcdf file: "ValueError: chunksize cannot exceed dimension size" The data is too big for my memory and needs to be chunked. The routine is basically as follows: import xarray…
Ben Müller
  • 125
  • 1
  • 11
2
votes
1 answer

Creating output variables and copying attributes in python xarray netcdf4

I can create variables and copy over attributes in netcdf4 like this: out_var = hndl_out_nc.createVariable(name_var, var.datatype, var.dimensions) out_var.setncatts({k: var.getncattr(k) for k in var.ncattrs()}) What is the corresponding version for…
user308827
  • 21,227
  • 87
  • 254
  • 417
2
votes
2 answers

How to set chunk size of netCDF4 in python?

I can see the default chunking setting in netCDF4 library, but I have no idea how to change the chunk size. from netCDF4 import Dataset volcgrp = Dataset('datasets/volcano.nc', 'r') data = volcgrp.variables['abso4'] print data.shape print…
American curl
  • 1,259
  • 2
  • 18
  • 21
1
vote
1 answer

Problems with installing netCDF4==1.4.2

I am trying to install netCDF4==1.4.2 using "pip install netCDF4==1.4.2" to use in jupyter notebook. I am running Windows 10 enterprise 64 bit. python 3.10.9 anaconda-client 1.11.2 anaconda-navigator …
mathnoob
  • 15
  • 5
1
vote
1 answer

Extracting data from NetCDF file in r

I am trying to load data from a NetCDF file to r and continue having issues even after following a couple tutorials and SO posts. This is the first time I work with NetCDF so I am unsure what I am doing wrong. I have tried both with the ncdf4 and…
FishyFishies
  • 301
  • 3
  • 14
1
vote
1 answer

Export NumPy array as NetCDF4 file

I'm trying to export a simple 2D NumPy array as a .nc (NetCDF) file. I'm trying to follow this example without exit. import numpy as np import netCDF4 as nc # Array example x = np.random.random((16,16)) # Create NetCDF4 dataset with…
sermomon
  • 254
  • 1
  • 11
1
vote
1 answer

DataArray changed when it was saved to a netCDF file

I first concatenated multiple DataArrays along the dimonsion of time, and then I merged a couple of meteorological variables into one Xarray.DataArray. Finally, I saved the DataArray into a netCDF file. It was strange, that the data changed after it…
CrayonAki
  • 11
  • 2
1
vote
1 answer

NetCDF4 error with the Dataset function in python

I am currently using ubuntu 22.04. I have installed anaconda3 on it, run everythong on the base environment and installed netcdf4 using the command pip install netcdf4 I have coded a script visu_choc.py, which uses the Dataset function of netcdf4,…
astrorobot
  • 11
  • 2