Utilities¶
Interpolation¶
-
opacplot2.utils.interpDT(arr, dens, temps, bcdmin=0, bctmin=0, lookup=0)¶ Depending on the choice for lookup, this function returns an interpolation function for values in arr, the density derivative of arr, or the temperature derivative of arr.
What
interpDT()returns is dependent upon thelookupandbcdmin/bctminarguments:INTERP_FUNCwill return an interpolation function for any density/temperature point within the range.INTERP_DFDDwill return a function for the density derivative at any density/temperature point within the range.INTERP_DFDTwill return a function for the temperature derivative at any density/temperature point within the range.BC_BOUNDis the default setting. If an input density/temp is smaller than the minimum value in thedens(ortemps) array, then it will automatically be set to this minimum value.BC_EXTRAP_ZEROwill insert zero points into thearrand eitherdensortempsforbcdmin,bctminrespectively.Parameters: - arr (numpy.ndarray) – Data array.
- dens (numpy.ndarray) – Density array.
- temps (numpy.ndarray) – Temperature array.
- bcdmin (int) – Boundary conditions for density.
- bctmin (int) – Boundary conditions for temperature.
- lookup (int) – Type of function to return.
Examples
In order to find a function that interpolates between dens/temp points for an IONMIX file that we had previously opened as
imx, we could use:>>> import opacplot2 as opp >>> f = opp.utils.interpDT(imx.pion, imx.dens, imx.temps, ... bcdmin=BC_EXTRAP_ZERO, ... bctmin=BC_EXTRAP_ZERO, ... lookup=INTERP_FUNC) >>> print(f(0,0)) # We added points at zero. 0 >>> print(f(123, 456)) # Density of 123 and temperature of 456. 1234.5678 # Resulting ion pressure at this dens/temp.
-
opacplot2.utils.intersect_1D_sorted_arr(arr_1, arr_2)¶ Function to return the venn diagram of two sorted 1D arrays.
In other words, this function will return the union of all values from both arrays that are within the intersection of their ranges. This may be used for interpolation schemes.
Parameters: - arr_1 (numpy.ndarray) – 1D sorted array number 1.
- arr_2 (numpy.ndarray) – 1D sorted array number 2.
Returns: An array that is the venn diagram of the two input arrays.
Return type: numpy.ndarray
Examples
>>> import numpy as np >>> import opacplot2 as opp >>> a = np.array([1,2,3,4,5]) >>> b = np.array([3.5,4.5,5.5,6]) >>> c = opp.utils.intersect_1D_sorted_arr(a,b) >>> print(c) [3.5 4 4.5 5]
Grid Structure¶
-
class
opacplot2.utils.EosMergeGrids(eos_data, filter_dens=<function <lambda>>, filter_temps=<function <lambda>>, intersect=['ele', 'ioncc'], thresh=[], qeos=False)¶ This class provides filtering capabilities for the EoS temperature and density grids.
For instance, SESAME tables may have some additional points in the ion EoS table, compared to the electron EoS table, and as FLASH requires the same density and temperature grid for all species, the simplest solution is to remove those extra points.
Parameters: - eos_data (dict) – Dictionary contraining the EoS data.
- intersect (list) – The resulting temperature [eV] and density [g/cm^(-3)] grids will be computed as an intersection of grids of all the species given in this list. Default: [‘ele’, ‘ioncc’]
- filter_dens (function) – A function that takes a grid of densities and returns a mask of points we don’t wont to keep. Defaut: (lamdba x: x>0.) i.e. don’t remove anything.
- filter_temps (function) – A function that takes a grid of temperatures and returns a mask of points we don’t wont to keep. Defaut: (lamdba x: x>0.) i.e. don’t remove anything.
- thresh (list) – Zero threshold on following keys
Returns: out – A dictionary with the same keys as eos_data. The species specified by
intersectwill have equal temperature and density grids.Return type: dict
Examples
>>> eos_sesame = opp.OpgSesame("../sesame/xsesame_ascii", opp.OpgSesame.SINGLE,verbose=False) >>> eos_data = eos_sesame.data[3720] # Aluminum >>> eos_data_filtered = EosMergeGrids(eos_data, intersect=['ele', 'ioncc'], # Merge ele and ioncc grids filter_temps=lamda x: x>1.) # Remove temperatures below 1eV