sisl.io.sile module

sisl.io.sile.add_sile(ending, cls, case=True, gzip=False, _parent_cls=None)[source]

Public for attaching lookup tables for allowing users to attach files for the IOSile function call

Parameters:

ending : str

The file-name ending, it can be several file endings (.TBT.nc)

cls : BaseSile child

An object that is associated with the respective file. It must be inherited from a BaseSile.

case : bool, (True)

Whether case sensitivity is applicable for determining file.

gzip : bool, (False)

Whether files with .gz endings can be read. This option should only be given to files with ASCII text output. It will automatically call:

>>> add_sile(ending+'.gz',...,gzip=False)

to add the gzipped file to the list of possible files.

sisl.io.sile.get_sile_class(file, *args, **kwargs)[source]

Guess the Sile class corresponding to the input file and return the class

Parameters:

file : str

the file to be quried for a correct Sile object. This file name may contain {<class-name>} which sets cls in case cls is not set. For instance:

water.xyz

will return an XYZSile.

cls : class

In case there are several files with similar file-suffixes you may query the exact base-class that should be chosen. If there are several ``Sile``s with similar file-endings this function returns a random one.

sisl.io.sile.get_sile(file, *args, **kwargs)[source]

Guess the Sile corresponding to the input file and return an open object of the corresponding Sile

Parameters:

file : str

the file to be quried for a correct Sile object. This file name may contain {<class-name>} which sets cls in case cls is not set. For instance:

water.dat{XYZSile}

will read the file water.dat as an XYZSile.

cls : class

In case there are several files with similar file-suffixes you may query the exact base-class that should be chosen. If there are several `Sile`s with similar file-endings this function returns a random one.

sisl.io.sile.get_siles(attrs=[None])[source]

Returns all siles with a specific attribute (or all)

Parameters:

attrs : list of attribute names

limits the returned sile-objects to those that have the given attributes hasattr(sile, attrs)

class sisl.io.sile.BaseSile[source]

Bases: object

Base class for the Siles

Methods

ArgumentParser([parser]) Returns the arguments that may be available for this Sile
ArgumentParser_out([parser]) Appends additional arguments based on the output of the file
read(*args, **kwargs) Generic read method which should be overloaded in child-classes
write(*args, **kwargs) Generic write method which should be overloaded in child-classes
ArgumentParser(parser=None, *args, **kwargs)[source]

Returns the arguments that may be available for this Sile

Parameters:

parser: ArgumentParser

the argument parser to add the arguments to.

ArgumentParser_out(parser=None, *args, **kwargs)[source]

Appends additional arguments based on the output of the file

Parameters:

parser: ArgumentParser

the argument parser to add the arguments to.

read(*args, **kwargs)[source]

Generic read method which should be overloaded in child-classes

Parameters:

**kwargs :

keyword arguments will try and search for the attribute read_ and call it with the remaining **kwargs as arguments.

write(*args, **kwargs)[source]

Generic write method which should be overloaded in child-classes

Parameters:

**kwargs :

keyword arguments will try and search for the attribute write_ and call it with the remaining **kwargs as arguments.

class sisl.io.sile.Sile(filename, mode='r', comment='#')[source]

Bases: sisl.io.sile.BaseSile

Class to contain a file with easy access

Attributes

file File of the current Sile

Methods

ArgumentParser([parser]) Returns the arguments that may be available for this Sile
ArgumentParser_out([parser]) Appends additional arguments based on the output of the file
is_keys(keys) Returns true if isinstance(keys,(list,np.ndarray))
key2case(key, case) Converts str/list of keywords to proper case
keys2case(keys, case) Converts str/list of keywords to proper case
line_has_key(line, key[, case])
line_has_keys(line, keys[, case])
read(*args, **kwargs) Generic read method which should be overloaded in child-classes
readline([comment]) Reads the next line of the file
step_either(keywords[, case]) Steps the file-handle until the keyword is found in the input
step_to(keywords[, case]) Steps the file-handle until the keyword is found in the input
write(*args, **kwargs) Generic write method which should be overloaded in child-classes
file

File of the current Sile

static is_keys(keys)[source]

Returns true if isinstance(keys,(list,np.ndarray))

static key2case(key, case)[source]

Converts str/list of keywords to proper case

static keys2case(keys, case)[source]

Converts str/list of keywords to proper case

static line_has_key(line, key, case=True)[source]
static line_has_keys(line, keys, case=True)[source]
readline(comment=False)[source]

Reads the next line of the file

step_either(keywords, case=True)[source]

Steps the file-handle until the keyword is found in the input

step_to(keywords, case=True)[source]

Steps the file-handle until the keyword is found in the input

class sisl.io.sile.SileCDF(filename, mode='r', lvl=0, access=1, _open=True)[source]

Bases: sisl.io.sile.BaseSile

Class to contain a file with easy access The file format for this file is the NetCDF file format

Attributes

file Filename of the current Sile

Methods

ArgumentParser([parser]) Returns the arguments that may be available for this Sile
ArgumentParser_out([parser]) Appends additional arguments based on the output of the file
isDataset(obj) Return true if obj is an instance of the NetCDF4 Dataset type
isDimension(obj) Return true if obj is an instance of the NetCDF4 Dimension type
isGroup(obj) Return true if obj is an instance of the NetCDF4 Group type
isRoot(obj) Return true if obj is an instance of the NetCDF4 Dataset type
isVariable(obj) Return true if obj is an instance of the NetCDF4 Variable type
iter([group, dimension, variable, levels, root]) Iterator on all groups, variables and dimensions.
read(*args, **kwargs) Generic read method which should be overloaded in child-classes
write(*args, **kwargs) Generic write method which should be overloaded in child-classes

Creates/Opens a SileCDF

Opens a SileCDF with mode and compression level lvl. If mode is in read-mode (r) the compression level is ignored.

The final access parameter sets how the file should be open and subsequently accessed.

  1. means direct file access for every variable read
  2. means stores certain variables in the object.

Attributes

file Filename of the current Sile

Methods

ArgumentParser([parser]) Returns the arguments that may be available for this Sile
ArgumentParser_out([parser]) Appends additional arguments based on the output of the file
isDataset(obj) Return true if obj is an instance of the NetCDF4 Dataset type
isDimension(obj) Return true if obj is an instance of the NetCDF4 Dimension type
isGroup(obj) Return true if obj is an instance of the NetCDF4 Group type
isRoot(obj) Return true if obj is an instance of the NetCDF4 Dataset type
isVariable(obj) Return true if obj is an instance of the NetCDF4 Variable type
iter([group, dimension, variable, levels, root]) Iterator on all groups, variables and dimensions.
read(*args, **kwargs) Generic read method which should be overloaded in child-classes
write(*args, **kwargs) Generic write method which should be overloaded in child-classes
file

Filename of the current Sile

classmethod isDataset(obj)[source]

Return true if obj is an instance of the NetCDF4 Dataset type

This is just a wrapper for isinstance(obj, netCDF4.Dataset).

classmethod isDimension(obj)[source]

Return true if obj is an instance of the NetCDF4 Dimension type

This is just a wrapper for isinstance(obj, netCDF4.Dimension).

classmethod isGroup(obj)[source]

Return true if obj is an instance of the NetCDF4 Group type

This is just a wrapper for isinstance(obj, netCDF4.Group).

classmethod isRoot(obj)

Return true if obj is an instance of the NetCDF4 Dataset type

This is just a wrapper for isinstance(obj, netCDF4.Dataset).

classmethod isVariable(obj)[source]

Return true if obj is an instance of the NetCDF4 Variable type

This is just a wrapper for isinstance(obj, netCDF4.Variable).

iter(group=True, dimension=True, variable=True, levels=-1, root=None)[source]

Iterator on all groups, variables and dimensions.

This iterator iterates through all groups, variables and dimensions in the Dataset

The generator sequence will _always_ be:

  1. Group
  2. Dimensions in group
  3. Variables in group

As the dimensions are generated before the variables it is possible to copy groups, dimensions, and then variables such that one always ensures correct dependencies in the generation of a new SileCDF.

Parameters:

group : bool (True)

whether the iterator yields Group instances

dimension : bool (True)

whether the iterator yields Dimension instances

variable : bool (True)

whether the iterator yields Variable instances

levels : int (-1)

number of levels to traverse, with respect to root variable, i.e. number of sub-groups this iterator will return.

root : str (None)

the base root to start iterating from.

Examples

Script for looping and checking each instance. >>> for gv in self.iter(): >>> if self.isGroup(gv): >>> # is group >>> elif self.isDimension(gv): >>> # is dimension >>> elif self.isVariable(gv): >>> # is variable

class sisl.io.sile.SileBin(filename, mode='r')[source]

Bases: sisl.io.sile.BaseSile

Class to contain a file with easy access The file format for this file is a binary format.

Attributes

file File of the current Sile

Methods

ArgumentParser([parser]) Returns the arguments that may be available for this Sile
ArgumentParser_out([parser]) Appends additional arguments based on the output of the file
read(*args, **kwargs) Generic read method which should be overloaded in child-classes
write(*args, **kwargs) Generic write method which should be overloaded in child-classes

Creates/Opens a SileBin

Opens a SileBin with mode (b). If mode is in read-mode (r).

Attributes

file File of the current Sile

Methods

ArgumentParser([parser]) Returns the arguments that may be available for this Sile
ArgumentParser_out([parser]) Appends additional arguments based on the output of the file
read(*args, **kwargs) Generic read method which should be overloaded in child-classes
write(*args, **kwargs) Generic write method which should be overloaded in child-classes
file

File of the current Sile

exception sisl.io.sile.SileError(value, obj=None)[source]

Bases: exceptions.IOError

Define an error object related to the Sile objects

sisl.io.sile.Sile_fh_open(func)[source]

Method decorator for objects to directly implement opening of the file-handle upon entry (if it isn’t already).

sisl.io.sile.sile_raise_write(self)[source]
sisl.io.sile.sile_raise_read(self)[source]