You're reading an old version of this documentation. If you want up-to-date information, please have a look at v0.8.2.

snl_d3d_cec_verify.result package

class snl_d3d_cec_verify.result.TimeStepResolver(map_path, n_steps)

Bases: object

map_path: Union[str, Path]

Path to the FlowFM_map.nc file

n_steps: int

Number of time steps in the simulation

class snl_d3d_cec_verify.result.Edges(map_path, n_steps)

Bases: TimeStepResolver

Class for extracting results on the edges 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.edges.extract_k(-1, 1) 
                                        geometry            u1   n0   n1
0      LINESTRING (1.00000 2.00000, 0.00000 2.00000) -3.662849e-17  0.0  1.0
...
Parameters:
  • map_path (Union[str, Path]) – path to the FlowFM_map.nc file

  • n_steps (int) – number of time steps in the simulation

extract_k(t_step, k, goem=None)

Extract data from the grid edges for a given time step and sigma level (k). Available data is:

  • u1: velocity, in metres per second

  • n0: edge normal x-coordinate

  • n1: edge normal y-coordinate

Results are returned as a geopandas.GeoDataFrame, either for all of the edges or for the result of the intersection with geom 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_k(-1, 1, line)
           geometry            u1
0   POINT (6.00000 2.00000) -6.794595e-18
1   POINT (7.00000 2.00000)  7.732358e-01
2   POINT (8.00000 2.00000)  7.753754e-01
3   POINT (9.00000 2.00000)  7.737631e-01
4  POINT (10.00000 2.00000)  7.750168e-01
Parameters:
  • t_step (int) – Time step index

  • k (int) – sigma level

  • goem (Optional[BaseGeometry]) – Optional shapely geometry, where data is extracted on the intersection with the grid edges using the object.intersection() method.

Raises:

IndexError – if the time-step index (t_step) is out of range

Return type:

GeoDataFrame

Returns:

Returns a geopandas.GeoDataFrame with LineString geometries for each edge or the result of the intersection with geom if set.

class snl_d3d_cec_verify.result.Faces(map_path, n_steps, xmax)

Bases: TimeStepResolver

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:
    k        ($x$, $y$) float64 1.002 1.002 1.002 1.002 ... 1.0 1.0 1.0 1.0
    $u$      ($x$, $y$) float64 0.781 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.01472 ... 0.001343 0.001343
Parameters:
  • map_path (Union[str, Path]) – path to the FlowFM_map.nc file

  • n_steps (int) – number of time steps in the simulation

  • xmax (Union[int, float]) – Maximum of x-direction range, in metres

xmax: Union[int, float]

Maximum of x-direction range, in metres

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:

  • k: sigma layer

  • u: velocity in the x-direction, in metres per second

  • v: velocity in the x-direction, in metres per second

  • w: velocity in the x-direction, in metres per second

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:
    k        (dim_0) float64 1.001
    $u$      (dim_0) float64 0.7748
    $v$      (dim_0) float64 -2.942e-17
    $w$      (dim_0) float64 0.0002786

The position extracted can also be shifted using the offset_x, offset_y and offset_z parameters.

Parameters:
  • t_step (int) – Time step index

  • case (CaseStudy) – Case study from which to get turbine position

  • offset_x (Union[int, float]) – Shift x-coordinate of extraction point, in metres. Defaults to 0

  • offset_y (Union[int, float]) – Shift y-coordinate of extraction point, in metres. Defaults to 0

  • offset_z (Union[int, float]) – Shift z-coordinate of extraction point, in metres. Defaults to 0

Raises:
Return type:

xarray.Dataset

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 layer

  • u: velocity in the x-direction, in metres per second

  • v: velocity in the x-direction, in metres per second

  • w: velocity in the x-direction, in metres per second

Results are returned as a xarray.Dataset. Use the x_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:
    k        (dim_0) float64 1.001 1.001 1.001 1.001 1.001 ... 1.0 1.0 1.0 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

The position extracted can also be shifted using the offset_x, offset_y and offset_z parameters.

Parameters:
  • t_step (int) – Time step index

  • case (CaseStudy) – Case study from which to get turbine position

  • x_step (Union[int, float]) – Sample step, in metres. Defaults to 0.5

  • offset_x (Union[int, float]) – Shift x-coordinate of extraction point, in metres. Defaults to 0

  • offset_y (Union[int, float]) – Shift y-coordinate of extraction point, in metres. Defaults to 0

  • offset_z (Union[int, float]) – Shift z-coordinate of extraction point, in metres. Defaults to 0

Raises:
Return type:

xarray.Dataset

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 layer

  • u: velocity in the x-direction, in metres per second

  • v: velocity in the x-direction, in metres per second

  • w: velocity in the x-direction, in metres per second

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:
    k        ($x$, $y$) float64 1.002 1.002 1.002 1.002 ... 1.0 1.0 1.0 1.0
    $u$      ($x$, $y$) float64 0.781 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.01472 ... 0.001343 0.001343

The z-plane can be shifted using the offset_z parameter.

Parameters:
  • t_step (int) – Time step index

  • case (CaseStudy) – Case study from which to get turbine position

  • offset_z (Union[int, float]) – Shift z-coordinate of extraction point, in metres. Defaults to {offset_z}

Raises:
Return type:

xarray.Dataset

extract_z(t_step, z)

Extract data on the plane at the given z-level. Available data is:

  • k: sigma layer

  • u: velocity in the x-direction, in metres per second

  • v: velocity in the x-direction, in metres per second

  • w: velocity in the x-direction, in metres per second

Results are returned as a xarray.Dataset. If the x and y 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:
    k        (dim_0) float64 1.001 1.001 1.001 1.001 1.001
    $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.0003097 -0.0002754 0.0003252

If x and y 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:
    k        ($x$, $y$) float64 1.002 1.002 1.002 1.002 ... 1.0 1.0 1.0 1.0
    $u$      ($x$, $y$) float64 0.781 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.01472 ... 0.001343 0.001343
Parameters:
  • t_step (int) – Time step index

  • z (Union[int, float]) – z-level at which to extract data

  • x (Optional[Sequence[Union[int, float]]]) – x-coordinates on which to interpolate data

  • y (Optional[Sequence[Union[int, float]]]) – y-coordinates on which to interpolate data

Raises:
Return type:

xarray.Dataset

extract_k(t_step, k)

Extract data on the plane at the given sigma-level (k). Available data is:

  • z: the z-level, in metres

  • u: velocity in the x-direction, in metres per second

  • v: velocity in the x-direction, in metres per second

  • w: velocity in the x-direction, in metres per second

Results are returned as a xarray.Dataset. If the x and y 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_k(-1, 1, x, y) 
<xarray.Dataset>
Dimensions:  (dim_0: 5)
Coordinates:
    k        ... 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:
    $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.0003101 -0.0002756 0.0003256

If x and y are not given, then the results are returned at the face centres.

>>> result.faces.extract_k(-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
    k        ... 1
    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.01473 ... 0.001343 0.001343
Parameters:
  • t_step (int) – Time step index

  • k (int) – k-level (sigma) at which to extract data

  • x (Optional[Sequence[Union[int, float]]]) – x-coordinates on which to interpolate data

  • y (Optional[Sequence[Union[int, float]]]) – y-coordinates on which to interpolate data

Raises:
Return type:

xarray.Dataset

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:

xarray.DataArray

class snl_d3d_cec_verify.result.Transect(z, x, y, data=None, name=None, attrs=None, translation=(0, 0, 0))

Bases: object

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(-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 the Faces.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:
    k        (dim_0) float64 1.002 1.002 1.002 1.001
    $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
Parameters:
  • 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, or data 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

name: Optional[str] = None

name of the data stored in the transect

attrs: Optional[dict[str, str]] = None

meta data associated with the transect

classmethod from_csv(path, name=None, attrs=None, translation=(0, 0, 0))

Create a new Transect object from a CSV file.

The CSV file must have x, y, and z column headers, and optionally a data column header. For example:

x, y, z, data
7, 3, 0, 1
8, 3, 0, 2
9, 3, 0, 3
Parameters:
Raises:

ValueError – if the unique values in the z-column is greater than one

Return type:

Transect

classmethod from_yaml(path, translation=(0, 0, 0))

Create a new Transect object from a YAML file.

The YAML file must have z , x and y, and keys where z is a single value and x and y are arrays.

Optionally, a data key can be given as an array, name key as a single value (treated as a string) and an attrs 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
Parameters:
Return type:

Transect

to_xarray()

Export transect as a xarray.DataArray object.

Return type:

xarray.DataArray

snl_d3d_cec_verify.result.get_reset_origin(da, origin)

Move the origin in the given xarray.DataArray object to the given location

The given xarray.DataArray object must have coordinates containing the characters x, y and z.

Parameters:
Return type:

xarray.DataArray

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 characters x, y and z. The returned object will replace these coordinated with starred versions.

Parameters:
Return type:

xarray.DataArray

snl_d3d_cec_verify.result.get_normalised_data(da, factor)

Normalise the data in the given xarray.DataArray object by the given factor

If the given xarray.DataArray object is named, the name will be replaced with a starred version.

Parameters:
Return type:

xarray.DataArray

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 factor

if \(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:

xarray.DataArray