Note: The default ITS GitLab runner is a shared resource and is subject to slowdowns during heavy usage.
You can run your own GitLab runner that is dedicated just to your group if you need to avoid processing delays.

Verified Commit cf571a1e authored by Qusai Al Shidi's avatar Qusai Al Shidi 💬

Merge branch 'cdha/swmfpy-more-tecplot-doc-fixes' into HEAD

parents e90d39d3 5b864452
Pipeline #26012 passed with stage
in 1 minute and 10 seconds
......@@ -571,7 +571,7 @@ Some useful references:
apply_equations(eqn_path: str, verbose: bool = False) -> None
```
Apply an equations file in the Tecplot macro format to the active dataset
Apply a Tecplot-formatted equations file to the active dataset.
Please reference the Tecplot User's Manual for more details on
equation files and syntax. It is recommended to use this function with eqn
......@@ -580,11 +580,9 @@ See [TECPLOT](TECPLOT.markdown) for tips on using pytecplot.
**Arguments**:
eqn_file_path (str):
The path to the equation macro file
(typically with extension `.eqn`).
verbose (bool):
(Optional) Whether or not to print the equations as they
- `eqn_file_path` _str_ - The path to the equation macro file (typically with
extension `.eqn`).
- `verbose` _bool_ - (Optional) Whether or not to print the equations as they
are applied. Default behavior is silent.
......@@ -630,8 +628,8 @@ This is helpful for accessing Tecplot variables.
**Arguments**:
variable_name (str):
A string which may contain the meta-characters * ? [ or ].
- `variable_name` _str_ - A string which may contain the meta-characters * ?
[ or ].
**Examples**:
......@@ -645,8 +643,8 @@ This is helpful for accessing Tecplot variables.
```python
print(dataset.variable('X [R]').name)
# TecplotPatternMatchWarning: no variables found matching: "X [R]" For
# a literal match, the meta-characters: * ? [ ] must be wrapped in square-
# For example, "[?]" matches the character "?"...
# a literal match, the meta-characters: * ? [ ] must be wrapped in
# square-brackets. For example, "[?]" matches the character "?"...
```
However,
```python
......@@ -665,21 +663,15 @@ Writes a tecplot zone to various formats.
**Arguments**:
tecplot_dataset (tecplot.data.dataset.Dataset):
The dataset to save.
tecplot_zone (tecplot.data.dataset.Zone):
The zone to save.
write_as (str):
Type of file to write to. Supported options are 'hdf5',
'csv', 'tecplot_ascii', and 'tecplot_plt'.
filename (str):
Name of the file to write to.
variables (list(tecplot.data.dataset.Variable)):
(Optional) Specify a subset of the dataset variables to
save. This option may decrease the size of the output. Default
- `tecplot_dataset` _tecplot.data.Dataset_ - The dataset to save.
- `tecplot_zone` _tecplot.data.zone_ - The zone to save.
- `write_as` _str_ - Type of file to write to. Supported options are `hdf5`,
`csv`, `tecplot_ascii`, and `tecplot_plt`.
- `filename` _str_ - Name of the file to write to.
- `variables` _list_ - (Optional) Specify a subset of the dataset variables
to save. This option may decrease the size of the output. Default
behavior is to save all variables.
verbose:
(Optional) Print diagnostic information. Defaults to False.
- `verbose` - (Optional) Print diagnostic information. Defaults to False.
**Examples**:
......@@ -726,52 +718,49 @@ interpolate_zone_to_geometry(dataset, source_zone, geometry: str, variables: lis
Interpolates Tecplot binary data onto various geometries.
Returns a tecplot zone object.
**Arguments**:
dataset:
The loaded Tecplot dataset.
source_zone:
The Tecplot zone to interpolate onto the geometry.
geometry (str):
Type of geometry for interpolation. Supported geometries
are 'shell', 'line', 'rectprism', or 'trajectory'. See below for the
- `dataset` _tecplot.data.Dataset_ - The loaded Tecplot dataset.
- `source_zone` _tecplot.data.zone_ - The Tecplot zone to interpolate onto
the geometry.
- `geometry` _str_ - Type of geometry for interpolation. Supported geometries
are `shell`, `line`, `rectprism`, or `trajectory`. See below for the
required keyword arguments for each geometry.
variables (list):
(Optional) Subset of variables to interpolate. Default
- `variables` _list_ - (Optional) Subset of variables to interpolate. Default
behavior is to interpolate all variables.
verbose:
(Optional) Print diagnostic information. Defaults to False.
**kwargs:
- `center` _array-like_ - Argument for the 'shell' geometry. Contains the X,
Y, and Z positions of the shell. Defaults to (0,0,0).
- `radius` _float_ - Argument for the 'shell' geometry. Required.
- `npoints` _array-like_ - Argument for the 'shell' geometry. Contains the
number of points in the azimuthal and polar directions to
interpolate onto, excluding the north and south polar points.
Defaults to (360,179).
- `r1` _array-like_ - Argument for the 'line' geometry. Contains the X, Y,
and Z positions of the point where the line starts. Required.
- `r2` _array-like_ - Argument for the 'line' geometry. Contains the X, Y,
and Z positions of the point where the line ends. Required.
- `npoints` _int_ - Argument for the 'line' geometry. The number of points
along the line to interpolate onto. Required.
- `center` _array-like_ - Argument for the 'rectprism' geometry. Contains the
X, Y, and Z positions of the center of the rectangular prism.
- `verbose` _bool_ - (Optional) Print diagnostic information. Defaults to
False.
- `**center` _array-like_ - Argument for the `shell` geometry. Contains the
X, Y, and Z positions of the shell. Defaults to (0,0,0).
- `**radius` _float_ - Required argument for the `shell` geometry.
- `**npoints` _array-like_ - Argument for the `shell` geometry. Contains the
number of points in the azimuthal and polar directions to interpolate
onto, excluding the north and south polar points. Defaults to
(360, 179).
- `**r1` _array-like_ - Required argument for the `line` geometry. Contains
the X, Y, and Z positions of the point where the line starts.
- `**r2` _array-like_ - Required argument for the `line` geometry. Contains
the X, Y, and Z positions of the point where the line ends.
- `**npoints` _int_ - Required argument for the `line` geometry. The number
of points along the line to interpolate onto.
- `**center` _array-like_ - Argument for the `rectprism` geometry. Contains
the X, Y, and Z positions of the center of the rectangular prism.
Defaults to (0,0,0).
- `halfwidths` _array-like_ - Argument for the 'rectprism' geometry. Contains
the half widths of the rectangular prism in the X, Y, and Z
directions. Required.
- `npoints` _array-like_ - Argument for the 'rectprism' geometry. Contains
the number of points in the X, Y, and Z directions to interpolate
onto. Required.
- `trajectory_data` _str_ - Argument for the 'trajectory' geometry. The path
to the ASCII trajectory data file. Required.
- `trajectory_format` _str_ - Argument for the 'trajectory' geometry. The
format of the trajectory data file. Supported formats are 'tecplot'
(data is a tecplot zone with 3D positional variables and 'time') and
'batsrus' (data is formatted as described for the `SATELLITE`
command, see SWMF documentation). Required.
- `**halfwidths` _array-like_ - Required argument for the `rectprism`
geometry. Contains the half widths of the rectangular prism in the X,
Y, and Z directions.
- `**npoints` _array-like_ - Required argument for the `rectprism` geometry.
Contains the number of points in the X, Y, and Z directions to
interpolate onto.
- `**trajectory_data` _str_ - Required argument for the `trajectory`
geometry. The path to the ASCII trajectory data file.
- `**trajectory_format` _str_ - Required argument for the `trajectory`
geometry. The format of the trajectory data file. Supported formats
are `tecplot` (data is a tecplot zone with 3D positional variables)
and `batsrus` (data is formatted as described for the `SATELLITE`
command, see SWMF documentation).
**Examples**:
......@@ -818,13 +807,13 @@ Interpolates Tecplot binary data onto various geometries.
)
## geometry: spacecraft trajectory as specified for the
## BATSRUS `SATELLITE` command
## BATSRUS SATELLITE command
tpt.interpolate_zone_to_geometry(
dataset=dataset,
source_zone=dataset.zone(0),
geometry='trajectory',
trajectory_format='batsrus',
trajectory_data='./test_data/satellite_e4.dat'
trajectory_data='satellite_e4.dat'
)
## The new zones are labeled with the name of the geometry and can be
......
......@@ -4,5 +4,5 @@
# run `pip install pydoc-markdown --user`
# then run this script in the project root directory
pydoc-markdown --py3 -v -I. --render-toc -m swmfpy -m swmfpy.web -m swmfpy.io -m swmfpy.paramin -m swmfpy.tools -m swmfpy.tecplottools $@ | sed 's/\\043/#/g' - > DOCUMENTATION.markdown
pydoc-markdown --py3 -v -I. --render-toc -m swmfpy -m swmfpy.web -m swmfpy.io -m swmfpy.paramin -m swmfpy.tools -m swmfpy.tecplottools $@ | sed 's/\\043/#/g' > DOCUMENTATION.markdown
......@@ -28,14 +28,13 @@ import numpy as np
import tecplot
def _get_variable_names(variables):
"""For getting the names of a group of Tecplot variables"""
def _get_variable_names(variables) -> list:
"""For getting the names of a group of Tecplot variables."""
return [var.name for var in variables]
def _shell_geometry(geometry_params: dict) -> dict:
"""Returns a dict containing points for the described shell geometry.
"""
"""Returns a dict containing points for the described shell geometry."""
nlon = geometry_params['npoints'][0] # 360
nlat = geometry_params['npoints'][1] # 179
lons = np.linspace(0, 360, nlon, endpoint=False)
......@@ -63,8 +62,7 @@ def _shell_geometry(geometry_params: dict) -> dict:
def _line_geometry(geometry_params: dict) -> dict:
"""Returns a dict containing points for the described line geometry.
"""
"""Returns a dict containing points for the described line geometry."""
geometry_points = {
'npoints': geometry_params['npoints'],
'X': np.linspace(
......@@ -84,8 +82,7 @@ def _line_geometry(geometry_params: dict) -> dict:
def _rectprism_geometry(geometry_params: dict) -> dict:
"""Returns a dict containing points for the described rectprism geometry.
"""
"""Returns a dict containing points for the described rectprism geometry."""
npoints = (geometry_params['npoints'][0]
* geometry_params['npoints'][1]
* geometry_params['npoints'][2])
......@@ -113,7 +110,7 @@ def _rectprism_geometry(geometry_params: dict) -> dict:
def _trajectory_geometry(geometry_params: dict) -> dict:
"""Returns a dict containing points for the described trajectory geometry.
Assumes format of trajectory file after SWMF SATELLITE command.
Assumes format of trajectory file after SWMF `SATELLITE` command.
"""
do_read = False
trajectory_data = []
......@@ -156,9 +153,13 @@ def _trajectory_geometry(geometry_params: dict) -> dict:
return geometry_points
def _save_hdf5(filename, geometry_params, new_zone, variables) -> None:
"""Save the aux data and a subset of the variables in hdf5 format.
"""
def _save_hdf5(
filename: str,
geometry_params: dict,
new_zone,
variables
) -> None:
"""Save the aux data and a subset of the variables in hdf5 format."""
column_names = _get_variable_names(variables)
tp_data = []
for var in variables:
......@@ -170,9 +171,13 @@ def _save_hdf5(filename, geometry_params, new_zone, variables) -> None:
h5_file['data'].attrs['names'] = column_names
def _save_csv(filename, geometry_params, new_zone, variables) -> None:
"""Save the aux data and a subset of the variables in plain-text format.
"""
def _save_csv(
filename: str,
geometry_params: dict,
new_zone,
variables
) -> None:
"""Save the aux data and a subset of the variables in plain-text format."""
aux_data = geometry_params.__repr__() + '\n'
column_names = variables[0].name.__repr__()
for var in variables[1:]:
......@@ -190,14 +195,14 @@ def _save_csv(filename, geometry_params, new_zone, variables) -> None:
)
def _add_variable_value(dataset, variable_name: str, zone, values):
def _add_variable_value(dataset, variable_name: str, zone, values) -> None:
"""Adds and populates a new variable to a zone in a dataset."""
dataset.add_variable(variable_name)
zone.values(bracketify(variable_name))[:] = values
def apply_equations(eqn_path: str, verbose: bool = False) -> None:
"""Apply an equations file in the Tecplot macro format to the active dataset
"""Apply a Tecplot-formatted equations file to the active dataset.
Please reference the Tecplot User's Manual for more details on
equation files and syntax. It is recommended to use this function with eqn
......@@ -205,12 +210,10 @@ def apply_equations(eqn_path: str, verbose: bool = False) -> None:
See [TECPLOT](TECPLOT.markdown) for tips on using pytecplot.
Args:
eqn_file_path (str):
The path to the equation macro file
(typically with extension `.eqn`).
verbose (bool):
(Optional) Whether or not to print the equations as they
are applied. Default behavior is silent.
eqn_file_path (str): The path to the equation macro file (typically with
extension `.eqn`).
verbose (bool): (Optional) Whether or not to print the equations as they
are applied. Default behavior is silent.
Examples:
```python
......@@ -266,8 +269,8 @@ def bracketify(variable_name: str) -> str:
This is helpful for accessing Tecplot variables.
Args:
variable_name (str):
A string which may contain the meta-characters * ? [ or ].
variable_name (str): A string which may contain the meta-characters * ?
[ or ].
Examples:
In a dataset which contains the variable 'X [R]',
......@@ -279,8 +282,8 @@ def bracketify(variable_name: str) -> str:
```python
print(dataset.variable('X [R]').name)
# TecplotPatternMatchWarning: no variables found matching: "X [R]" For
# a literal match, the meta-characters: * ? [ ] must be wrapped in square-
# For example, "[?]" matches the character "?"...
# a literal match, the meta-characters: * ? [ ] must be wrapped in
# square-brackets. For example, "[?]" matches the character "?"...
```
However,
```python
......@@ -308,21 +311,15 @@ def write_zone(
"""Writes a tecplot zone to various formats.
Args:
tecplot_dataset (tecplot.data.dataset.Dataset):
The dataset to save.
tecplot_zone (tecplot.data.dataset.Zone):
The zone to save.
write_as (str):
Type of file to write to. Supported options are 'hdf5',
'csv', 'tecplot_ascii', and 'tecplot_plt'.
filename (str):
Name of the file to write to.
variables (list(tecplot.data.dataset.Variable)):
(Optional) Specify a subset of the dataset variables to
save. This option may decrease the size of the output. Default
behavior is to save all variables.
verbose:
(Optional) Print diagnostic information. Defaults to False.
tecplot_dataset (tecplot.data.Dataset): The dataset to save.
tecplot_zone (tecplot.data.zone): The zone to save.
write_as (str): Type of file to write to. Supported options are `hdf5`,
`csv`, `tecplot_ascii`, and `tecplot_plt`.
filename (str): Name of the file to write to.
variables (list): (Optional) Specify a subset of the dataset variables
to save. This option may decrease the size of the output. Default
behavior is to save all variables.
verbose: (Optional) Print diagnostic information. Defaults to False.
Examples:
```python
......@@ -407,18 +404,16 @@ def _assign_geometry_defaults(
geometry: str,
default_params: dict,
geometry_params: dict
):
) -> dict:
"""Checks parameters with defaults and assigns them.
If the parameters are already set nothing will change.
Args:
geometry (str):
String identifying the geometry to look for.
default_params (dict):
Dictionary of the default parameters.
geomatry_params (dict):
Dictionary in which to look for and set parameters.
geometry (str): String identifying the geometry to look for.
default_params (dict): Dictionary of the default parameters.
geomatry_params (dict): Dictionary in which to look for and set
parameters.
"""
if geometry in geometry_params['geometry']:
for key, value in default_params.items():
......@@ -432,7 +427,7 @@ def _assign_geometry_defaults(
def _check_geometry_requirements(
geometry_requirements: dict,
geometry_params: dict
):
) -> None:
"""Checks that the required kwargs for the given geometry have been set.
"""
if geometry_params['geometry'] not in geometry_requirements:
......@@ -447,7 +442,7 @@ def _check_geometry_requirements(
def _get_geometry_points(
geometry_params: dict
):
) -> dict:
"""Select the right function to calculate the geometry points."""
if 'shell' in geometry_params['geometry']:
geometry_points = _shell_geometry(geometry_params)
......@@ -473,51 +468,48 @@ def interpolate_zone_to_geometry(
):
"""Interpolates Tecplot binary data onto various geometries.
Returns a tecplot zone object.
Args:
dataset:
The loaded Tecplot dataset.
source_zone:
The Tecplot zone to interpolate onto the geometry.
geometry (str):
Type of geometry for interpolation. Supported geometries
are 'shell', 'line', 'rectprism', or 'trajectory'. See below for the
required keyword arguments for each geometry.
variables (list):
(Optional) Subset of variables to interpolate. Default
behavior is to interpolate all variables.
verbose:
(Optional) Print diagnostic information. Defaults to False.
**kwargs:
center (array-like): Argument for the 'shell' geometry. Contains the X,
Y, and Z positions of the shell. Defaults to (0,0,0).
radius (float): Argument for the 'shell' geometry. Required.
npoints (array-like): Argument for the 'shell' geometry. Contains the
number of points in the azimuthal and polar directions to
interpolate onto, excluding the north and south polar points.
Defaults to (360,179).
r1 (array-like): Argument for the 'line' geometry. Contains the X, Y,
and Z positions of the point where the line starts. Required.
r2 (array-like): Argument for the 'line' geometry. Contains the X, Y,
and Z positions of the point where the line ends. Required.
npoints (int): Argument for the 'line' geometry. The number of points
along the line to interpolate onto. Required.
center (array-like): Argument for the 'rectprism' geometry. Contains the
X, Y, and Z positions of the center of the rectangular prism.
Defaults to (0,0,0).
halfwidths (array-like): Argument for the 'rectprism' geometry. Contains
the half widths of the rectangular prism in the X, Y, and Z
directions. Required.
npoints (array-like): Argument for the 'rectprism' geometry. Contains
the number of points in the X, Y, and Z directions to interpolate
onto. Required.
trajectory_data (str): Argument for the 'trajectory' geometry. The path
to the ASCII trajectory data file. Required.
trajectory_format (str): Argument for the 'trajectory' geometry. The
format of the trajectory data file. Supported formats are 'tecplot'
(data is a tecplot zone with 3D positional variables and 'time') and
'batsrus' (data is formatted as described for the #SATELLITE
command, see SWMF documentation). Required.
dataset (tecplot.data.Dataset): The loaded Tecplot dataset.
source_zone (tecplot.data.zone): The Tecplot zone to interpolate onto
the geometry.
geometry (str): Type of geometry for interpolation. Supported geometries
are `shell`, `line`, `rectprism`, or `trajectory`. See below for the
required keyword arguments for each geometry.
variables (list): (Optional) Subset of variables to interpolate. Default
behavior is to interpolate all variables.
verbose (bool): (Optional) Print diagnostic information. Defaults to
False.
**center (array-like): Argument for the `shell` geometry. Contains the
X, Y, and Z positions of the shell. Defaults to (0,0,0).
**radius (float): Required argument for the `shell` geometry.
**npoints (array-like): Argument for the `shell` geometry. Contains the
number of points in the azimuthal and polar directions to interpolate
onto, excluding the north and south polar points. Defaults to
(360, 179).
**r1 (array-like): Required argument for the `line` geometry. Contains
the X, Y, and Z positions of the point where the line starts.
**r2 (array-like): Required argument for the `line` geometry. Contains
the X, Y, and Z positions of the point where the line ends.
**npoints (int): Required argument for the `line` geometry. The number
of points along the line to interpolate onto.
**center (array-like): Argument for the `rectprism` geometry. Contains
the X, Y, and Z positions of the center of the rectangular prism.
Defaults to (0,0,0).
**halfwidths (array-like): Required argument for the `rectprism`
geometry. Contains the half widths of the rectangular prism in the X,
Y, and Z directions.
**npoints (array-like): Required argument for the `rectprism` geometry.
Contains the number of points in the X, Y, and Z directions to
interpolate onto.
**trajectory_data (str): Required argument for the `trajectory`
geometry. The path to the ASCII trajectory data file.
**trajectory_format (str): Required argument for the `trajectory`
geometry. The format of the trajectory data file. Supported formats
are `tecplot` (data is a tecplot zone with 3D positional variables)
and `batsrus` (data is formatted as described for the `SATELLITE`
command, see SWMF documentation).
Examples:
```python
......@@ -562,13 +554,13 @@ def interpolate_zone_to_geometry(
)
## geometry: spacecraft trajectory as specified for the
## BATSRUS #SATELLITE command
## BATSRUS SATELLITE command
tpt.interpolate_zone_to_geometry(
dataset=dataset,
source_zone=dataset.zone(0),
geometry='trajectory',
trajectory_format='batsrus',
trajectory_data='./test_data/satellite_e4.dat'
trajectory_data='satellite_e4.dat'
)
## The new zones are labeled with the name of the geometry and can be
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment