FileTools

About the FileTools class

The WaveBlocks Project

@author: R. Bourquin @copyright: Copyright (C) 2010, 2011, 2012 R. Bourquin @license: Modified BSD License

Class documentation

The WaveBlocks Project

This file contains various functions for finding and retrieving the files that contain parameter settings and simulation results. Note: The terms ‘path’ and ‘ID’ are used as synonyms here. Each simulation ID is just the basename of the path or the configuration file.

@author: R. Bourquin @copyright: Copyright (C) 2010, 2011 R. Bourquin @license: Modified BSD License

FileTools.compare_by(namea, nameb, pattern, ldel='[', mdel='=', rdel=']', as_string=True)[source]

Compare two simulation IDs with respect to a (numerical) value in the ID.

Parameters:
  • namea – The first name in the comparison
  • nameb – The second name in the comparison
  • pattern – The pattern whose (numerical) value is used for sorting
  • ldel – Left delimiter of the pattern
  • mdel – Middle delimiter of the pattern
  • rdel – Right delimiter of the pattern
  • as_string – Determines if the values for pattern get converted to floats
Returns:

A boolean answer if the IDs are the same w.r.t the pattern.

FileTools.gather_all(stringlist, pattern)[source]

Collects all simulation IDs which contain a specific pattern from a given list.

Parameters:
  • stringlist – A list with the simulation IDs
  • pattern – The pattern
Returns:

A list of simulation IDs that contain the given pattern.

FileTools.get_max_by(stringlist, pattern, ldel='[', mdel='=', rdel=']', as_string=False)[source]

Get the maximum of a list with simulation IDs with respect to a (numerical) value in the ID.

Parameters:
  • stringlist – A list with the simulation IDs
  • pattern – The pattern whose (numerical) value is used for sorting
  • ldel – Left delimiter of the pattern
  • mdel – Middle delimiter of the pattern
  • rdel – Right delimiter of the pattern
  • as_string – Determines if the values for pattern get converted to floats
Returns:

A sorted list of simulation IDs.

Note

This is just a simple convenience function so that the user needs not to remember if the sort order is ascending or descending which plays no role for iteration.

FileTools.get_min_by(stringlist, pattern, ldel='[', mdel='=', rdel=']', as_string=False)[source]

Get the minimum of a list with simulation IDs with respect to a (numerical) value in the ID.

Parameters:
  • stringlist – A list with the simulation IDs
  • pattern – The pattern whose (numerical) value is used for sorting
  • ldel – Left delimiter of the pattern
  • mdel – Middle delimiter of the pattern
  • rdel – Right delimiter of the pattern
  • as_string – Determines if the values for pattern get converted to floats
Returns:

A sorted list of simulation IDs.

Note

This is just a simple convenience function so that the user needs not to remember if the sort order is ascending or descending which plays no role for iteration.

FileTools.get_number_simulations(path)[source]

Get the number of simulations at hand below the given path.

Parameters:path – The path under which we search for a output file.
Returns:The number of simulations result directories.
FileTools.get_parameters_file(path)[source]

Search for a configuration file containing the simulation parameters under a given path.

Parameters:path – The path under which we search for a configuration file.
Returns:The path (filename) of the configuration file.

Note

In case there are more than one .py file under the given path we just return the first one found!

FileTools.get_result_dirs(path)[source]

Lists all simulations (IDs) that can be found under the given path.

Parameters:path – The filesystem path under which we search for simulations.
Returns:A list of simulation IDs.
FileTools.get_results_file(path)[source]

Search for a file containing the simulation results under a given path.

Parameters:path – The path under which we search for a output file.
Returns:The path (filename) of the output file.

Note

In case there are more than one .hdf5 file under the given path we just return the first one found!

FileTools.group_by(stringlist, pattern, ldel='[', mdel='=', rdel=']', as_string=True)[source]

Groups simulation IDs with respect to a pattern.

Parameters:
  • stringlist – A list with the simulation IDs
  • pattern – The pattern used for grouping
  • ldel – Left delimiter of the pattern
  • mdel – Middle delimiter of the pattern
  • rdel – Right delimiter of the pattern
  • as_string – Determines if the values for pattern get converted to floats. Not used here.
Returns:

A list of groups of simulation IDs.

FileTools.intersect_by(lista, listb, pattern, ldel='[', mdel='=', rdel=']', as_string=True)[source]

Find the intersection of two lists containing simulation IDs.

Parameters:
  • lista – A first list with the simulation IDs
  • listb – A second list with the simulation IDs
  • pattern – The pattern whose numerical value is used for sorting
  • ldel – Left delimiter of the pattern
  • mdel – Middle delimiter of the pattern
  • rdel – Right delimiter of the pattern
  • as_string – Determines if the values for pattern get converted to floats
Returns:

A sorted list of simulation IDs.

FileTools.name_contains(name, pattern)[source]

Checks if a simulation ID contains a given pattern.

Parameters:
  • name – The full simulation ID.
  • pattern – The pattern in question.
Returns:

A boolean answer.

FileTools.sort_by(stringlist, pattern, ldel='[', mdel='=', rdel=']', as_string=False)[source]

Sorts simulation IDs with respect to a (numerical) value in the ID.

Parameters:
  • stringlist – A list with the simulation IDs
  • pattern – The pattern whose (numerical) value is used for sorting
  • ldel – Left delimiter of the pattern
  • mdel – Middle delimiter of the pattern
  • rdel – Right delimiter of the pattern
  • as_string – Determines if the values for pattern get converted to floats
Returns:

A sorted list of simulation IDs.

Table Of Contents

Previous topic

IOM_plugin_wavepacket

Next topic

Spawner

This Page