pylbo.data_containers
Classes
Baseclass for a Legolas data container. |
|
Main container for a single Legolas dataset. |
|
Baseclass for a Legolas data container. |
Functions
|
Ensures that the given data is a |
|
Ensures that the given data is a |
Module Contents
- pylbo.data_containers.ensure_dataset(data: any) None [source]
Ensures that the given data is a
LegolasDataSet
.
- pylbo.data_containers.ensure_dataseries(data: any) None [source]
Ensures that the given data is a
LegolasDataSeries
.
- class pylbo.data_containers.LegolasDataContainer[source]
Bases:
abc.ABC
Baseclass for a Legolas data container.
- class pylbo.data_containers.LegolasDataSet(datfile)[source]
Bases:
LegolasDataContainer
Main container for a single Legolas dataset.
- scale_factor
Array with the scale factor. One for Cartesian geometries, r for cylindrical.
- Type:
- property legolas_version: pylbo._version.VersionHandler[source]
- property parameters: dict[source]
Returns the parameters in a dict with the parameter names as keys
- property ef_grid: numpy.ndarray[source]
Returns the eigenfunction grid, None if eigenfunctions are not present.
- property ef_names: numpy.ndarray[source]
Retrieves the eigenfunction names, None if eigenfunctions are not present.
- property derived_ef_names: numpy.ndarray[source]
Retrieves the derived eigenfunction names, None if not present.
- property has_ef_subset: bool[source]
Returns True if the dataset contains a subset of the eigenfunctions.
- _ensure_compatibility() None [source]
Makes sure that the dataset is backwards compatible with new changes. Mainly used for older (<2.0.0) datasets.
- get_sound_speed(which_values=None) float | numpy.ndarray [source]
Calculates the sound speed based on the equilibrium arrays, given by \(c_s = \sqrt{\frac{\gamma p_0}{\rho_0}}\).
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
Array with the sound speed at every grid point, or a float corresponding to the value of which_values if provided.
- Return type:
- get_alfven_speed(which_values=None) float | numpy.ndarray [source]
Calculates the Alfvén speed based on the equilibrium arrays, given by \(c_A = \sqrt{\frac{B_0^2}{\rho_0}}\).
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
Array with the Alfvén speed at every grid point, or a float corresponding to the value of which_values if provided.
- Return type:
- get_tube_speed(which_values=None) float | numpy.ndarray [source]
Calculates the tube speed for a cylinder, given by \(c_t = \frac{c_s c_A}{\sqrt{c_s^2 + c_A^2}}\).
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
Array with the tube speed at every grid point, or a float corresponding to the value of which_values if provided. Returns None if the geometry is not cylindrical.
- Return type:
- get_reynolds_nb(which_values=None) float | numpy.ndarray [source]
Calculates the Reynolds number, defined as \(R_e = \frac{ac_s}{\eta}\) where the slabsize is given by \(a = x_{end} - x_{start}\).
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
Array with the Reynolds number at every grid point, or a float corresponding to the value of which_values if provided. Returns None if the resistivity is zero somewhere on the domain.
- Return type:
- get_magnetic_reynolds_nb(which_values=None) float | numpy.ndarray [source]
Calculates the magnetic Reynolds number, defined as \(R_m = \frac{ac_A}{\eta}\) where the slabsize is given by \(a = x_{end} - x_{start}\).
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
Array with the magnetic Reynolds number at every grid point, or a float corresponding to the value of which_values if provided. Returns None if the resistivity is zero somewhere on the domain.
- Return type:
- get_k0_squared() float [source]
Calculates the squared wave number, defined as \(k_0^2 = k_2^2 + k_3^2\).
- get_matrix_B() tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] [source]
Retrieves the matrix B from the datfile.
- Returns:
Tuple(rows – Tuple containing the rows, columns and values of the non-zero B-matrix elements. Rows and columns are integers, values are real.
- Return type:
numpy.ndarray, cols: numpy.ndarray, vals: numpy.ndarray)
- Raises:
MatricesNotPresent – If the matrices were not saved to the datfile.
- get_matrix_A() tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] [source]
Retrieves the matrix A from the datfile.
- Returns:
Tuple(rows – Tuple containing the rows, columns and values of the non-zero A-matrix elements. Rows and columns are integers, values are complex.
- Return type:
numpy.ndarray, cols: numpy.ndarray, vals: numpy.ndarray)
- Raises:
MatricesNotPresent – If the matrices were not saved to the datfile.
- get_eigenvectors() numpy.ndarray [source]
Retrieves the eigenvectors from the datfile.
- Returns:
Array containing the eigenvectors. One eigenvector in each column.
- Return type:
- Raises:
EigenvectorsNotPresent – If the eigenvectors were not saved to the datfile.
- get_residuals() numpy.ndarray [source]
Retrieves the residuals from the datfile.
- Returns:
Array containing the residuals.
- Return type:
- Raises:
ResidualsNotPresent – If the residuals were not saved to the datfile.
- _get_eigenfunction_like(ev_guesses: numpy.ndarray, ev_idxs: numpy.ndarray, getter_func: Callable) numpy.ndarray [source]
Returns the eigenfunctions based on the supplied getter function.
- Parameters:
ev_guesses (complex, numpy.ndarray) – Eigenvalue guesses.
ev_idxs (int, numpy.ndarray) – Indices of the eigenvalues to retrieve.
getter_func (function) – Function to retrieve the eigenfunctions.
- Returns:
Array containing the eigenfunctions, items are dictionaries.
- Return type:
- get_eigenfunctions(ev_guesses=None, ev_idxs=None) numpy.ndarray [source]
Returns the eigenfunctions based on given eigenvalue guesses or their indices. An array will be returned where every item is a dictionary, containing both the eigenvalue and its eigenfunctions. Either eigenvalue guesses or indices can be supplied, but not both.
- Parameters:
ev_guesses (complex, numpy.ndarray) – Eigenvalue guesses.
ev_idxs (int, numpy.ndarray) – Indices corresponding to the eigenvalues that need to be retrieved.
- Returns:
Array containing the eigenfunctions and eigenvalues corresponding to the supplied indices. Every index in this array contains a dictionary with the eigenfunctions and corresponding eigenvalue. The keys of each dictionary are the eigenfunction names.
- Return type:
- get_nearest_eigenvalues(ev_guesses)[source]
Calculates the eigenvalues nearest to a given guess based on the distance between two points.
- Parameters:
ev_guesses (float, complex, list of float, list of complex) – The guesses for the eigenvalues. These can be a single float/complex value, or a list/Numpy array of floats/complex values.
- Returns:
The indices of the nearest eigenvalues in the
eigenvalues
array. The nearest eigenvalues to the provided guesses, corresponding with the indices idxs.- Return type:
Tuple(numpy.ndarray, numpy.ndarray)
- get_eigenvalues_at_distance(ev_guesses, min_distance=0.0)[source]
Calculates the nearest eigenvalues nearest to a given guess but at a minimum distance away.
- Parameters:
- Returns:
The indices of the nearest eigenvalues at the minimum distance in the
eigenvalues
array. The nearest eigenvalues at a minimum distance to the provided guesses, corresponding with the indices idxs.- Return type:
Tuple(numpy.ndarray, numpy.ndarray)
- get_omega_max(real=True, re_range=None)[source]
Calculates the maximum eigenvalue. The real or imaginary part is used, depending on the real argument. If a range is specified, the maximum eigenvalue is calculated within that range on the real axis.
- Parameters:
eigenvalues (numpy.ndarray(dtype=complex)) – The array of eigenvalues.
real (bool) – If True, the real part of the eigenvalues is used.
re_range (tuple(float, float)) – The range on the real axis to calculate the maximum eigenvalue. Defaults to None, which means all eigenvalues are considered.
- Returns:
The maximum eigenvalue.
- Return type:
- class pylbo.data_containers.LegolasDataSeries(datfiles)[source]
Bases:
LegolasDataContainer
Baseclass for a Legolas data container.
- property continua: dict[source]
Returns the continua. Each key corresponds to a multiple Numpy arrays, one for each dataset.
- property parameters: dict[source]
Returns the parameters. Each key corresponds to multiple Numpy arrays, one for each dataset.
- property has_background: numpy.ndarray[source]
Returns True if background is present.
- property has_efs: numpy.ndarray[source]
Returns True if eigenfunctions are present.
- property ef_names: numpy.ndarray[source]
Returns the eigenfunction names.
- property ef_grid: numpy.ndarray[source]
Returns the eigenfunction grid.
- property has_derived_efs: numpy.ndarray[source]
Returns True at index i if eigenfunctions are present in dataset i.
- property derived_ef_names: numpy.ndarray[source]
Returns the derived eigenfunction names.
- property has_ef_subset: numpy.ndarray[source]
Returns True at index i if the i-th dataset contains a subset.
- property has_matrices: numpy.ndarray[source]
Returns True at index i if the i-th dataset contains matrices.
- property has_eigenvectors: numpy.ndarray[source]
Returns True at index i if the i-th dataset contains eigenvectorst.
- property has_residuals: numpy.ndarray[source]
Returns True at index i if the i-th dataset contains residuals.
- get_sound_speed(which_values=None) numpy.ndarray [source]
Calculates the sound speed for the various datasets.
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
A Numpy array of same length as the number of datasets, containing the sound speeds. Elements are either arrays themselves or floats, depending on the value of which_values.
- Return type:
- get_alfven_speed(which_values=None) numpy.ndarray [source]
Calculates the Alfvén speed for the various datasets.
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
A Numpy array of same length as the number of datasets, containing the Alfvén speeds. Elements are either arrays themselves or floats, depending on the value of which_values.
- Return type:
- get_tube_speed(which_values=None) numpy.ndarray [source]
Calculates the tube speed for the various datasets.
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
A Numpy array of same length as the number of datasets, containing the tube speeds. Elements are either arrays themselves or floats, depending on the value of which_values. Elements are None if the geometry is not cylindrical.
- Return type:
- get_reynolds_nb(which_values=None) numpy.ndarray [source]
Calculates the Reynolds number for the various datasets.
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
A Numpy array of same length as the number of datasets, containing the Reynolds number. Elements are either arrays themselves or floats, depending on the value of which_values. Elements are None if the resistivity is zero.
- Return type:
- get_magnetic_reynolds_nb(which_values=None) numpy.ndarray [source]
Calculates the magnetic Reynolds number for the various datasets.
- Parameters:
which_values (str) – Callback to
get_values()
, either “average”/”minimum”/”maximum”.- Returns:
A Numpy array of same length as the number of datasets, containing the magnetic Reynolds number. Elements are either arrays themselves or floats, depending on the value of which_values. Elements are None if the resistivity is zero.
- Return type:
- get_k0_squared() numpy.ndarray [source]
Calculates the squared wave number for the various datasets.
- Returns:
A Numpy array of same length as the number of datasets, containing the squared wavenumber for each.
- Return type:
- get_omega_max(real=True)[source]
Calculates the maximum of the real or imaginary part of the spectrum for the various datasets.
- Parameters:
real (bool) – Returns the largest real part if True (default option), returns the largest imaginary part if False.
- Returns:
omega_max – A Numpy array of same length as the number of datasets, containing tuples of the eigenvalue that has the largest real or imaginary part.
- Return type: