pyts.io package

Submodules

pyts.io.base module

A base module for the io package.

pyts.io.base.checkname(fname, extensions=[])[source]

Test whether fname exists.

If it does not, change the file extension in the list of extensions until a file is found. If no file is found this function raises IOError.

pyts.io.base.convname(fname, extension=None)[source]

Change the file extension.

pyts.io.formatter module

class pyts.io.formatter.SuperFormatter(template)[source]

Bases: string.Formatter

SuperFormatter adds the following capabilities:

  1. Initialize with a template string, and the __call__() method uses this string. Thus, example usage of this formatter looks like:

    template = SuperFormatter(template_string)
    out_string = template(*args, **kwargs)
    
  2. White space at the end of a format specifier is stripped. This allows for aligning text within the template.

  3. Multiple format strings separated by | can be specified within a template. This formatter will loop over the format strings until it finds one that doesn’t throw a ValueError. For example, the format string 6d|<6.3f|8s will format the following objects as:

    input output string
    3.74583754 '3.746 '
    384 '   384'
    None 'None    '
  4. Default values may be specified after a / at the end of the format string. For example if the container is {show_data:s/False}, and there is no key show_data in **kwargs, then False will fill that location.

  5. The format_prfx attribute allows the user to define a default container prefix. This will be prepended to all format specifiers that are a single-character type specifier. For example if format_prfx = '<20', then the format specifier 'f' will be changed to '<20f', but '>08.3f' will be unchanged. This is applied to each specifier within a multiple specification, thus 'd|f|s' would actually be '<20d|<20f|<20s'.

  6. Custom format specifiers have been implemented by adding a hook that searches for a _format_<specifier> method prior to running the normal formatting routines. That method takes the value to be formatted as input (in addition to self), and should return the fully-formatted string (no further formatting is applied).

    For example, a custom format specifier pet (specified as {my_dog:pet} in the template) could be defined as:

    class MyNewFormatter(SuperFormatter):
    
        def _format_pet(self, value):
            return value.upper()
    

    Note that this will throw an AttributeError if my_dog is an object without an upper method (i.e. not a string), but you could add to the method to handle all of the different types that value might be.

  7. Custom format specifiers with arguments can be specified as {my_dogs:pets(10s,10s)}. In this case the string inside the parenthesis is supplied as the second argument to the _format_pets method. The method that implements this format could be defined as:

    class MyNewFormatter(SuperFormatter):
    
        def _format_pets(self, value, form2):
            out = ''
            for v,f in zip(value, form2.split(',')):
                out += format(v, f)
            return out
    
__call__(*args, **kwargs)[source]

Format the template string with *args and **kwargs.

allow_sloppy = False
default_format_prfx = ''
format_field(value, format_spec)[source]
format_prfx = ''
get_value(key, args, kwargs)[source]

pyts.io.input module

This module is for reading/writing PyTurbSim input (.inp) files.

class pyts.io.input.InputFormatter(template)[source]

Bases: pyts.io.formatter.SuperFormatter

This formatter is defined to format/parse the templates/inp file.

format_prfx = '<20'
pyts.io.input.read(fname)[source]

Read a TurbSim input (.inp) file.

Parameters:

fname : str

The filename to read from.

Returns:

tsinput : tsinput, dict

A PyTurbSim input dictionary.

pyts.io.input.readInPSD(fname)[source]

Read the input spectrum from file fname, and return it as a dictionary.

Parameters:

fname : str

The filename to read the PSD from.

The frequency in the input file should be in units of hz, and the

spectrum should be in units of m^2/s^2/hz.

pyts.io.input.write(filename, in_dict)[source]

Write an input file.

pyts.io.main module

This is the main (top-level) io module. It defines the ‘readModel’ function, which is useful for collecting information from available TurbSim input/output files.

pyts.io.main.readModel(fname)[source]

Read a TurbSim data and input file and return a tsdata data object.

Parameters:

fname : str

The filename to load. If the file ends in:

  • .bl or .wnd, the file is assumed to be a bladed-format file.
  • .bts, the file is assumed to be a TurbSim-format file.
Returns:

tsdata : tsdata

The TurbSim data contained in the binary data file.

pyts.io.read module

pyts.io.read.bladed(fname)[source]

Read Bladed format (.wnd, .bl) full-field time-series binary data files.

Parameters:

fname : str

The filename from which to read the data.

Returns:

tsdata : tsdata

The TurbSim data contained in the binary data file.

pyts.io.read.sum_scan(filename)[source]

Scan a sum file for specific variables.

Parameters:

filename : string

The file to scan.

Returns:

out : dict

A dictionary of values identified.

pyts.io.read.turbsim(fname)[source]

Read TurbSim format (.bts) full-field time-series binary data files.

Parameters:

fname : str

The filename from which to read the data.

Returns:

tsdata : tsdata

The TurbSim data contained in the binary data file.

pyts.io.sum module

class pyts.io.sum.SumFormatter(template)[source]

Bases: pyts.io.formatter.SuperFormatter

default_format_prfx = '>10'
pyts.io.sum.write(filename, in_dict)[source]

Write a sum file.

pyts.io.write module

This module is for writing PyTurbSim data objects to various formats.

The functions in this module were translated directly from the original TSsubs.f90 file.

pyts.io.write.bladed(fname, tsdat)[source]

Write TurbSim output to a Bladed-format (.wnd) binary file.

Parameters:

fname : str

The filename to which the data should be written.

tsdat : tsdata

A TurbSim data object.

Notes

Bladed is a Trademark of GL Garrad-Hassan.

pyts.io.write.formatted(fname, tsdat)[source]

Write the data to a set of TurbSim ‘formatted’ (readable) files (.u, .v, .w).

Parameters:

fname : str

the base-filename to which the data should be written. ‘.u’, ‘.v’, ‘.w’ will be appended to fname for each file.

tsdat : tsdata

The ‘tsdata’ object that contains the data.

pyts.io.write.turbsim(fname, tsdat)[source]

Write the data to a TurbSim-format binary file (.bts).

Parameters:

fname : str

the filename to which the data should be written.

tsdat : tsdata

The ‘tsdata’ object that contains the data.

Module contents

This is the PyTurbSim input/output package. It contains modules for reading/writing PyTurbSim input/data from/to disk.