fluiddyn.util.serieofarrays

Serie of arrays

Provides classes to iterate over numbered files in a directory:

class fluiddyn.util.serieofarrays.SerieOfArrays(path)[source]

Bases: object

Serie of arrays used for post-processing.

Parameters:
pathstr

The path of the base directory or of a file example.

Attributes:
pathstr

The path of the base directory.

class fluiddyn.util.serieofarrays.SerieOfArraysFromFiles(path, slicing=None)[source]

Bases: SerieOfArrays

Serie of arrays saved in files (images, netcdf, etc.).

Parameters:
pathstr

The path of the base directory or of a file example.

slicingNone or iterable of iterables or str

Iterable of slides (start, stop, step).

Can also be a string of the form “0:2:6, 1” (in this case for two indexes).

Attributes:
path_dirstr

The path of the base directory.

get_slicing_tuples/set_slicing_tupleslist of tuples

Lists of slicing tuples “(start, stop, step)” (one for each index). This list can be changed to loop over different sets of files.

Notes

An instance of SerieOfArraysFromFiles is an iterable and provides other iterables.

Use the function set_slicing_tuples() to specify the files over which iterate.

set_slicing_tuples_from_str(str_slices)[source]

Set slicing_tuples from a string.

get_arrays()[source]

Get the arrays on the serie.

get_name_files()[source]

Get the names of the files of the serie.

get_name_arrays()[source]

Get the name of the arrays of the serie.

get_array_from_name(name)[source]

Get the array from its name.

get_array_from_indices(*indices)[source]

Get an array from its indices.

Parameters:
*indices

As many indices as used in the serie. For example with names of the form ‘im100a.png’, 2 indices are needed.

get_tuples_indices()[source]

Get a list of tuples containing the indices computed from self._slicing_tuples

get_indices_from_index(index)[source]

Get indices from a flatten index

get_array_from_index(index)[source]

Get the ith array of the serie.

Parameters:
index: int

Index of the array, for example 0 to get the first array.

get_path_all_files()[source]

Get all paths found from path_dir and base_name.

get_path_files()[source]

Get all paths of the serie.

If the serie is formed from arrays in one file, only one path is given.

get_path_arrays()[source]

Get all paths of the arrays of the serie.

If the serie is formed from arrays in one file, len(path) == len(arrays).

get_name_path_arrays()[source]

Iterable returning tuples (name, path)

check_all_files_exist()[source]

Check that all files exist.

check_all_arrays_exist()[source]

Check that all arrays exists.

iter_indices()[source]

Iterator on the indices.

len(indices) == self.nb_indices

iter_name_files()[source]

Iterator on the file names.

iter_name_arrays()[source]

Iterator on the array names.

iter_path_files()[source]

Iterator on the file paths.

iter_arrays()[source]

Iterator on the arrays of the serie.

get_tuple_array_name_from_index(index: int = 0)[source]

Get an array and its name

get_str_for_name_from_idim_idx(idim, idx)[source]

Compute the str corresponding to the index idx for the dimension idim

compute_str_indices_from_indices(*indices)[source]

Compute the string corresponding to the indices.

Parameters:
indices: iterable of int.
compute_name_from_indices(*indices)[source]

Compute a file name from a list of indices.

Parameters:
indices: iterable of int.
compute_indices_from_name(name)[source]

Compute a list of indices from a file name.

Parameters:
name: str

Name of the array.

isfile(path)[source]

Check whether a path or name corresponds to an existing file.

get_slicing_tuples_all_files()[source]

Get nb_indices “slices” (to get all the arrays in the directory).

The “slices” are tuples of size 1 ((start,)), 2 ((start, stop)) or 3 ((start, stop, step)).

get_slicing_tuples()[source]

Get nb_indices “slices” to get all the arrays of the serie.

The “slices” are tuples of size 1 ((start,)), 2 ((start, stop)) or 3 ((start, stop, step)).

set_slicing_tuples(*slicing_tuples)[source]

Set the (nb_indices) “slicing tuples”.

The “slicing tuples” are tuples of size 1 ((start,)), 2 ((start, stop)) or 3 ((start, stop, step)).

get_nb_arrays()[source]

Get the number of arrays in the serie.

get_nb_files()[source]

Get the number of files of the serie.

get_index_slices()

Get nb_indices “slices” to get all the arrays of the serie.

The “slices” are tuples of size 1 ((start,)), 2 ((start, stop)) or 3 ((start, stop, step)).

get_index_slices_all_files()

Get nb_indices “slices” (to get all the arrays in the directory).

The “slices” are tuples of size 1 ((start,)), 2 ((start, stop)) or 3 ((start, stop, step)).

set_index_slices(*slicing_tuples)

Set the (nb_indices) “slicing tuples”.

The “slicing tuples” are tuples of size 1 ((start,)), 2 ((start, stop)) or 3 ((start, stop, step)).

set_index_slices_from_str(str_slices)

Set slicing_tuples from a string.

class fluiddyn.util.serieofarrays.SeriesOfArrays(serie, slicing_tuples_from_indserie=None, ind_start='first', ind_stop=None, ind_step=1)[source]

Bases: object

Series of arrays.

This class can be used to produce series of arrays from a SerieOfArrays.

Parameters:
serie: SerieOfArrays or str
slicing_tuples_from_indserie: str or function

The function has to take an integer and to return an iterable of “slicing tuples” used to compute a file name.

set_index_series(index_series)[source]

Set the indices corresponding to the series.

Parameters:
index_seriessequence of int
get_next_serie()[source]

Get the next serie.

get_serie_from_index(index)[source]

Get a serie from an index.

get_name_all_files()[source]

Get all file names.

get_name_all_arrays()[source]

Get all array names.

Functions

add_depreciated_function(cls, name)

Add a depreciated function like get_index_slices

compute_slices(str_slices)

Return a tuple of slices

get_nb_arrays_in_file(fname)

Classes

SerieOfArrays(path)

Serie of arrays used for post-processing.

SerieOfArraysFromFiles(path[, slicing])

Serie of arrays saved in files (images, netcdf, etc.).

SeriesOfArrays(serie[, ...])

Series of arrays.

SlicingTuplesFromIndexSerie(str_slices, serie)

SlicingTuplesFromIndexSerieAll1By1(serie)

Exceptions

OutOfRangeError

Specific IndexError