pyts.io package¶
Submodules¶
pyts.io.base module¶
A base module for the io package.
pyts.io.formatter module¶
-
class
pyts.io.formatter.
SuperFormatter
(template)[source]¶ Bases:
string.Formatter
SuperFormatter adds the following capabilities:
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)
White space at the end of a format specifier is stripped. This allows for aligning text within the template.
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 string6d|<6.3f|8s
will format the following objects as:input output string 3.74583754
'3.746 '
384
' 384'
None
'None '
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 keyshow_data
in**kwargs
, thenFalse
will fill that location.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 ifformat_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'
.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 anupper
method (i.e. not a string), but you could add to the method to handle all of the different types thatvalue
might be.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
-
allow_sloppy
= False¶
-
default_format_prfx
= ''¶
-
format_prfx
= ''¶
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
, dictA PyTurbSim input dictionary.
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.sum module¶
-
class
pyts.io.sum.
SumFormatter
(template)[source]¶ Bases:
pyts.io.formatter.SuperFormatter
-
default_format_prfx
= '>10'¶
-
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.
Module contents¶
This is the PyTurbSim input/output package. It contains modules for reading/writing PyTurbSim input/data from/to disk.