• Stars
    star
    726
  • Rank 60,266 (Top 2 %)
  • Language Cython
  • License
    MIT License
  • Created over 10 years ago
  • Updated 21 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

netcdf4-python: python/numpy interface to the netCDF C library

netcdf4-python

Python/numpy interface to the netCDF C library.

Build status PyPI package Anaconda-Server Badge DOI

News

For details on the latest updates, see the Changelog.

6/4/2023: Version 1.6.4 released. Now requires certifi to locate SSL certificates - this allows OpenDAP https URLs to work with linux wheels (issue #1246).

3/3/2023: Version 1.6.3 released.

11/15/2022: Version 1.6.2 released. Fix for compilation with netcdf-c < 4.9.0 (issue #1209).
Slicing multi-dimensional variables with an all False boolean index array now returns an empty numpy array (instead of raising an exception - issue #1197).

09/18/2022: Version 1.6.1 released. GIL now released for all C lib calls, set_alignment and get_alignment module functions added to modify/retrieve HDF5 data alignment properties. Added Dataset methods to query availability of optional compression filters.

06/24/2022: Version 1.6.0 released. Support for quantization (bit-grooming and bit-rounding) functionality in netcdf-c 4.9.0 which can dramatically improve compression. Dataset.createVariable now accepts dimension instances (instead of just dimension names). 'compression' kwarg added to Dataset.createVariable to support szip as well as new compression algorithms available in netcdf-c 4.9.0 through compression plugins (such as zstd, bzip2 and blosc). Working arm64 wheels for Apple M1 Silicon now available on pypi.

10/31/2021: Version 1.5.8 released. Fix Enum bug, add binary wheels for aarch64 and python 3.10.

6/22/2021: Version 1.5.7 released. Fixed OverflowError on Windows when reading data with dimension sizes greater than 2**32-1. Masked arrays no longer returned for vlens.

2/15/2021: Version 1.5.6 released. Added Dataset.fromcdl and Dataset.tocdl, which require ncdump and ncgen utilities to be in $PATH. Removed python 2.7 support.

12/20/2020: Version 1.5.5.1 released. Updated binary wheels for OSX and linux that link latest netcdf-c and hdf5 libs.

12/01/2020: Version 1.5.5 released. Update license wording to be consistent with MIT license.

07/23/2020: Version 1.5.4 released. Now requires numpy >= 1.9.

10/27/2019: Version 1.5.3 released. Fix for issue #972, plus binary wheels for python 3.8.

09/03/2019: Version 1.5.2 released. Bugfixes, no new features.

05/06/2019: Version 1.5.1.2 released. Fixes another slicing regression (issue #922)) introduced in the 1.5.1 release.

05/02/2019: Version 1.5.1.1 released. Fixes incorrect __version__ module variable in 1.5.1 release, plus a slicing bug (issue #919)).

04/30/2019: Version 1.5.1 released. Bugfixes, no new features.

04/02/2019: Version 1.5.0.1 released. Binary wheels for macos x and linux rebuilt with netcdf-c 4.6.3 (instead of 4.4.1.1). Added read-shared capability for faster reads of NETCDF3 files (mode='rs').

03/24/2019: Version 1.5.0 released. Parallel IO support for classic file formats added using the pnetcdf library (contribution from Lars Pastewka, pull request #897).

03/08/2019: Version 1.4.3.2 released. Include missing membuf.pyx file in source tarball. No need to update if you installed 1.4.3.1 from a binary wheel.

03/07/2019: Version 1.4.3.1 released. Fixes bug in implementation of NETCDF4_CLASSIC parallel IO support in 1.4.3.

03/05/2019: Version 1.4.3 released. Issues with netcdf-c 4.6.2 fixed (including broken parallel IO). set_ncstring_attrs() method added, memoryview buffer now returned when an in-memory Dataset is closed.

10/26/2018: Version 1.4.2 released. Minor bugfixes, added Variable.get_dims() method and master_file kwarg for MFDataset.__init__.

08/10/2018: Version 1.4.1 released. The old slicing behavior (numpy array returned unless missing values are present, otherwise masked array returned) is re-enabled via set_always_mask(False).

05/11/2018: Version 1.4.0 released. The netcdftime package is no longer included, it is now a separate package dependency. In addition to several bug fixes, there are a few important changes to the default behaviour to note:

  • Slicing a netCDF variable will now always return masked array by default, even if there are no masked values. The result depended on the slice before, which was too surprising. If auto-masking is turned off (with set_auto_mask(False)) a numpy array will always be returned.
  • _FillValue is no longer treated as a valid_min/valid_max. This was too surprising, despite the fact the thet netcdf docs attribute best practices suggests that clients should to this if valid_min, valid_max and valid_range are not set.
  • Changed behavior of string attributes so that nc.stringatt = ['foo','bar'] produces an vlen string array attribute in NETCDF4, instead of concatenating into a single string (foobar). In NETCDF3/NETCDF4_CLASSIC, an IOError is now raised, instead of writing foobar.
  • Retrieved compound-type variable data now returned with character array elements converted to numpy strings (issue #773). Works for assignment also. Can be disabled using set_auto_chartostring(False). Numpy structured array dtypes with 'SN' string subtypes can now be used to define netcdf compound types in createCompoundType (they get converted to ('S1',N) character array types automatically).
  • valid_min, valid_max, _FillValue and missing_value are now treated as unsigned integers if _Unsigned variable attribute is set (to mimic behaviour of netcdf-java). Conversion to unsigned type now occurs before masking and scale/offset operation (issue #794)

11/01/2017: Version 1.3.1 released. Parallel IO support with MPI! Requires that netcdf-c and hdf5 be built with MPI support, and mpi4py. To open a file for parallel access in a program running in an MPI environment using mpi4py, just use parallel=True when creating the Dataset instance. See examples/mpi_example.py for a demonstration. For more info, see the tutorial section.

9/25/2017: Version 1.3.0 released. Bug fixes for netcdftime and optimizations for reading strided slices. encoding kwarg added to Dataset.__init__ and Dataset.filepath to deal with oddball encodings in filename paths (sys.getfilesystemencoding() is used by default to determine encoding). Make sure numpy datatypes used to define CompoundTypes have isalignedstruct flag set to avoid segfaults - which required bumping the minimum required numpy from 1.7.0 to 1.9.0. In cases where missing_value/valid_min/valid_max/_FillValue cannot be safely cast to the variable's dtype, they are no longer be used to automatically mask the data and a warning message is issued.

6/10/2017: Version 1.2.9 released. Fixes for auto-scaling and masking when _Unsigned and/or valid_min, valid_max attributes present. setup.py updated so that pip install works if cython not installed. Now requires setuptools version 18.0 or greater.

6/1/2017: Version 1.2.8 released. From Changelog:

  • recognize _Unsigned attribute used by netcdf-java to designate unsigned integer data stored with a signed integer type in netcdf-3 issue #656.
  • add Dataset init memory parameter to allow loading a file from memory pull request #652, issue #406 and issue #295.
  • fix for negative times in num2date issue #659.
  • fix for failing tests in numpy 1.13 due to changes in numpy.ma issue #662.
  • Checking for _Encoding attribute for NC_STRING variables, otherwise use 'utf-8'. 'utf-8' is used everywhere else, 'default_encoding' global module variable is no longer used. getncattr method now takes optional kwarg 'encoding' (default 'utf-8') so encoding of attributes can be specified if desired. If _Encoding is specified for an NC_CHAR ('S1') variable, the chartostring utility function is used to convert the array of characters to an array of strings with one less dimension (the last dimension is interpreted as the length of each string) when reading the data. When writing the data, stringtochar is used to convert a numpy array of fixed length strings to an array of characters with one more dimension. chartostring and stringtochar now also have an 'encoding' kwarg. Automatic conversion to/from character to string arrays can be turned off via a new set_auto_chartostring Dataset and Variable method (default is True). Addresses issue #654
  • Cython >= 0.19 now required, _netCDF4.c and _netcdftime.c removed from repository.

1/8/2017: Version 1.2.7 released. Python 3.6 compatibility, and fix for vector missing_values.

12/10/2016: Version 1.2.6 released. Bug fixes for Enum data type, and _FillValue/missing_value usage when data is stored in non-native endian format. Add get_variables_by_attributes to MFDataset. Support for python 2.6 removed.

12/1/2016: Version 1.2.5 released. See the Changelog for changes.

4/15/2016: Version 1.2.4 released. Bugs in handling of variables with specified non-native "endian-ness" (byte-order) fixed ([issue #554] (#554)). Build instructions updated and warning issued to deal with potential backwards incompatibility introduced when using HDF5 1.10.x (see Unidata/netcdf-c/issue#250).

3/10/2016: Version 1.2.3 released. Various bug fixes. All text attributes in NETCDF4 formatted files are now written as type NC_CHAR, unless they contain unicode characters that cannot be encoded in ascii, in which case they are written as NC_STRING. Previously, all unicode strings were written as NC_STRING. This change preserves compatibility with clients, like Matlab, that can't deal with NC_STRING attributes. A setncattr_string method was added to force attributes to be written as NC_STRING.

1/1/2016: Version 1.2.2 released. Mostly bugfixes, but with two new features.

  • support for the new NETCDF3_64BIT_DATA format introduced in netcdf-c 4.4.0. Similar to NETCDF3_64BIT (now NETCDF3_64BIT_OFFSET), but includes 64 bit dimension sizes (> 2 billion), plus unsigned and 64 bit integer data types. Uses the classic (netcdf-3) data model, and does not use HDF5 as the underlying storage format.

  • Dimension objects now have a size attribute, which is the current length of the dimension (same as invoking len on the Dimension instance).

The minimum required python version has now been increased from 2.5 to 2.6.

10/15/2015: Version 1.2.1 released. Adds the ability to slice Variables with unsorted integer sequences, and integer sequences with duplicates.

9/23/2015: Version 1.2.0 released. New features:

7/28/2015: Version 1.1.9 bugfix release.

5/14/2015: Version 1.1.8 released. Unix-like paths can now be used in createVariable and createGroup.

    v = nc.createVariable('/path/to/var1', ('xdim', 'ydim'), float)

will create a variable named 'var1', while also creating the groups 'path' and 'path/to' if they do not already exist.

Similarly,

    g = nc.createGroup('/path/to') 

now acts like mkdir -p in unix, creating groups 'path' and '/path/to', if they don't already exist. Users who relied on nc.createGroup(groupname) failing when the group already exists will have to modify their code, since nc.createGroup will now return the existing group instance. Dataset.__getitem__ was also added. nc['/path/to'] now returns a group instance, and nc['/path/to/var1'] now returns a variable instance.

3/19/2015: Version 1.1.7 released. Global Interpreter Lock (GIL) now released when extension module calls C library for read operations. This speeds up concurrent reads when using threads. Users who wish to use netcdf4-python inside threads should read http://www.hdfgroup.org/hdf5-quest.html#gconc regarding thread-safety in the HDF5 C library. Fixes to setup.py now ensure that pip install netCDF4 with export USE_NCCONFIG=0 will use environment variables to find paths to libraries and include files, instead of relying exclusively on the nc-config utility.

Installation

The easiest way to install is through pip:

pip install netCDF4

or, if you are a user of the Conda package manager,

conda install -c conda-forge netCDF4

Development installation

  • Clone GitHub repository (git clone https://github.com/Unidata/netcdf4-python.git)

  • Make sure numpy and Cython are installed and you have Python 3.7 or newer.

  • Make sure HDF5 and netcdf-4 are installed, and the nc-config utility is in your Unix PATH.

  • Run python setup.py build, then pip install -e ..

  • To run all the tests, execute cd test && python run_all.py.

Documentation

See the online docs for more details.

Usage

Sample iPython notebooks available in the examples directory on reading and writing netCDF data with Python.

More Repositories

1

MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
Python
1,177
star
2

netcdf-c

Official GitHub repository for netCDF-C libraries and utilities.
C
483
star
3

thredds

THREDDS Data Server v4.6
262
star
4

netcdf-fortran

Official GitHub repository for netCDF-Fortran libraries, which depend on the netCDF C library. Install the netCDF C library first.
Fortran
214
star
5

siphon

Siphon - A collection of Python utilities for retrieving atmospheric and oceanic data from remote sources, focusing on being able to retrieve data from Unidata data technologies, such as the THREDDS data server.
Python
209
star
6

awips2

Weather forecasting display and analysis package developed by NWS/Raytheon, released as open source software by Unidata.
Java
161
star
7

python-workshop

A series of Jupyter Notebooks on exploring Unidata technology with Python. See website for more information.
Jupyter Notebook
147
star
8

netcdf-java

The Unidata netcdf-java library
Java
137
star
9

netcdf-cxx4

Official GitHub repository for netCDF-C++ libraries and utilities.
C++
120
star
10

python-training

Notebooks teaching Python for use meteorology and atmospheric and climate sciences.
Jupyter Notebook
119
star
11

python-gallery

Repository of examples showing off the use of Python for meteorology.
Python
86
star
12

IDV

The Integrated Data Viewer (IDV) from Unidata is a framework for analyzing and displaying geoscience data.
Java
77
star
13

cftime

Time-handling functionality from netcdf4-python.
Python
71
star
14

gempak

Analysis and product generation for meteorological data.
C
67
star
15

tomcat-docker

Security-hardened Tomcat container for thredds-docker and ramadda-docker
Dockerfile
62
star
16

tds

THREDDS Data Server
Java
58
star
17

UDUNITS-2

API and utility for arithmetic manipulation of units of physical quantities
C
58
star
18

online-python-training

Repo for materials associated with the Online Python Training (OPT) project
CSS
50
star
19

LDM

The Unidata Local Data Manager (LDM) system includes network client and server programs designed for event-driven data distribution, and is the fundamental component of the Unidata Internet Data Distribution (IDD) system.
C
41
star
20

python-awips

A framework for querying AWIPS meteorological datasets from an EDEX Data Server.
Python
36
star
21

thredds-docker

Dockerized THREDDS
Dockerfile
30
star
22

cloudstream

Docker-based framework for Application Streaming
Shell
28
star
23

HurricaneTracker

Hurricane Track Visualization in Python
Python
18
star
24

rosetta

ρ΢ητα β‡’ rosetta
Java
17
star
25

science-gateway

Unidata Science Gateway
TeX
17
star
26

pyCWT

Continuous Wavelet Transform Library for Python
Python
16
star
27

jj2000

Fork of jpeg2k code from https://code.google.com/p/jj2000/.
Java
16
star
28

compression

Provide a standard source set (and build) for various compression libraries
C
13
star
29

ldm-docker

Dockerized LDM
Tcl
12
star
30

ldm-alchemy

Python tools to handle LDM data feeds and convert to other formats.
Python
12
star
31

CloudAWIPS

AWIPS CAVE Streaming in a CentOS 7 Virtual Environment
Shell
10
star
32

metpy-mondays

Jupyter Notebook
9
star
33

ttm

Provide a reference implementation for the TTM programming language.
C
9
star
34

git-recipes

Useful Git recipes
8
star
35

ncWMS

Snapshots of ncWMS used by TDS
Java
8
star
36

FMTP

File Multicast Transfer Protocol
C++
8
star
37

unidata-users-workshop

Unidata Users Workshop
8
star
38

threddsIso

A THREDDS Data Server extension which generates NCML, a metadata rubric, and ISO 19115.
XSLT
7
star
39

EC-netCDF-CF

EarthCube: Advancing netCDF-CF Project
7
star
40

yax

The goal of the yax project is to allow the use of YACC (Gnu Bison actually) to parse/process XML documents.
Python
7
star
41

station-lists

Lists of locations of weather stations for shared use by other projects.
C
6
star
42

netcdf

NetCDF Users Group (NUG)
Makefile
6
star
43

users-workshop-2023

Repo covering Jupyter Notebook resources for Unidata's 2023 triennial meeting held in Boulder, Colorado
Jupyter Notebook
6
star
44

TdsConfig

Contents of TDS configuration directories for several variants including a TDS serving all Unidata IDD data
XSLT
6
star
45

metpy-analysis

Materials for the 2-day course on MetPy for Quantitative Analysis of Meteorological Data
Jupyter Notebook
6
star
46

metpy-ams-2023

Materials for the 2023 AMS short course "MetPy for your Data Analyzing Meteorological Observations in Python"
Jupyter Notebook
5
star
47

cloudidv

Repository for the Cloud-Based IDV
Python
5
star
48

pyaos-ams-2021

Jupyter Notebook
5
star
49

netCDF-Perl

Perl interface to the (deprecated) netCDF 2 API
M4
5
star
50

pyaos-ams-2020

Unidata AMS 2020 Student Conference PyAOS Workshop
Jupyter Notebook
5
star
51

docker-nctests

Docker configuration files for building netCDF regression testing containers.
Shell
5
star
52

netCDF-Decoders

Routines that encode meteorological data in netCDF format
C
5
star
53

Unidata-Dockerfiles

Unidata Dockerfiles
HTML
4
star
54

WorldWeatherSymbol_font

Building a TTF font from WMO weather symbols in SVG format
4
star
55

tdm-docker

Dockerized TDM
Shell
4
star
56

sruth

Java
4
star
57

awips2-core

Java
3
star
58

Garp

GARP (GEMPAK Analysis and Rendering Program)
C
3
star
59

drilsdown

Drawing Rich Integrated Lat-lon- time Samples from Datasets Online into Working Notebooks
Jupyter Notebook
3
star
60

jpattern

The goal of the jpattern project is to provide a reference Java implementation of the Snobol4 primitives as implemented by Robert Dewar in Ada.
Java
3
star
61

python-readiness

Materials for Unidata's Python Readiness workshop series equipping students with skills for their coursework and research.
Jupyter Notebook
2
star
62

awips2-ncep

Java
2
star
63

GEMPAK-Tables

Makefile
2
star
64

UnidataRadarApp

Unidata Radar App
Java
2
star
65

awips-ml

Python
2
star
66

uncc-workshop-2020

Supporting materials for the 2020 Unidata workshop at UNC Charlotte
Jupyter Notebook
2
star
67

cloudcontrol

CloudControl is a web-based dashboard which provides administrative controls to deploy and manage Docker images in the cloud.
Java
2
star
68

awips2-goesr

AWIPS GOES-R Plugins
Java
2
star
69

rtstats

Unidata rtstats revamp
Python
2
star
70

metpy-bams-2022

Scripts used to generate images for the MetPy 2022 BAMS publication
Jupyter Notebook
2
star
71

Wave

Weather Analysis and Visualization Environment
Python
2
star
72

awips2-gemlibs

GEMPAK and NSHARP libraries for AWIPS II
C
2
star
73

github-utils

Utility scripts using GitHub's REST API.
Python
2
star
74

awips2-hazards

AWIPS Hazard Services Plugins
Java
1
star
75

dcredbook-util

C Shell scripts to output NWS Redbook graphics to GIF, PostScript and Vector Graphic files.
Shell
1
star
76

awips2-tools

AWIPS II Automation Tools provided by the National Weather Service
Shell
1
star
77

pygcdm

Python
1
star
78

thredds-test-data

PowerShell
1
star
79

nexus-tools

A set of shell scripts to manage publications within raw repositories on the Unidata nexus artifacts server.
Shell
1
star
80

bison.py

The goal of this project is allow the use of ''Bison'' to generate parsers for Python.
Shell
1
star
81

ucar-intern-pdws

Materials from teaching the UCAR Summer Intern Professional Development Workshop Series event on Python
Jupyter Notebook
1
star
82

awips2-drawing

AWIPS Drawing Tool
Java
1
star
83

awips2-gsd

GSD AWIPS Plugins
Java
1
star
84

unidata-gempak-workshop

Scripts made available for the Unidata GEMPAK training workshop
Shell
1
star
85

awips2-data-delivery

Java
1
star
86

awips2-rpm

HTML
1
star
87

unidata.github.io

Basic gh-pages site to point users to our main website
HTML
1
star
88

awips2-ogc

OGC AWIPS Plugins
Java
1
star
89

pyaos-ams-2023

Materials for the AMS 2023 Student Conference Python Workshop.
Jupyter Notebook
1
star
90

ou-workshop-2020

Supporting materials for Unidata 2020 workshop at OU.
Jupyter Notebook
1
star
91

ast.obsolete

The goal of the ast system is provide a pure Java implementation of the Google protobuf system.
Shell
1
star
92

thredds-performance-tests

Python
1
star