[ SciPy v1.12.0 Manual  ](../../index.html)

  * [ Installing ](https://scipy.org/install/)
  * [ User Guide ](../../tutorial/index.html)
  * [ API reference ](../index.html)
  * [ Building from source ](../../building/index.html)
  * [ Development ](../../dev/index.html)
  * [ Release notes ](../../release.html)

__ __ __

1.12.0

  * [ __ GitHub  ](https://github.com/scipy/scipy "GitHub")
  * [ __ Twitter  ](https://twitter.com/SciPy_team "Twitter")

__

  * [ scipy ](../main_namespace.html)
  * [ scipy.cluster ](../cluster.html)
  * [ scipy.constants ](../constants.html)
  * [ scipy.datasets ](../datasets.html)
  * [ scipy.fft ](../fft.html)
  * [ scipy.fftpack ](../fftpack.html)
  * [ scipy.integrate ](../integrate.html)
  * [ scipy.interpolate ](../interpolate.html)
  * [ scipy.io ](../io.html)
  * [ scipy.linalg ](../linalg.html)
  * [ scipy.misc ](../misc.html)
  * [ scipy.ndimage ](../ndimage.html)
  * [ scipy.odr ](../odr.html)
  * [ scipy.optimize ](../optimize.html)
  * [ scipy.signal ](../signal.html)
  * [ scipy.sparse ](../sparse.html)
  * [ scipy.spatial ](../spatial.html)
  * [ scipy.special ](../special.html)
  * [ scipy.stats ](../stats.html)

__ On this page

  * ` netcdf_file  `

#  scipy.io.netcdf_file  #

_ class  _ scipy.io.  netcdf_file  (  _ filename  _ , _ mode  =  'r'  _ , _
mmap  =  None  _ , _ version  =  1  _ , _ maskandscale  =  False  _ )  [
[source]
](https://github.com/scipy/scipy/blob/v1.12.0/scipy/io/_netcdf.py#L98-L805) #

    

A file object for NetCDF data.

A  ` netcdf_file  ` object has two standard attributes: _dimensions_ and
_variables_ . The values of both are dictionaries, mapping dimension names to
their associated lengths and variable names to variables, respectively.
Application programs should never modify these dictionaries.

All other attributes correspond to global attributes defined in the NetCDF
file. Global file attributes are created by assigning to an attribute of the
` netcdf_file  ` object.

Parameters  :

    

**filename** string or file-like

    

string -> filename

**mode** {ârâ, âwâ, âaâ}, optional

    

read-write-append mode, default is ârâ

**mmap** None or bool, optional

    

Whether to mmap _filename_ when reading. Default is True when _filename_ is a
file name, False when _filename_ is a file-like object. Note that when mmap is
in use, data arrays returned refer directly to the mmapped data on disk, and
the file cannot be closed as long as references to it exist.

**version** {1, 2}, optional

    

version of netcdf to read / write, where 1 means _Classic format_ and 2 means
_64-bit offset format_ . Default is 1. See [ here
](https://docs.unidata.ucar.edu/nug/current/netcdf_introduction.html#select_format)
for more info.

**maskandscale** bool, optional

    

Whether to automatically scale and/or mask data based on attributes. Default
is False.

Notes

The major advantage of this module over other modules is that it doesnât
require the code to be linked to the NetCDF libraries. This module is derived
from [ pupynere ](https://bitbucket.org/robertodealmeida/pupynere/) .

NetCDF files are a self-describing binary data format. The file contains
metadata that describes the dimensions and variables in the file. More details
about NetCDF files can be found [ here
](https://www.unidata.ucar.edu/software/netcdf/guide_toc.html) . There are
three main sections to a NetCDF data structure:

  1. Dimensions 

  2. Variables 

  3. Attributes 

The dimensions section records the name and length of each dimension used by
the variables. The variables would then indicate which dimensions it uses and
any attributes such as data units, along with containing the data values for
the variable. It is good practice to include a variable that is the same name
as a dimension to provide the values for that axes. Lastly, the attributes
section would contain additional information such as the name of the file
creator or the instrument used to collect the data.