Wrapper for netCDF readers.


Convert file into a NetcdfReader instance. Returns reader, closeit where closeit is set to True if we have to close the file before leaving the procedure.

class NetcdfReader(path)[source]

Bases: object

Wraps and extends netCDF4.Dataset. Read only mode. Supports with statements.

Additional documentation available at:

Open the Netcdf file specified by path (read mode).


alias of NetcdfReaderError

read_dimvalue(dimname, path='/')[source]

Returns the value of a dimension.

read_keys(keys, dict_cls=<class 'monty.collections.AttrDict'>, path='/')[source]

Read a list of variables/dimensions from file. If a key is not present the corresponding entry in the output dictionary is set to None.

read_value(varname, path='/', cmode=None, default=<class ''>)[source]

Returns the values of variable with name varname in the group specified by path.

  • varname – Name of the variable
  • path – path to the group.
  • cmode – if cmode==”c”, a complex ndarrays is constructed and returned (netcdf does not provide native support from complex datatype).
  • default – read_value returns default if varname is not present.

numpy array if varname represents an array, scalar otherwise.

read_variable(varname, path='/')[source]

Returns the variable with name varname in the group specified by path.


List of variable names stored in the group specified by path.


Navigate all the groups in the file starting from top. If top is None, the root group is used.

class ETSF_Reader(path)[source]


This object reads data from a file written according to the ETSF-IO specifications.

We assume that the netcdf file contains at least the crystallographic section.

Open the Netcdf file specified by path (read mode).


Chemical symbols char [number of atom species][symbol length].


Read ixc from an Abinit file. Return XcFunc object.

read_structure(cls=<class 'pymatgen.core.structure.Structure'>)[source]

Returns the crystalline structure.


Returns the type index from the chemical symbol. Note python convention.

structure_from_ncdata(ncdata, site_properties=None, cls=<class 'pymatgen.core.structure.Structure'>)[source]

Reads and returns a pymatgen structure from a NetCDF file containing crystallographic data in the ETSF-IO format.

  • ncdata – filename or NetcdfReader instance.
  • site_properties – Dictionary with site properties.
  • cls – The Structure class to instanciate.