snl_d3d_cec_verify.result package¶
- class snl_d3d_cec_verify.result.Edges(nc_path, n_steps)¶
Class for extracting results on the edges of the simulation grid for flexible mesh (
'fm'
) models. Use in conjunction with theResult
class.>>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.edges.extract_sigma(-1, 0.5) geometry u1 ... n0 n1 0 LINESTRING (0.00000 1.00000, 0.00000 2.00000) 9.753143e-01 ... 1.0 -0.0 ...
- Parameters:
- extract_sigma(t_step, value, goem=None)¶
Extract data from the grid edges for a given time step and sigma level (
sigma
). Available data is:u1
: velocity, in metres per secondk
: turbulent kinetic energy, in metres squared per second squaredn0
: edge normal x-coordinaten1
: edge normal y-coordinate
Results are returned as a
geopandas.GeoDataFrame
, either for all of the edges or for the result of the intersection withgeom
if set. For example:>>> from shapely.geometry import LineString >>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> line = LineString([(6, 2), (10, 2)]) >>> result.edges.extract_sigma(-1, 0.5, line) geometry u1 $k$ 0 POINT (10.00000 2.00000) 0.991826 -0.004130 1 POINT (6.00000 2.00000) 0.991709 -0.004194 2 POINT (7.00000 2.00000) 0.974911 -0.004177 3 POINT (8.00000 2.00000) 0.992091 -0.004168 4 POINT (9.00000 2.00000) 0.976797 -0.004141
- Parameters:
t_step (
int
) – Time step indexsigma – sigma level
goem (
Optional
[BaseGeometry
]) – Optional shapely geometry, where data is extracted on the intersection with the grid edges using theobject.intersection()
method.
- Raises:
IndexError – if the time-step index (
t_step
) is out of range- Return type:
- Returns:
Returns a
geopandas.GeoDataFrame
withLineString
geometries for each edge or the result of the intersection withgeom
if set.
- class snl_d3d_cec_verify.result.Faces(nc_path, n_steps, xmax)¶
Class for extracting results on the faces of the simulation grid. Use in conjunction with the
Result
class.>>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.faces.extract_z(-1, -1) <xarray.Dataset> Dimensions: ($x$: 18, $y$: 4) Coordinates: * $x$ ($x$) float64 0.5 1.5 2.5 3.5 4.5 5.5 ... 13.5 14.5 15.5 16.5 17.5 * $y$ ($y$) float64 1.5 2.5 3.5 4.5 $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 Data variables: $\sigma$ ($x$, $y$) float64 -0.4994 -0.4994 -0.4994 ... -0.5 -0.5 -0.5 $u$ ($x$, $y$) float64 0.781 0.781 0.781 ... 0.7763 0.7763 0.7763 $v$ ($x$, $y$) float64 -3.237e-18 1.423e-17 ... -8.598e-17 -4.824e-17 $w$ ($x$, $y$) float64 -0.01472 -0.01472 ... 0.001343 0.001343 $k$ ($x$, $y$) float64 0.004802 0.004765 ... 0.003674 0.0036...
- Parameters:
- extract_turbine_centre(t_step, case, offset_x=0, offset_y=0, offset_z=0)¶
Extract data at the turbine centre, as defined in the given
CaseStudy
object. Available data is:sigma
: sigma layeru
: velocity in the x-direction, in metres per secondv
: velocity in the x-direction, in metres per secondw
: velocity in the x-direction, in metres per secondk
: turbulent kinetic energy, in metres squared per second squared
Results are returned as a
xarray.Dataset
. For example:>>> from snl_d3d_cec_verify import MycekStudy, Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> case = MycekStudy() >>> result.faces.extract_turbine_centre(-1, case) <xarray.Dataset> Dimensions: (dim_0: 1) Coordinates: $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 $x$ (dim_0) ... 6 $y$ (dim_0) ... 3 Dimensions without coordinates: dim_0 Data variables: $\sigma$ (dim_0) float64 -0.4996 $u$ (dim_0) float64 0.7748 $v$ (dim_0) float64 -2.942e-17 $w$ (dim_0) float64 0.0002786 $k$ (dim_0) float64 0.004...
The position extracted can also be shifted using the
offset_x
,offset_y
andoffset_z
parameters.- Parameters:
t_step (
int
) – Time step indexcase (
CaseStudy
) – Case study from which to get turbine positionoffset_x (
Union
[int
,float
]) – Shift x-coordinate of extraction point, in metres. Defaults to0
offset_y (
Union
[int
,float
]) – Shift y-coordinate of extraction point, in metres. Defaults to0
offset_z (
Union
[int
,float
]) – Shift z-coordinate of extraction point, in metres. Defaults to0
- Raises:
IndexError – if the time-step index (
t_step
) is out of rangeValueError – if the length of the
CaseStudy
object is greater than one
- Return type:
- extract_turbine_centreline(t_step, case, x_step=0.5, offset_x=0, offset_y=0, offset_z=0)¶
Extract data along the turbine centreline, from the turbine position defined in the given
CaseStudy
object. Available data is:k
: sigma layeru
: velocity in the x-direction, in metres per secondv
: velocity in the x-direction, in metres per secondw
: velocity in the x-direction, in metres per secondk
: turbulent kinetic energy, in metres squared per second squared
Results are returned as a
xarray.Dataset
. Use thex_step
argument to control the frequency of samples. For example:>>> from snl_d3d_cec_verify import MycekStudy, Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> case = MycekStudy() >>> result.faces.extract_turbine_centreline(-1, case, x_step=1) <xarray.Dataset> Dimensions: (dim_0: 13) Coordinates: $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 $x$ (dim_0) float64 6.0 7.0 8.0 9.0 10.0 ... 14.0 15.0 16.0 17.0 18.0 $y$ (dim_0) ... 3 3 3 3 3 3 3 3 3 3 3 3 3 Dimensions without coordinates: dim_0 Data variables: $\sigma$ (dim_0) float64 -0.4996 -0.4996 -0.4996 ... -0.4999 -0.4999 nan $u$ (dim_0) float64 0.7748 0.7747 0.7745 0.7745 ... 0.7759 0.7762 nan $v$ (dim_0) float64 -2.942e-17 4.192e-17 9.126e-17 ... -8.523e-17 nan $w$ (dim_0) float64 0.0002786 -0.0004764 0.0003097 ... -7.294e-05 nan $k$ (dim_0) float64 0.004307 0.004229 0.004157 ... 0.003691 nan
The position extracted can also be shifted using the
offset_x
,offset_y
andoffset_z
parameters.- Parameters:
t_step (
int
) – Time step indexcase (
CaseStudy
) – Case study from which to get turbine positionx_step (
Union
[int
,float
]) – Sample step, in metres. Defaults to0.5
offset_x (
Union
[int
,float
]) – Shift x-coordinate of extraction point, in metres. Defaults to0
offset_y (
Union
[int
,float
]) – Shift y-coordinate of extraction point, in metres. Defaults to0
offset_z (
Union
[int
,float
]) – Shift z-coordinate of extraction point, in metres. Defaults to0
- Raises:
IndexError – if the time-step index (
t_step
) is out of rangeValueError – if the length of the
CaseStudy
object is greater than one
- Return type:
- extract_turbine_z(t_step, case, offset_z=0)¶
Extract data from the z-plane interseting the turbine centre, as defined in the given
CaseStudy
object, at the face centres. Available data is:k
: sigma layeru
: velocity in the x-direction, in metres per secondv
: velocity in the x-direction, in metres per secondw
: velocity in the x-direction, in metres per secondk
: turbulent kinetic energy, in metres squared per second squared
Results are returned as a
xarray.Dataset
.For example:>>> from snl_d3d_cec_verify import MycekStudy, Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> case = MycekStudy() >>> result.faces.extract_turbine_z(-1, case) <xarray.Dataset> Dimensions: ($x$: 18, $y$: 4) Coordinates: * $x$ ($x$) float64 0.5 1.5 2.5 3.5 4.5 5.5 ... 13.5 14.5 15.5 16.5 17.5 * $y$ ($y$) float64 1.5 2.5 3.5 4.5 $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 Data variables: $\sigma$ ($x$, $y$) float64 -0.4994 -0.4994 -0.4994 ... -0.5 -0.5 -0.5 $u$ ($x$, $y$) float64 0.781 0.781 0.781 ... 0.7763 0.7763 0.7763 $v$ ($x$, $y$) float64 -3.237e-18 1.423e-17 ... -8.598e-17 -4.824e-17 $w$ ($x$, $y$) float64 -0.01472 -0.01472 ... 0.001343 0.001343 $k$ ($x$, $y$) float64 0.004802 0.004765 ... 0.003674 0.0036...
The z-plane can be shifted using the
offset_z
parameter.- Parameters:
- Raises:
IndexError – if the time-step index (
t_step
) is out of rangeValueError – if the length of the
CaseStudy
object is greater than one
- Return type:
- extract_z(t_step, z, x=None, y=None)¶
Extract data on the plane at the given z-level. Available data is:
sigma
: sigma valueu
: velocity in the x-direction, in metres per secondv
: velocity in the x-direction, in metres per secondw
: velocity in the x-direction, in metres per secondk
: turbulent kinetic energy, in metres squared per second squared
Results are returned as a
xarray.Dataset
. If thex
andy
parameters are defined, then the results are interpolated onto the given coordinates. For example:>>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> x = [6, 7, 8, 9, 10] >>> y = [2, 2, 2, 2, 2] >>> result.faces.extract_z(-1, -1, x, y) <xarray.Dataset> Dimensions: (dim_0: 5) Coordinates: $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 $x$ (dim_0) ... 6 7 8 9 10 $y$ (dim_0) ... 2 2 2 2 2 Dimensions without coordinates: dim_0 Data variables: $\sigma$ (dim_0) float64 -0.4996 -0.4996 -0.4996 -0.4997 -0.4997 $u$ (dim_0) float64 0.7748 0.7747 0.7745 0.7745 0.7746 $v$ (dim_0) float64 -3.877e-18 4.267e-17 5.452e-17 5.001e-17 8.011e-17 $w$ (dim_0) float64 0.0002786 -0.0004764 ... -0.0002754 0.0003252 $k$ (dim_0) float64 0.004317 0.0042... 0.00416... 0.00409... 0.00403...
If
x
andy
are not given, then the results are returned at the face centres.>>> result.faces.extract_z(-1, -1) <xarray.Dataset> Dimensions: ($x$: 18, $y$: 4) Coordinates: * $x$ ($x$) float64 0.5 1.5 2.5 3.5 4.5 5.5 ... 13.5 14.5 15.5 16.5 17.5 * $y$ ($y$) float64 1.5 2.5 3.5 4.5 $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 Data variables: $\sigma$ ($x$, $y$) float64 -0.4994 -0.4994 -0.4994 ... -0.5 -0.5 -0.5 $u$ ($x$, $y$) float64 0.781 0.781 0.781 ... 0.7763 0.7763 0.7763 $v$ ($x$, $y$) float64 -3.237e-18 1.423e-17 ... -8.598e-17 -4.824e-17 $w$ ($x$, $y$) float64 -0.01472 -0.01472 ... 0.001343 0.001343 $k$ ($x$, $y$) float64 0.004802 0.004765 ... 0.003674 0.0036...
- Parameters:
- Raises:
IndexError – if the time-step index (
t_step
) is out of rangeRuntimeError – if only
x
ory
is set
- Return type:
- extract_sigma(t_step, sigma, x=None, y=None)¶
Extract data on the plane at the given sigma-level. Available data is:
z
: the z-level, in metresu
: velocity in the x-direction, in metres per secondv
: velocity in the x-direction, in metres per secondw
: velocity in the x-direction, in metres per secondk
: turbulent kinetic energy, in metres squared per second squared
Results are returned as a
xarray.Dataset
. If thex
andy
parameters are defined, then the results are interpolated onto the given coordinates. For example:>>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> x = [6, 7, 8, 9, 10] >>> y = [2, 2, 2, 2, 2] >>> result.faces.extract_sigma(-1, -0.5, x, y) <xarray.Dataset> Dimensions: (dim_0: 5) Coordinates: $\sigma$ ... -0.5 time datetime64[ns] 2001-01-01T01:00:00 $x$ (dim_0) ... 6 7 8 9 10 $y$ (dim_0) ... 2 2 2 2 2 Dimensions without coordinates: dim_0 Data variables: $z$ (dim_0) float64 -1.001 -1.001 -1.001 -1.001 -1.001 $u$ (dim_0) float64 0.7747 0.7746 0.7744 0.7745 0.7745 $v$ (dim_0) float64 -3.88e-18 4.267e-17 5.452e-17 5.002e-17 8.013e-17 $w$ (dim_0) float64 0.0002791 -0.0004769 ... -0.0002756 0.0003256 $k$ (dim_0) float64 0.004... 0.0042... 0.0041... 0.004... 0.0040...
If
x
andy
are not given, then the results are returned at the face centres.>>> result.faces.extract_sigma(-1, -0.5) <xarray.Dataset> Dimensions: ($x$: 18, $y$: 4) Coordinates: * $x$ ($x$) float64 0.5 1.5 2.5 3.5 4.5 5.5 ... 13.5 14.5 15.5 16.5 17.5 * $y$ ($y$) float64 1.5 2.5 3.5 4.5 $\sigma$ ... -0.5 time datetime64[ns] 2001-01-01T01:00:00 Data variables: $z$ ($x$, $y$) float64 -1.001 -1.001 -1.001 -1.001 ... -1.0 -1.0 -1.0 $u$ ($x$, $y$) float64 0.7809 0.7809 0.7809 ... 0.7763 0.7763 0.7763 $v$ ($x$, $y$) float64 -3.29e-18 1.419e-17 ... -8.598e-17 -4.824e-17 $w$ ($x$, $y$) float64 -0.01473 -0.01473 ... 0.001343 0.001343 $k$ ($x$, $y$) float64 0.004809 0.004772 ... 0.003674 0.0036...
- Parameters:
- Raises:
IndexError – if the time-step index (
t_step
) is out of rangeRuntimeError – if only
x
ory
is set
- Return type:
- extract_depth(t_step)¶
Extract the depth, in meters, at each of the face centres.
Results are returned as a
xarray.DataArray
. For example:>>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.faces.extract_depth(-1) <xarray.DataArray 'depth' ($x$: 18, $y$: 4)> array([[2.00234445, 2.00234445, 2.00234445, 2.00234445], [2.00224624, 2.00224624, 2.00224624, 2.00224624], [2.00212823, 2.00212823, 2.00212823, 2.00212823], [2.00201275, 2.00201275, 2.00201275, 2.00201275], [2.00188605, 2.00188605, 2.00188605, 2.00188605], [2.00176218, 2.00176218, 2.00176218, 2.00176218], [2.00163089, 2.00163089, 2.00163089, 2.00163089], [2.00150178, 2.00150178, 2.00150178, 2.00150178], [2.0013675 , 2.0013675 , 2.0013675 , 2.0013675 ], [2.00123502, 2.00123502, 2.00123502, 2.00123502], [2.00109849, 2.00109849, 2.00109849, 2.00109849], [2.00096352, 2.00096352, 2.00096352, 2.00096352], [2.0008259 , 2.0008259 , 2.0008259 , 2.0008259 ], [2.00068962, 2.00068962, 2.00068962, 2.00068962], [2.0005524 , 2.0005524 , 2.0005524 , 2.0005524 ], [2.00041653, 2.00041653, 2.00041653, 2.00041653], [2.00027887, 2.00027887, 2.00027887, 2.00027887], [2.00014281, 2.00014281, 2.00014281, 2.00014281]]) Coordinates: * $x$ ($x$) float64 0.5 1.5 2.5 3.5 4.5 5.5 ... 13.5 14.5 15.5 16.5 17.5 * $y$ ($y$) float64 1.5 2.5 3.5 4.5 time datetime64[ns] 2001-01-01T01:00:00
- Parameters:
t_step (
int
) – Time step index- Raises:
IndexError – if the time-step index (
t_step
) is out of range- Return type:
- class snl_d3d_cec_verify.result.Transect(id, z, x, y, data=None, name=None, attrs=None, translation=(0, 0, 0))¶
Store for data associated with a transect across the domain, at a particular z-level.
Data is stored for each x and y pair, in order. For example:
>>> x = Transect(0, -1, [1, 2, 3, 4], [2, 2, 2, 2], [5, 4, 3, 2]) >>> x.to_xarray() <xarray.DataArray (dim_0: 4)> array([5, 4, 3, 2]) Coordinates: $z$ ... -1 $x$ (dim_0) ... 1 2 3 4 $y$ (dim_0) ... 2 2 2 2 Dimensions without coordinates: dim_0
Transect
objects can also be unpacked, like a dictionary, to extract matching data from theFaces.extract_z()
method:>>> from snl_d3d_cec_verify import Result >>> data_dir = getfixture('data_dir') >>> result = Result(data_dir) >>> result.faces.extract_z(-1, **x) <xarray.Dataset> Dimensions: (dim_0: 4) Coordinates: $z$ ... -1 time datetime64[ns] 2001-01-01T01:00:00 $x$ (dim_0) ... 1 2 3 4 $y$ (dim_0) ... 2 2 2 2 Dimensions without coordinates: dim_0 Data variables: $\sigma$ (dim_0) float64 -0.4994 -0.4995 -0.4995 -0.4995 $u$ (dim_0) float64 0.7793 0.7776 0.7766 0.7757 $v$ (dim_0) float64 1.193e-17 4.679e-17 2.729e-17 -2.519e-17 $w$ (dim_0) float64 -0.001658 0.0001347 -0.00114 0.0002256 $k$ (dim_0) float64 0.0047... 0.0046... 0.004... 0.0044...
- Parameters:
id – integer identifier for the transect
z – z-level of the transect, in meters
x – x-coordinates of the transect, in meters
y – y-coordinates of the transect, in meters
data – values at each point along the transect
name – name of the data stored in the transect
attrs – meta data associated with the transect
translation – translation of the transect origin, defaults to
(0, 0, 0)
- Raises:
ValueError – if the lengths of
x
,y
, ordata
do not match
- z: Num¶
z-level of the transect, in meters
- x: npt.NDArray[np.float64]¶
x-coordinates of the transect, in meters
- y: npt.NDArray[np.float64]¶
y-coordinates of the transect, in meters
- data: Optional[npt.NDArray[np.float64]] = None¶
values at each point along the transect
- classmethod from_csv(path, id, name=None, attrs=None, translation=(0, 0, 0))¶
Create a new
Transect
object from a CSV file.The CSV file must have
x
,y
, andz
column headers, and optionally adata
column header. For example:x, y, z, data 7, 3, 0, 1 8, 3, 0, 2 9, 3, 0, 3
- Parameters:
id (
int
) – integer identifiername (
Optional
[str
]) – name of data in the resultingTransect
objectattrs (
Optional
[dict
[str
,str
]]) – attributes for the resultingTransect
objecttranslation (
Tuple
[Union
[int
,float
],Union
[int
,float
],Union
[int
,float
]]) – translation of the transect origin, defaults to(0, 0, 0)
- Raises:
ValueError – if the unique values in the z-column is greater than one
- Return type:
- classmethod from_yaml(path, translation=(0, 0, 0))¶
Create a new
Transect
object from a YAML file.The YAML file must have
id
,z
,x
andy
, and keys whereid
is an integer identifier,z
is a single value andx
andy
are arrays.Optionally, a
data
key can be given as an array,name
key as a single value (treated as a string) and anattrs
key with a nested dictionary. For example:z: -1.0 x: [7, 8, 9] y: [3, 3, 3] data: [1, 2, 3] name: $\gamma_0$ attrs: mock: mock path: not mock
- to_xarray()¶
Export transect as a
xarray.DataArray
object.- Return type:
- snl_d3d_cec_verify.result.get_reset_origin(da, origin)¶
Move the origin in the given
xarray.DataArray
object to the given locationThe given
xarray.DataArray
object must have coordinates containing the charactersx
,y
andz
.
- snl_d3d_cec_verify.result.get_normalised_dims(da, factor)¶
Normalise the coordinates in the given
xarray.DataArray
object by the given factor.The given
xarray.DataArray
object must have coordinates containing the charactersx
,y
andz
. The returned object will replace these coordinated with starred versions.- Parameters:
da (xarray.DataArray) – object to modify
factor (
Union
[int
,float
]) – normalising factor, coordinates are divided by this value
- Return type:
- snl_d3d_cec_verify.result.get_normalised_data(da, factor)¶
Normalise the data in the given
xarray.DataArray
object by the given factorIf the given
xarray.DataArray
object is named, the name will be replaced with a starred version.- Parameters:
da (xarray.DataArray) – object to modify.
factor (
Union
[int
,float
]) – normalising factor, the data is divided by this value
- Return type:
- snl_d3d_cec_verify.result.get_normalised_data_deficit(da, factor, name=None)¶
Normalise the data in the given
xarray.DataArray
object by the given factor as a percentage deficit of that factorif \(x\) is the data and \(f\) is the normalising factor, then the quantity generated by this function is:
\[100 * (1 - x / f)\]- Parameters:
- Return type: