ship.utils.fileloaders package

Submodules

ship.utils.fileloaders.datloader module

Summary:
Factory class for building the AUnits from an ISIS data file. This is used to read and build the parts of the ISIS dat file.
Author:
Duncan Runnacles
Created:
01 Apr 2016
Copyright:
Duncan Runnacles 2016

Todo

There are a few functions in here that should be made protected. This doesn’t really make much difference in Python in terms of encapsulation, but it makes it a bit clearer to any calling scripts that they might be messing with something that they probablly shouldn’t be messing with.

Comments are a bit over the top in this file. Need to go through and decide what is helpful and what is just getting in the way.

Updates:

class DatLoader[source]

Bases: ship.utils.atool.ATool, ship.utils.fileloaders.loader.ALoader

Isis data file (.DAT) I/O methods.

Factory for creating the .DAT file objects. Identifies different section of the .DAT file and creates objects of the different units. Also saves updated file.

All unknown data within the file is contained within UnkownSection units. These read in the text as found and write out as found, with no knowledge of the contents. Effectively bypassing the need to worry about parts that aren’t being used yet.

buildDat(contents, arg_dict={})[source]
createUnknownSection()[source]

Builds unidentified sections from the .DAT file.

All currently un-dealt-with sections of the .DAT file are incorporated into this. Loads in chunks of the file ‘as-is’ and prints them out the same way.

getUnits()[source]

Getter for imported units

Note

Deprecated: Will be removed. Please use self.units directly.

Returns:IsisUnitCollection - The units loaded from the dat file.
loadFile(file_path, arg_dict={})[source]

Loads the ISIS .DAT file.

Splits it into objects for each unit type, initial conditions etc.

This is an epic if-else section for each unit type currently represented.

Needs cleaning up and writing with a bit more style.

Easy to add another unit type, if it’s not currently covered then it will just be collected in the universal ‘UnknownUnit’ and printed back out the same as it came in.

Parameters:

file_path (str) – path to the .dat file to load.

Returns:

units - UnitCollection containing the dat file units or False if

they couldn’t be loaded.

Raises:
  • IOError – If the file cannot be loaded or is empty.
  • AttributeError – if the file is not of an expected type (.dat/.ief).

See also

IsisUnitCollection FactoryClasses

TODO: Decide if the observer style calls are ever going to be needed.
If they aren’t then remove them rather than have them cluttering up the file.
updateSubContents()[source]

Updates the self.units.

Appends the new temp_unit to list of units and resets all the variables.

logger = <logging.Logger object at 0x0534DCF0>

logging references with a __name__ set to this module.

ship.utils.fileloaders.fileloader module

Summary:
Main file loader for the API. This offers convenience methods to make it simple to load any type of file from one place.
Author:
Duncan Runnacles
Created:
01 Apr 2016
Copyright:
Duncan Runnacles 2016

TODO:

Updates:

class FileLoader[source]

Bases: object

loadFile(filepath, arg_dict={})[source]

Load a file from disk.

Parameters:
  • filepath (str) – the path to the file to load.
  • arg_dict={} (Dict) – contains keyword referenced arguments needed by any of the loaders. E.g. the TuflowLoader can take some scenario values.
Returns:

The object created by the individual file loaders. E.g. for .dat files this will be an IsisUnitCollection. See the individual ALoader implementations for details of return types.

Raises:

AttributeError – if the file type is not tcf/dat/ief/ied.

See also

:class:’ALoader’ :class:’IefLoader’ :class:’TuflowLoader’ :class:’DatLoader’

logger = <logging.Logger object>

logging references with a __name__ set to this module.

ship.utils.fileloaders.iefloader module

Summary:
Contains the Factory class for loading and building the Ief object from an ief file at a given path.
Author:
Duncan Runnacles
Created:
01 Apr 2016
Copyright:
Duncan Runnacles 2016

TODO:

Updates:

class IefLoader[source]

Bases: ship.utils.atool.ATool, ship.utils.fileloaders.loader.ALoader

Builds an Ief object.

Contains the details of the ISIS ief file located at the given file path.

Factory class for reading the ISIS ief file into an Ief object that allows for simple access and updating of the ief file.

See also

atool

loadFile(file_path, arg_dict={})[source]

Loads the ief file at the given path.

Parameters:file_path (str) – The path to the ief file.
Returns:Ief file object containing the contents loaded from file.
logger = <logging.Logger object at 0x06FB6FD0>

logging references with a __name__ set to this module.

ship.utils.fileloaders.loader module

Summary:

Abstract base class that should be implemented by all file loading classes in the API.

Contains methods that help file loaders play nicely with the file loading factory and other parts of the API.

Author:
Duncan Runnacles
Created:
01 Apr 2016
Copyright:
Duncan Runnacles 2016

TODO:

Updates:

class ALoader[source]

Bases: object

addWarning(title, msg)[source]

Can be used to store non-deadly errors during load for easy lookup.

The errors/warnings will be added to the warning_store list so that they can be passed on or interogated after the file has been loaded.

This does not take the place of raising actual errors, it’s just for noting anything that might be useful for the caller to know after loading the file.

Parameters:
  • title (str) – the title of the warning.
  • msg (str) – the message body of the warning.
loadFile(filepath, arg_dict={})[source]

Load the file at the given path

Parameters:
  • filepath (str) – the file path to load.
  • arg_dict={} (Dict) – contains keyword referenced arguments needed by any of the loaders. E.g. the TuflowLoader can take some scenario values.

Return:

Raises:NotImplementedError – if subclass does not override this method.

ship.utils.fileloaders.tuflowloader module

class TuflowLoader[source]

Bases: ship.utils.fileloaders.loader.ALoader

buildControlFiles(_load_list, model)[source]

Add TuflowFilepart’s to the correct ControlFile’s.

Loops through the list of TuflowFilePart’s created when parsing the tuflow input files. When it finds a TuflowFilepart containing a reference to a tuflow control file it will recursively call itself and start adding parts to the ControlFile for that type instead. It will either find another control file and, again, make a recursive call, or will finish adding the TuflowFileparts to the ControlFile and drop back into the previous function call (recursive) to continue reading the previous list of TuflowFilepart’s.

getFile(path)[source]

Load the file into the contents list.

Parameters:file_path (str) – path to the required file.
Returns:True if loaded ok, False otherwise.
loadControlFile(model_file)[source]
loadFile(tcf_path, arg_dict={})[source]

Main loader function defined by the ALoader interface.

The presumption with this loader is that a .tcf file (i.e. the root of all tuflow models will be given as a starting point. The rest of the model can then be accessed from there.

loadModel(tcf_path, arg_dict={})[source]

Load a full tuflow model from the given tcf path.

parseDefineLogic(line, parent, key)[source]
parseIfLogic(line, parent, root, key)[source]
tuflow_model = None

TuflowModel class instance

user_variables = None

Any event values that are passed through.

logger = <logging.Logger object at 0x054CC3B0>

logging references with a __name__ set to this module.

Module contents