ocmw.dataproc.otm_extraction module

Open Telemac-Mascaret data extraction functions.

InitialiseFile

Initialise Selafin file for reading, inlcuding setting up mesh search tree.

OTMDate2Num

Convert OTM timestamp into a python date number

OTMDate2Str

Convert OTM timestamp to date strings

genOTMTimeStamps

Convert OTM timestamp information into an array of python date numbers.

getSlfTriangle

Get the triangular element and node the contain the point (LocX,LocY) from SLF file handle

getSlfNodesWeights

Get the barycentric weigthing factors to interpolate from element nodes onto the point (LocX,LocY) from Selafin file

getMeshTriangle

Get the triangular element and node the contain the point (LocX,LocY) from mesh dictionary

getMeshNodesWeights

Get the barycentric weigthing factors to interpolate from element nodes onto the point (LocX,LocY) from mesh dictionary data

Functions for saving extracted model data into standard OCMW file format.

generateOutputFileStr

Generate output path + filename string

save2ocmw

Create data dictionary of extracted node and location data and save to an OCMW format file.

saveLoc2ocmw

Create data dictionary of extracted location data and save to an OCMW file

saveNodes2ocmw

Create data dictionary of extracted node data and save to an OCMW file

Functions for extracting the model mesh into a standard OCMW format.

enhanceMesh

Add element cntroid locations and barycentric weighting to centroid

extractMesh

Extract model mesh from a Selafin output file

extractGeometry

Extract the model mesh from the OTM Selafin geometry file used to run the model

Functions for extracting 2D fields from multiple model output files.

get2DElevation

Get time series of surface elevation at a user defined location

getMultiFileLocElevation

Gect a multi-file time series of model surface elevation at a user defined location.

extractElevationFrames

Extract timeseries of model surface elevation for animation frames.

extractMultiFile2DField

Extract timeseries of 2D model field data for particular model variable.

Functions for extracting data at set of geospatial locations.

getVariableData

Get variable time series extracted from Selafin file

getLoc2DVars

Extract time series for default set of 2D model fields

getLoc3DVars

Extract time series for default set of 3D model fields

getLocTS

Get timeseries of model data for nodes around a location and interpolate onto location

extract2DLocData

Extract OTM model 2D field data interpolated onto a user defined location

extract3DLocData

Extract OTM 3D field data interpolated onto a user defined location

processLocsDataFile

Extract OTM model data for a set of user defined locations

Functions for extracting data at points along a linear transect.

getTransectPoints

Define transect data locations based on start and end points, and spacing

extractTransect

Extract a transect of 2-D or 3-D data from Selafin file

Functions for extracting data at a set of model nodes.

getVarTimeSeries

Extract timeseries of data for a particular model variable a set of model nodes.

getNodesTS

Extract timeseries of data for a specific model node.

extractNodeTSData

Extract timeseries of data for a set of model nodes.

processNodeDataFile

Extract data from a set of nodes based on user supplied run file.

Functions for extracting data for nodes within a polygon

getMeshNodeLocs

Extract mesh node indices and node coordinates from a 2D Selafine file

processPolygonDataFile

Extract data from nodes within a polygon based on user supplied run file.

Parsers for user supplied ascii run file used by processLocDataFile, processNodesDataFile, and processPolygonDataFile.

parseLocsRunFile

Parser to read run parameters from a configuration file for an extract at user defined locations

parseNodesRunFile

Parser to read run parameters from a configuration file for an extract at model nodes

parseTransectRunFile

Parser to read run parameters from a configuration file for extract along a trnasect

parsePolygonRunFile

Parser to read run parameters from a configuration file for an extract of nodes within a polygon

Open Telemac-Mascaret output data extraction built on the HR Wallingford parser tools supplied with OTM.

Chris Old IES, School of Engineering, University of Edinburgh Feb 2020

class ocmw.dataproc.otm_extraction.slfFile(fileName)[source]

Bases: Selafin

Class structure for reading OTM Selafin files.

Inhereting properties from the Selafin object in the OTM python scripts.

Intialisation of the class

@param file_name (string) Name of the file

properties()[source]

Print a list of teh class properties to std output

Returns:

None.

methods()[source]

Print a list of class methods to std output

Returns:

None.

ocmw.dataproc.otm_extraction.InitialiseFile(FileName)[source]

Initialise Selafin file for reading, inlcuding setting up mesh search tree.

Parameters:

FileName (Str) – Selafin filename including path to location

Returns:

SLF (Selafin obj) – OTM object based on the Selafin class

ocmw.dataproc.otm_extraction.OTMDate2Num(timestamp)[source]

Convert OTM timestamp into a python date number

Parameters:

timestamp (numpy.array, int32) – Array of date time fields [year,month,day,hour,minute,seccond].

Returns:

datenum (float) – Date number.

ocmw.dataproc.otm_extraction.OTMDate2Str(timestamp)[source]

Convert OTM timestamp to date strings

Parameters:

timestamp (numpy.array, int32) – Array of date time fields [year,month,day,hour,minute,seccond].

Returns:

datestr (str) – Date string.

ocmw.dataproc.otm_extraction.genOTMTimeStamps(idate, times, epoch=array([1900, 1, 1, 0, 0, 0]))[source]

Convert OTM timestamp information into an array of python date numbers.

Parameters:
  • idate (numpy.array, int32) – Array of date time fields [year,month,day,hour,minute,seccond].

  • times (numpy.array, float) – Timestep offset from idate in seconds

  • epoch (numpy.array, int32, optional) – Time epoch to use when generating timestampes. The default is default_epoch.

Returns:

timeStamp (numpy.array, float) – Timestamp as date number in days from epoch.

ocmw.dataproc.otm_extraction.getSlfTriangle(slfHnd, LocX, LocY)[source]

Get the triangular element and node the contain the point (LocX,LocY) from SLF file handle

Parameters:
  • slfHnd (Selafin obj) – Handle to the Selafin obj for the file being processed

  • LocX (float) – x coordinate of the point of interest

  • LocY (float) – y coordinate of the point of interest

Returns:

  • NNodes (list[int64]) – Indices for the nodes surrounding the location

  • Elem (int64) – Index for the mesh element corresponding to the nodes

ocmw.dataproc.otm_extraction.getSlfNodesWeights(slfHnd, LocX, LocY)[source]

Get the barycentric weigthing factors to interpolate from element nodes onto the point (LocX,LocY) from Selafin file

Parameters:
  • slfHnd (Selafin obj) – Handle to the Selafin obj for the file being processed

  • LocX (float) – x coordinate of the point of interest

  • LocY (float) – y coordinate of the point of interest

Returns:

  • Elem (TYPE) – Index of the element containing the point

  • NNodes (list, int64) – Indices of the nodes for the element surrounding the point (LocX,LocY)

  • NWghts (list, float) – Barycebtric weights from element nodes to point (LocX,LocY)

  • NLocs (list, list[float,float]) – Location of nodes surroundng the point (LocX,LocY)

ocmw.dataproc.otm_extraction.getMeshTriangle(mesh, LocX, LocY)[source]

Get the triangular element and node the contain the point (LocX,LocY) from mesh dictionary

Parameters:
  • slfHnd (Selafin obj) – Handle to the Selafin obj for the file being processed

  • LocX (float) – x coordinate of the point of interest

  • LocY (float) – y coordinate of the point of interest

Returns:

  • NNodes (list, int64) – Indices for the nodes surrounding the location

  • Elem (int64) – Index for the mesh element corresponding to the nodes

ocmw.dataproc.otm_extraction.getMeshNodesWeights(mesh, LocX, LocY)[source]

Get the barycentric weigthing factors to interpolate from element nodes onto the point (LocX,LocY) from mesh dictionary data

Parameters:
  • slfHnd (Selafin obj) – Handle to the Selafin obj for the file being processed

  • LocX (float) – x coordinate of the point of interest

  • LocY (float) – y coordinate of the point of interest

Returns:

  • Elem (TYPE) – Index of teh element containing the point

  • NNodes (list, int64) – Indices of the nodes for the element surrounding the point (LocX,LocY)

  • NWghts (list, float) – Barycebtric weights from element nodes to point (LocX,LocY)

  • NLocs (list, list[float,float]) – Location of nodes surroundng the point (LocX,LocY)

ocmw.dataproc.otm_extraction.generateOutputFileStr(filePath, runStr)[source]

Generate output path + filename string

Parameters:
  • filePath (str) – Path to Selfin files

  • runStr (str) – Prefix identifying file to be processes i.e. filename excluding “_2D.slf” or “_3D.slf”

Returns:

outFName (str) – Full path and filename for outputing extracted data.

ocmw.dataproc.otm_extraction.save2ocmw(outfname, glbAttr, Loc, nodes, Data2D, Data3D)[source]

Create data dictionary of extracted node and location data and save to an OCMW format file.

Parameters:
  • outfname (str) – Full path and filename for data output.

  • glbAttr (str) – Global attribute dictionary generated using “generateGlobalAttributes”.

  • Loc (list, float) – DESCRIPTION.

  • nodes (list, [float,float]) – Element corner nodes surrounding location.

  • Data2D (dict) – Data dictionary containg the node and interpolated model 2D fields.

  • Data3D (dict) – Data dictionary containg the node and interpolated model 3D fields.

Returns:

None.

ocmw.dataproc.otm_extraction.saveLoc2ocmw(outfname, glbAttr, loc, crs, Data2D, Data3D)[source]

Create data dictionary of extracted location data and save to an OCMW file

Parameters:
  • outfname (str) – Full path and filename for data output.

  • glbAttr (str) – Global attribute dictionary generated using “generateGlobalAttributes”.

  • Loc (list, [float,float]) – Location coordinates.

  • crs (str) – Coordinate reference system used for location data.

  • Data2D (dict) – Data dictionary containg the interpolated model 2D fields.

  • Data3D (dict) – Data dictionary containg the interpolated model 3D fields.

Returns:

None.

ocmw.dataproc.otm_extraction.saveNodes2ocmw(outfname, glbAttr, nodes, Data2D, Data3D)[source]

Create data dictionary of extracted node data and save to an OCMW file

Parameters:
  • outfname (str) – Full path and filename for data output.

  • glbAttr (str) – Global attribute dictionary generated using “generateGlobalAttributes”.

  • nodes (list, float) – Indices of nodes where data are extracted.

  • Data2D (dict) – Data dictionary containg the nodes model 2D fields.

  • Data3D (dict) – Data dictionary containg the nodes model 3D fields.

Returns:

None.

ocmw.dataproc.otm_extraction.enhanceMesh(mesh)[source]

Add element cntroid locations and barycentric weighting to centroid

Parameters:

mesh (dict) – Mesh data strcuture generated by either extractMesh or extractGeometry

Returns:

mesh (dict) – Dictionary strcuture contining the mesh data.

ocmw.dataproc.otm_extraction.extractMesh(slfFile, enhance=True, meshFile=None, saveMesh=True)[source]

Extract model mesh from a Selafin output file

Parameters:
  • slfFile (str or slfObj) – Full path and file name of to Selfin file or handle to corresponding Selfin object

  • enhance (bool, optional) – Toggle to add mesh enhancment data. The default is True.

  • meshFile (str, optional) – Output mesh file name. The default is None.

  • saveMesh (bool, optional) – Toggle saving of mesh data to a file. The default is True.

Returns:

meshData (dict) – Dictionary strcuture contining the mesh data.

ocmw.dataproc.otm_extraction.extractGeometry(geomFile, enhance=True, saveMesh=False)[source]

Extract the model mesh from the OTM Selafin geometry file used to run the model

Parameters:
  • geomFile (str) – Full path and file name of the Selafin geometry file.

  • enhance (bool, optional) – Extra identifier if multiple model versions available. The default is True.

  • saveMesh (str, optional) – Toggle saving of mesh data to a file. The default is True.

Returns:

meshData (dict) – Dictionary strcuture contining the mesh data.

ocmw.dataproc.otm_extraction.get2DElevation(vals, wgts, varNames)[source]

Get time series of surface elevation at a user defined location

Parameters:
  • vals (numpy.array, float) – Time sereis of node data extracted from a Selafin 2D model output file.

  • wgts (list, float) – Barycetnric node weightings for interpolation to location.

  • varNames (list, str) – Available model 2D variables.

Returns:

elev2D (dict) – Dictionary structure contiaining elevation data (nodes and location).

ocmw.dataproc.otm_extraction.getMultiFileLocElevation(datapath, files, Loc, glbAttrTitle='Model tidal harmonics at XTRACK locations')[source]

Gect a multi-file time series of model surface elevation at a user defined location. Used for validation of model against X-Track surface elevation data

Parameters:
  • datapath (str) – Path to set of Selafin 2D model output files.

  • files (list, str) – List of model 2D Selafin files to process.

  • Loc (list, [float,float]) – Coordinates [x,y] of location elevation calculation.

  • glbAttrTitle (str, optional) – Title string describing use of time series. The default is ‘Model tidal harmonics at XTRACK locations’.

Returns:

tsData (dict) – Dictionary structure contain time series of elevation at nodes and location.

ocmw.dataproc.otm_extraction.extractElevationFrames(filePath, runStr)[source]

Extract timeseries of model surface elevation for animation frames.

ocmw.dataproc.otm_extraction.extractMultiFile2DField(filePath, modStr, startStr, nFiles, varStr, outSuffix=None, saveFile=True)[source]

Extract timeseries of 2D model field data for particular model variable.

ocmw.dataproc.otm_extraction.getVariableData(slfData, slfVarNames, varName)[source]

Get variable time series extracted from Selafin file

Parameters:
  • slfData (numpy.array, float) – Extracted time series of model fields.

  • slfVarNames (list, str) – List of available variables.

  • varName (str) – Name of variable to extract from Selafin file data.

Returns:

varData (numpy.array, float) – Extracted time series for requested variable.

ocmw.dataproc.otm_extraction.getLoc2DVars(vals, wgts, varNames)[source]

Extract time series for default set of 2D model fields

Parameters:
  • vals (numpy.array, float) – Extracted time series of 2D field data.

  • wgts (numpy.array, float) – Barycentric weighting factors for interpolation from nodes.

  • varNames (list, str) – List of available model 2D fields

Returns:

vars2D (dict) – Data dictionary containg the interpolated default model 2D fields

ocmw.dataproc.otm_extraction.getLoc3DVars(vals, wgts, varNames)[source]

Extract time series for default set of 3D model fields

Parameters:
  • vals (numpy.array, float) – Extracted time series of 3D field data.

  • wgts (numpy.array, float) – Barycentric weighting factors for interpolation from nodes.

  • varNames (list, str) – List of available model 3D fields

Returns:

vars3D (dict) – Data dictionary containg the interpolated default model 3D fields

ocmw.dataproc.otm_extraction.getLocTS(slfHnd, Elem, NNodes, NWghts)[source]

Get timeseries of model data for nodes around a location and interpolate onto location

Parameters:
  • slfHnd (Selafin obj) – Handle to the Selafin object for the file being processed.

  • Elem (int64) – Element ID.

  • NNodes (list, int64) – Nearest node indices.

  • NWghts (list, float) – Barycentric node weights for interpolation to location.

Returns:

tsData (dict) – Dictionary structure containing the data at the nodes and requested location.

ocmw.dataproc.otm_extraction.extract2DLocData(slf2D, Loc)[source]

Extract OTM model 2D field data interpolated onto a user defined location

Parameters:
  • slf2D (Selafin obj) – Filename of the OTM Selafin file containing the 2D model fields.

  • Loc (list, float) – Location [x,y] where data are to be interpolated to.

Returns:

list – Set of output data. Elem = index of element containing the location NNodes = indices of the corner nodes of the element NWghts = Barycentric weights for interpolation from nodes to location Data2D = dictionary containing the 2D data for the nodes and location

ocmw.dataproc.otm_extraction.extract3DLocData(slf3D, Loc)[source]

Extract OTM 3D field data interpolated onto a user defined location

Parameters:
  • filePath (str) – Path to the data file to be processed.

  • fileStr (str) – Prefix identifying file to be processes i.e. filename excluding “_3D.slf”

  • Loc (list, float) – Location [x,y] where data are to be interpolated to.

Returns:

list – Set of output data. Elem = index of element containing the location NNodes = indices of the corner nodes of the element NWghts = Barycentric weights for interpolation from nodes to location Data2D = dictionary containing the 2D data for the nodes and location Data3D = dictionary containing the 3D data for the nodes and location

ocmw.dataproc.otm_extraction.processLocsDataFile(filePath, runStr, locIDs, procStr, locs)[source]

Extract OTM model data for a set of user defined locations

Parameters:
  • filePath (str) – Path to Selfin files

  • runStr (str) – Prefix identifying file to be processes i.e. filename excluding “_2D.slf” or “_3D.slf”

  • locIDs (list, str) – Identifiers used to name extract file for each location.

  • modelVer (TYPE) – DESCRIPTION.

  • procStr (TYPE) – DESCRIPTION.

  • locs (TYPE) – DESCRIPTION.

Returns:

None.

ocmw.dataproc.otm_extraction.singleProcess(filePath, runStr, idStr, procStr, Loc)[source]
ocmw.dataproc.otm_extraction.batchProcess(filePath, searchStr, idStr, procStr, Loc)[source]
ocmw.dataproc.otm_extraction.dataDict(slfHnd, nlocs)[source]
ocmw.dataproc.otm_extraction.getLocsTS(slf, locs)[source]
ocmw.dataproc.otm_extraction.getTransectPoints(loc01, loc02, dL)[source]

Define transect data locations based on start and end points, and spacing

Parameters:
  • loc01 (list[float,float]) – Transect start point coordinates [x,y]

  • loc02 (list[float,float]) – Transect end point coordinates [x,y]

  • dL (float) – Transect sample spacing

Returns:

  • Locs (numpy.array, [float,float]) – Coordinates of transect data points.

  • Theta (float) – Direction of transect - mathematical convention.

ocmw.dataproc.otm_extraction.extract2DTransect(filePath, runStr, tranStr, loc01, loc02, dL, crs)[source]

Extract a transect of 2-D data from Selafin file

Parameters:
  • filePath (str) – Path to Selfin files

  • runStr (str) – Prefix identifying file to be processes i.e. filename excluding “_2D.slf”

  • tranStr (str) – String containing transect description for setting the Global Attributes title.

  • loc01 (list[float]) – Transect start point location [x,y]

  • loc02 (list[float]) – Transect end point location [x,y]

  • dL (float) – Transect sample separation in m

Returns:

Trans_Data (dict) – Data dictionary containing transect data

ocmw.dataproc.otm_extraction.extract3DTransect(filePath, runStr, tranStr, loc01, loc02, dL, crs)[source]

Extract a transect of 3-D data from Selafin file

Parameters:
  • filePath (str) – Path to Selfin files

  • runStr (str) – Prefix identifying file to be processes i.e. filename excluding “_3D.slf”

  • tranStr (str) – String containing transect description for setting the Global Attributes title.

  • loc01 (list[float]) – Transect start point location [x,y]

  • loc02 (list[float]) – Transect end point location [x,y]

  • dL (float) – Transect sample separation in m

Returns:

Trans_Data (dict) – Data dictionary containing transect data

ocmw.dataproc.otm_extraction.extractTransect(filePath, runStr, tranStr, loc01, loc02, dL, crs, only2D=False)[source]

Extract a transect of 2-D or 3-D data from Selafin file

Parameters:
  • filePath (str) – Path to Selfin files

  • runStr (str) – Prefix identifying file to be processes i.e. filename excluding “_2D.slf” or “_3D.slf”

  • tranStr (str) – String containing transect description for setting the Global Attributes title.

  • loc01 (list[float]) – Transect start point location [x,y]

  • loc02 (list[float]) – Transect end point location [x,y]

  • dL (float) – Transect sample separation in m

  • only2D (bool, optional) – Toggle to extract only 2D data. The default is False.

Returns:

Trans_Data (dict) – Data dictionary containing transect data

ocmw.dataproc.otm_extraction.getVarTimeSeries(slfHnd, nodes, varStr)[source]

Extract timeseries of data for a particular model variable a set of model nodes.

ocmw.dataproc.otm_extraction.getNodesTS(slfHnd, nodes)[source]

Extract timeseries of data for a specific model node.

ocmw.dataproc.otm_extraction.extractNodeTSData(filePath, fileStr, nodes, only2D=False)[source]

Extract timeseries of data for a set of model nodes.

ocmw.dataproc.otm_extraction.processNodeDataFile(filePath, runStr, idStr, procStr, nodes)[source]

Extract data from a set of nodes based on user supplied run file.

ocmw.dataproc.otm_extraction.getMeshNodeLocs(filePath, runStr, setStr=None)[source]

Extract mesh node indices and node coordinates from a 2D Selafine file

Parameters:
  • filePath (TYPE) – DESCRIPTION.

  • runStr (TYPE) – DESCRIPTION.

  • setStr (TYPE, optional) – DESCRIPTION. The default is None.

Returns:

  • nnodes (TYPE) – DESCRIPTION.

  • meshx (TYPE) – DESCRIPTION.

  • meshy (TYPE) – DESCRIPTION.

ocmw.dataproc.otm_extraction.processPolygonDataFile(filePath, runStr, idStr, procStr, polygon)[source]

Extract data from nodes within a polygon based on user supplied run file.

ocmw.dataproc.otm_extraction.parseLocsRunFile(fileName)[source]

Parser to read run parameters from a configuration file for an extract at user defined locations

Parameters:

fileName (str) – Full path and file name for run configuration file.

Returns:

params (dict) – Dicttionary containing the run paramters.

ocmw.dataproc.otm_extraction.parseNodesRunFile(fileName)[source]

Parser to read run parameters from a configuration file for an extract at model nodes

Parameters:

fileName (str) – Full path and file name for run configuration file.

Returns:

params (dict) – Dicttionary containing the run paramters.

ocmw.dataproc.otm_extraction.parseTransectRunFile(fileName)[source]

Parser to read run parameters from a configuration file for extract along a trnasect

Parameters:

fileName (str) – Full path and file name for run configuration file.

Returns:

params (dict) – Dicttionary containing the run paramters.

ocmw.dataproc.otm_extraction.parsePolygonRunFile(fileName)[source]

Parser to read run parameters from a configuration file for an extract of nodes within a polygon

Parameters:

fileName (str) – Full path and file name for run configuration file.

Returns:

params (dict) – Dicttionary containing the run paramters.