ship.tuflow.datafiles package

Submodules

ship.tuflow.datafiles.datafileloader module

Summary:

Deals with loading all data from ADataObject type files.

This process can get quite messy so it seems sensible to have a separate factory to deal with it.

See Also:
ADataObject, TmfDataObject, TmfCsvDataObject, DcDataObject
Author:
Duncan Runnacles
Created:
01 Apr 2016
Copyright:
Duncan Runnacles 2016

Todo

Need to add a subfile loader for the materials csv file loader.

This module needs some cleaning up still. There is quite a bit of repeated code around that could be pulled out into module level functions and used by all of the loader.

Updates:

hasCommentOnlyLine(line, comment_types)[source]

Find if line contains only comments

Parameters:
  • line (string) – line to check for comment only status.
  • comment_types (list) – the possible comment characters to check for.
Returns:

String containing line if True or False if not.

loadDataFile(datafile, args_dict={})[source]

Factory function for creating DataFileObject type objects.

Loads the contents of the DataFileObject based on the composition of the given object and returns the newly created DataFileObject of that type.

The args_dict is a dict of key-value pairs where the key represents a placeholder used within one of the data files and the value reprents the variables that should be used to replace that value. This is common in bc_dbase file for instance where ‘__event__’ may be used as a place holder with BC Event Text and BC Event Name used in the control files to define what should be used. Other options are the use of scenario and event definitions. Within these BC Event Source can be defined to associate certain placeholders with values e.g.:

Define Event == 8hr
    BC Event Source == ~DUR~ | 8hr
    BC Database == ..c_dbase\my_bcdbase.csv
End Define

These are stored in the tuflow model when loaded and can be passed when loading data files to use.

Parameters:
  • datafile (TuflowFile) – FilePart to create the DataFileObject from.
  • args_dict={} (dict) – This is a dictionary of keywords and associated values that can be used to identify and replace placeholders in the source file names or column names within data files. NOTE CURRENTLY NOT USED.
Returns:

of type identified from the composition of the given

TuflowFile object.

Return type:

DataFileObject

Note

The args_dict is CURRENTLY NOT USED, but will be supported soon.

See also

TuflowFile DataFileObject

readBcFile(datafile, args_dict={})[source]

Loads the contents of the BC Database file refernced by datafile.

Loads the data from the file referenced by the given TuflowFile object into a :class:’rowdatacollection’ and a list of comment only lines.

Parameters:datafile (TuflowFile) – TuflowFile object with file details.
Returns:rowdatacollection, comment_lines(list).
Return type:tuple

See also

:class:’rowdatacollection’.

readMatCsvFile(datafile, args_dict={})[source]

Loads the contents of the Materials CSV file referenced by datafile.

Loads the data from the file referenced by the given TuflowFile object into a :class:’rowdatacollection’ and a list of comment only lines.

Parameters:datafile (TuflowFile) – TuflowFile object with file details.
Returns:rowdatacollection, comment_lines(list).
Return type:tuple

See also

:class:’rowdatacollection’.

readMatSubfile(main_datafile, filename, header_list, args_dict)[source]
readTmfFile(datafile)[source]

Loads the contents of the Materials CSV file referenced by datafile.

Loads the data from the file referenced by the given TuflowFile object into a :class:’rowdatacollection’ and a list of comment only lines.

Parameters:datafile (TuflowFile) – TuflowFile object with file details.
Returns:rowdatacollection, comment_lines(list).
Return type:tuple

See also

:class:’rowdatacollection’.

readXsFile(datafile)[source]

Loads the contents of the estry 1d_xs file reference by datafile.

ship.tuflow.datafiles.datafileobject module

Summary:

Used for accessing files that contain data and links to other files. contains a factory method that will select the correct concrete implementation of ADataFileObject for the user based on the contents of the DataFile variables given as a parameter.

Contains the abstract ADataFileObject class and concrete implmentations.

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

TODO:

Updates:

class ADataFileObject(row_collection, file_part, comment_lines=[], args_dict={})[source]

Bases: object

Abstract superclass for all data file objects.

All classes that deal with reading and writing data from the DataFile derivation of TuflowFilePart should create an implementation of this class.

Loading of the data should be separated into the DataFileLoader module to reduce the complexity of these classes.

Primarily these classes are for data access and handling although they also must contain a method for writing the data back to file.

See also

DataFile DataFileLoader

addSubfile(subfile)[source]

Add a subfile to this object.

Subfiles are separate data files that are references by the contents of an ADatafileObject instance.

They should be derived from ADatafileSubFile.

Parameters:subfile (ADataFileSubfile) – subfile to add.
Raises:TypeError if subfile is not of type ADataFileSubfile

See also

ADataFileSubfile

changeRoot(root)[source]

Updates the root variable in the path_holder

Parameters:root (str) – new root directory.
dataObjectAsList(key)[source]

Returns the a list of the data associated with the given key.

The Keys for each class are usually defined by a related enum. These should be used when calling this function.

Parameters:key (int) – values associated with the different data types.
Returns:containing the data stipulated by the given key.
Return type:list
Raises:KeyError – if key value does not exist.
getAllPaths(include_this=True, name_only=False, resolve_paths=True)[source]

Get all paths held by this object

Parameters:
  • include_this=True (bool) – if True it includes the path of this DatafileObject.
  • name_only=False (bool) – if True only the filename will be returned.
  • resolver_name=True (bool) – if True any placeholders in the filename will be replaced with the value set in the EventSourceData.
Returns:

list - containing all the filepaths referenced by this object.

getDataObject(key)[source]

Returns the ADataObject associated with the given key.

The Keys for each class are usually defined by a related enum. These should be used when calling this function.

Parameters:key (int) – values associated with the different data types.
Returns:containing the data stipulated by the given key.
Return type:ADataObject
Raises:KeyError – if key value does not exist.
resolveEvtSrc(values)[source]

Replace placeholders with values in the given list.

Placeholder values can be used in most of the data files to define filenames, variables, etc. This method will replace the placeholder with the corresponding value if found in the EventSourceData.

Parameters:value (list) – str’s to replace placeholders in.
saveData(plus_subfiles=False)[source]

Save the current state of the data contained by this instance.

Unless plus_subfiles == False all subfile data will be saved as well.

Parameters:
  • plus_subfiles=False (bool) – if True all associated subfile will be
  • to their current state as well. (saved) –
Raises:

IOError – if there is a problem writing to file.

class ADataFileSubfile(path_holder, row_collection, filename, comment_lines=[], args_dict={})[source]

Bases: object

Abstract super class for and ADataFileObject contained subfiles.

Any files that are referenced by the ADataFileObject and which need to be read in should be included in the ADataFileObject’s self.subfiles list and be derived from this class.

class BcDataObject(row_collection, file_part, comment_lines, args_dict={})[source]

Bases: ship.tuflow.datafiles.datafileobject.ADataFileObject

Concrete implementation of the ADataFileObject class. Reads/Writes the data in tuflow boundary condition database csv files.

getAllPaths(include_this=True, name_only=False, resolve_paths=True)[source]

Get all paths held by this object

Overrides superclass method.

Args:

Return:

class BcEnum[source]

Bases: object

Enum for accessing data in BcDataObject

ADD_COL_1 = 4
ADD_COL_2 = 6
COLUMN1 = 2
COLUMN2 = 3
COLUMN_3 = 7
COLUMN_4 = 8
ITERABLE = range(0, 9)
MULT_COL = 5
NAME = 0
SOURCE = 1
class DataFileSubfileMat(path_holder, row_collection, comment_lines, filename, head1_location, head2_location)[source]

Bases: ship.tuflow.datafiles.datafileobject.ADataFileSubfile

Concrete instance of ADataFileSubfile

class MatCsvDataObject(row_collection, file_part, comment_lines, args_dict={})[source]

Bases: ship.tuflow.datafiles.datafileobject.ADataFileObject

Concrete implementation of the ADataFileObject class. Reads/Writes the data in tuflow Materials csv files.

class MatCsvEnum[source]

Bases: object

Enum for accessing data in MatCsvDataObject

CL = 10
HAZARD_ID = 11
HEADER1 = 7
HEADER2 = 8
ID = 0
IL = 9
ITERABLE = range(0, 12)
MANNINGS = 1
N1 = 2
N2 = 4
SUBFILE_NAME = 6
Y1 = 3
Y2 = 5
class SubfileMatEnum[source]

Bases: object

Enum for use in accessing data in DataFileSubfileMat

DEPTH = 1
ITERABLE = range(0, 9)
MANNINGS = 2
NAME = 0
class TmfDataObject(row_collection, file_part, comment_lines)[source]

Bases: ship.tuflow.datafiles.datafileobject.ADataFileObject

Concrete implementation of the ADataFileObject class.

Used for reading/writing tuflow .tmf materials files.

class TmfEnum[source]

Bases: object

Enum for accessing data in TmfDataObject

CONTINUING_LOSS = 3
FRACTION_IMPERVIOUS = 10
ID = 0
INITIAL_LOSS = 2
ITERABLE = range(0, 11)
MANNINGS = 1
MANNINGS_1 = 5
MANNINGS_2 = 7
MANNINGS_DEPTH_1 = 4
MANNINGS_DEPTH_2 = 6
RESERVED = 8
SOIL_REDUCTION_FACTOR = 9
class XsDataObject(row_collection, file_part, comment_lines=[])[source]

Bases: ship.tuflow.datafiles.datafileobject.ADataFileObject

class XsEnum[source]

Bases: object

Enum for accessing data in CrossSectionDataObject.

COLUMN_1 = 3
COLUMN_2 = 4
COLUMN_3 = 5
COLUMN_4 = 6
COLUMN_5 = 7
COLUMN_6 = 8
FLAGS = 2
ITERABLE = range(0, 12)
SKEW = 11
SOURCE = 0
TYPE = 1
Z_INCREMENT = 9
Z_MAXIMUM = 10

Module contents