Welcome to pyofx’s documentation!

pyofx is an OrcFxAPI extension.

The module contains a number of helper functions useful to those using OrcaFlex.

It also wraps the OrcFxAPI.Model class to provide extra functionality and offers interfaces to directories of OrcaFlex files and Distributed OrcaFlex.

Pre-requisites

pyofx has been built and tested on Python 2.7 and with version 9.7 of the OrcaFlex DLL

pyofx is pure Python and does not rely on any external packages with the exception of OrcFxAPI, which you will need to have installed.

Installation

pyofx can be found at the Python Package Index and so can be installed with pip/easy_install. If you don’t have pip or easy install you should consider installing pip-win on Windows for a pain-free interface to python packages.

There are also Windows installers for the 64-bit version of python.

You can check if it is installed properly like so:

>>> import pyofx

Tutorial

Once installed pyofx behaves exactly as OrcFxAPI does and provides all the same functions and classes.

Model

The only class that is altered is the OrcFxAPI.Model class.

pyofx.Model has:

  • a path attribute, the full path of the model on disk
  • a model_name attribute, the filename without extension
  • an open method, opens the model in the OrcaFlex GUI
  • an objects_of_type method, a list of model objects filtered by type (e.g. ‘Line’) and optionally further conditions
  • lines, vessels and six_d_buoys attributes which are shortcuts to the relevant objects_of_type

The class docstring contains some further details and examples:

class pyofx.Model(*args, **kwargs)[source]

Wrapper around OrcFxAPI.Model to add extra functionality.

  1. added path attribute so the location of the model on the disc can be found from:
>>> model = Model(r"C:\path o\data_file.dat")
>>> model.path
"C:\path    o\data_file.dat"

2. added a model_name attribute (added in v0.0.9) of the file name without path or extensions:

>>> model = Model(r"C:\path o\data_file.dat")
>>> model.model_name
"data_file"

3. added the open method. This will open the model in the OrcaFlex GUI, if the model does not exist on disc then a windows temp file will be created. Won’t return until the OrcaFlex.exe instance is closed.

>>> model = Model()
>>> model.open() # Opens a temp file in OrcaFlex.exe

4. added objects_of_type() to return a list of objects in the model of a certain types/ e.g. model.objects_of_type(‘Line’)

>>> model = Model()
>>> model.CreateObject(otVessel, 'Bigger Boat')
>>> for v in model.objects_of_type('Vessel'):
...     print v.name
"Bigger Boat"
  1. added attribute lines, shortcut to objects_of_type(‘Line’)
  2. added attribute vessels, shortcut to objects_of_type(‘Vessel’)
  3. added attribute six_d_buoys, shortcut to objects_of_type(‘6DBuoy’)

Folders of Models

Often when using the OrcaFlex API you want to apply some function to a folder or folders containing OrcaFlex .dat/.sim/.yml files. pyofx.Models provides an interface to make this easier.

class pyofx.Models(directories, filetype='dat', subdirectories=False, return_model=True, filter_function=None, failed_function=None, virtual_logging=False)[source]

a generator which yields OrcaFlex files in directories.

Suppose we have saved some simulations in C:UsersUserProjectOrcaFlex, to iterate over all those simulations we can use:

>>> for model in Models(r"C:\Users\User\Project\OrcaFlex"):
...    print model
<pyofx.Model object at 0x00000000031B6DD8>
<pyofx.Model object at 0x00000000031B6E80>

Note that in the above example the generator yields Model objects of the .dat files. To return the path to the file rather than the Model object we can pass return_model=False and to return .sim file filetype=”sim”

There are various other options as detailed in the api_docs_:

Distributed OrcaFlex

There is also a way to add files to Distributed OrcaFlex from python with:

class pyofx.Jobs(dllname=None)[source]

Python interface to Distributed OrcaFlex

>>> from pyofx import Jobs
>>> j = Jobs(r"\\network\path\to\OrcFxAPI.dll")

Methods:

add(filepath, variables=None)

Adds an orcaflex file to the list of jobs with optional variables object.

>>> j.add(r"\\network\folder\Hs=2.2m_model.dat", {'Hs':'2.2m'})

run(wait=False)

Submits jobs to Distributed Orcaflex. If wait is True it will not return unitll all jobs have completed.

>>> j.run(True)
>>> print "All jobs finished" # This won't print unitll the simulations are complete.

Indices and tables

Table Of Contents

Next topic

API Documentation

This Page