Spatial coherence
Defining, calculating, and saving/loading spatial coherence values.
- pyconturb.coherence.calculate_coh_mat(freq, spat_df, con_tc=None, coh_model='iec', dtype=<class 'numpy.float64'>, chunk_idcs=None, **kwargs)[source]
Calculate coherence matrix using Cholesky decomposition.
If constraint is passed in, the first
n_c
rows/columns of the returned array correlate the constraints and the subsequentn_sp
rows/columns correspond to the requested simulation points.- Parameters
freq (array-like) – [Hz] Full frequency vector for coherence calculations. Option to calculate coherence for a subset using
chunk_idcs
keyword argument. Dimension is(n_f,)
.spat_df (pandas.DataFrame) – Spatial information on the points to simulate. Must have rows
[k, x, y, z]
, and each of then_sp
columns corresponds to a different spatial location and turbine component (u, v or w).con_tc (pyconturb TimeConstraint, optional) – Optional constraining data for the simulation. The TimeConstraint object is built into PyConTurb; see documentation for more details. Default is none (no constaint). Containts
n_c
columns, one for each constraint location.coh_model (str, optional) – Spatial coherence model specifier. Default is “iec” (IEC 61400-1, Ed. 4).
dtype (data type, optional) – Change precision of calculation (np.float32 or np.float64). Will reduce the storage, and might slightly reduce the computational time. Default is np.float64.
chunk_idcs (int or numpy.array, optional) – Indices of
freq
for which coherence should be calculated or loaded. Dimension is(n_fchunk,)
if given. Default is None (get all frequencies infreq
).**kwargs – Keyword arguments to pass into
get_iec[3d]_cor_mat
.
- Returns
coh_mat – Generated coherence matrix. Dimension is
(n_fchunk, n_c+n_sp, n+n_sp)
.- Return type
numpy.ndarray
- pyconturb.coherence.generate_coherence_file(spat_df, coh_file, freq=None, con_tc=None, coh_model='iec', nf_chunk=1, dtype=<class 'numpy.float64'>, verbose=False, **kwargs)[source]
Calculate a coherence matrix and save it to an HDF5 file for later reuse.
- Parameters
spat_df (pandas.DataFrame) – Spatial information on the points to simulate. Must have rows
[k, x, y, z]
, and each of then_sp
columns corresponds to a different spatial location and turbine component (u, v or w).coh_file (str or pathlib.Path) – Path to file from which to load coherence. Assumed to be an HDF5 file with dataset “coherence” containing a 2D coherence array with dimensions
(n_f, (n_c+n_sp)^2)
.con_tc (pyconturb TimeConstraint, optional) – Optional constraining data for the simulation. The TimeConstraint object is built into PyConTurb; see documentation for more details. Default is none (no constaint). Containts
n_c
columns, one for each constraint location.freq (array-like, optional) – [Hz] Full frequency vector for coherence calculations if con_tc not given. Option to only calculate coherence for a subset of
freq
usingchunk_idcs
keyword argument. Dimension offreq
is is(n_f,)
.coh_model (str, optional) – Spatial coherence model specifier. Default is “iec” (IEC 61400-1, Ed. 4).
dtype (data type, optional) – Change precision of calculation (np.float32 or np.float64). Will reduce the storage, and might slightly reduce the computational time. Default is np.float64.
nf_chunk (int, optional) – Number of frequencies in a chunk of analysis. Increasing this number may speed up computation but may result in more (or too much) memory used. Smaller grids may benefit from larger values for
nf_chunk
. Default is 1.verbose (boolean, optional) – Whether to print updates to screen during calculation. Default is False.
**kwargs – Keyword arguments to pass into
calculate_coh_mat
.
- Returns
coh_mat – Generated coherence matrix. Dimension is
(n_fchunk, n_sp, n_sp)
.- Return type
numpy.ndarray
- pyconturb.coherence.get_coh_mat(freq, spat_df, con_tc=None, coh_model='iec', dtype=<class 'numpy.float64'>, coh_file=None, chunk_idcs=None, **kwargs)[source]
Get coherence matrix (either calculate or load) for set of frequencies.
If the
coh_file
option is given, this function callsload_coh_mat
to load the requested matrix from file. If no file name is given, this function instead callscalculate_coh_mat
to calculate the coherence matrix.- Parameters
freq (array-like) – [Hz] Full frequency vector for coherence calculations. Option to calculate coherence for a subset using chunk_idcs keyword argument. Dimension is
(n_f,)
.spat_df (pandas.DataFrame) – Spatial information on the points to simulate. Must have rows
[k, x, y, z]
, and each of then_sp
columns corresponds to a different spatial location and turbine component (u, v or w).con_tc (pyconturb TimeConstraint, optional) – Optional constraining data for the simulation. The TimeConstraint object is built into PyConTurb; see documentation for more details. Default is none (no constaint). Containts
n_c
columns, one for each constraint location.coh_model (str, optional) – Spatial coherence model specifier. Default is “iec” (IEC 61400-1, Ed. 4).
dtype (data type, optional) – Change precision of calculation (np.float32 or np.float64). Will reduce the storage, and might slightly reduce the computational time. Default is np.float64.
coh_file (str or pathlib.Path, optional) – Path to file from which to load coherence. Assumed to be an HDF5 file with dataset “coherence” containing a 2D coherence array with dimensions
(n_f, n_sp^2)
. Default is None (calculate, don’t load from file).chunk_idcs (int or numpy.array, optional) – Indices of freq for which coherence should be calculated or loaded. Dimension is
(n_fchunk,)
if given. Default is None (get all frequencies infreq
).**kwargs – Keyword arguments to pass into
calculate_coh_mat
.
- Returns
coh_mat – Generated or loaded coherence matrix. Dimension is
(n_fchunk, n_c+n_sp, n+n_sp)
.- Return type
numpy.ndarray
- pyconturb.coherence.load_coh_mat(coh_file, freq=None, chunk_idcs=None)[source]
Load all or part of a coherence matrix from an HDF5 file.
- Parameters
coh_file (str or pathlib.Path) – Path to file from which to load coherence. Assumed to be an HDF5 file with dataset “coherence” containing a 2D coherence array with dimensions
(n_f, n_sp^2)
.freq (array-like, optional) – [Hz] Full frequency vector that was used in coherence calculations. Omitting
freq
means load the entire dataset. Option to load a subset of the coherence matrix using chunk_idcs keyword argument (indexes along frequency). Dimension is(n_f,)
.chunk_idcs (int or numpy.array) – Indices of freq for which coherence should be calculated or loaded. Dimension is
(n_fchunk,)
if given. Default is None (get all frequencies in freq).
- Returns
coh_mat – Generated coherence matrix. Dimension is
(n_fchunk, n_sp, n_sp)
.- Return type
numpy.ndarray