File Format Functions and Classes¶
IONMIX (.cn4)¶
-
class
opacplot2.OpacIonmix(fn, mpi, twot=False, man=False, hassele=False, verbose=False)¶ Class to read in IONMIX EOS and Opacity Files.
The
OpacIonmixclass is used to read in an IONMIX file and translate its information into object attributes. All energies in this file are in Joules and must be converted to ergs. Unlike other file classes,OpacIonmixdoes not store its data as a dictionary. Instead, it stores its data in class attributes.Parameters: - fn (str) – The name of the file to open.
- mpi (str) – The mass per ion in grams.
- twot (bool) – Flag for two-temperature data.
- man (bool) – Flag for manual temperature/density points.
- hassele (bool) – lag for electron entropy data.
-
fn¶ str
Filename.
-
mpi¶ float
Mass per ion.
-
twot¶ bool
Two-temperature data.
-
man¶ bool
Manual temp/dens points.
-
hassele¶ bool
Has electron entropy data.
-
verb¶ bool
Verbose.
-
ntemp¶ int
Number of temperature points.
-
ndens¶ int
Number of density points.
-
numDens¶ numpy.ndarray
Number densitites.
-
temps¶ numpy.ndarray
Temperatures.
-
ngroups¶ numpy.ndarray
Number of groups
-
data¶ str
Data at the end of the IONMIX file.
-
dens¶ numpy.ndarray
Densities.
-
ngroups int
Number of groups.
-
zbar¶ numpy.ndarray
Average ionizations.
-
etot¶ numpy.ndarray
Total energy. Only included in single-temperature data.
-
cvtot¶ numpy.ndarray
Total C_v. Only included in single-temperature data.
-
dedn¶ numpy.ndarray
de/dn. Only included in single-temperature data.
-
dzdt¶ numpy.ndarray
dz/dt. Only included in two-temperature data.
-
pion¶ numpy.ndarray
Ion pressure. Only included in two-temperature data.
-
pele¶ numpy.ndarray
Electron pressure. Only included in two-temperature data.
-
dpidt¶ numpy.ndarray
dp_i/dt. Only included in two-temperature data.
-
dpedt¶ numpy.ndarray
dp_e/dt. Only included in two-temperature data.
-
eion¶ numpy.ndarray
Ion energy. Only included in two-temperature data.
-
eele¶ numpy.ndarray
Electron energy. Only included in two-temperature data.
-
cvion¶ numpy.ndarray
C_v for ions. Only included in two-temperature data.
-
cvele¶ numpy.ndarray
C_v for electrons. Only included in two-temperature data.
-
deidn¶ numpy.ndarray
de_i/dn. Only included in two-temperature data.
-
deedn¶ numpy.ndarray
de_e/dn. Only included in two-temperature data.
-
opac_bounds¶ numpy.ndarray
Opacity boundaries.
-
rosseland¶ numpy.ndarray
Rosseland opacity.
-
planck_absorb¶ numpy.ndarray
Planck absorption.
-
planck_emiss¶ numpy.ndarray
Planck emissivity.
Examples
For a directory with the IONMIX file
imx.cn4for Aluminum:>>> import opacplot2 as opp >>> op = opp.Opac_Ionmix('imx.cn4', 4.4803895e-23) # Al mass in grams >>> print(op.zbar) array([...]) # Array of average ionizations for dens/temp points.
Notes
If you receive a
ValueError: invalid literal for int() with base 10error, settingman=Truemay help to fix this.-
extendToZero()¶ This routine adds another temperature point at zero.
-
write(fn, zvals, fracs, twot=None, man=None)¶ This method writes to an IONMIX file.
Parameters: - fn (str) – Name of output file.
- zvals (tuple) – Atomic numbers.
- fracs (tuple) – Element fractions.
- twot (bool) – Flag for two-temperature data.
- man (bool) – Flag for manual temp/dens points.
Examples
In order to extend
imx.cn4for Al to zero:>>> import opacplot2 as opp >>> op = opp.OpacIonmix('imx.cn4', (13,), (1,)) >>> op.extendToZero() # Add temperature point at zero. >>> op.write('imx-0.cn4', (13,), (1,))
-
opacplot2.writeIonmixFile(fn, zvals, fracs, numDens, temps, zbar=None, dzdt=None, pion=None, pele=None, dpidt=None, dpedt=None, eion=None, eele=None, cvion=None, cvele=None, deidn=None, deedn=None, ngroups=None, opac_bounds=None, rosseland=None, planck_absorb=None, planck_emiss=None, sele=None)¶ opacplot2.writeIonmixFile()provides an explicit and flexible way to write IONMIX files.Parameters: - fn (str) – Name of the file to write.
- zvals (tuple) – Atomic numbers of elements to write to file.
- fracs (tuple) – Element fractions.
- numdens (numpy.ndarray) – Number densities.
- temps (numpy.ndarray) – Temperature array.
- zbar=None (numpy.ndarray) – Average ionization. Only used for tabulated EoS in FLASH.
- dzdt=None (numpy.ndarray) – Temperature derivative of average ionization. Ignored by FLASH.
- pion=None (numpy.ndarray) – Ion pressure Only used for tabulated EoS in FLASH.
- pele=None (numpy.ndarray) – Electron pressure. Only used for tabulated EoS in FLASH.
- dpidt=None (numpy.ndarray) – Temperature derivative of ion pressure. Ignored by FLASH.
- dpedt=None (numpy.ndarray) – Temperature derivative of electron pressure. Ignored by FLASH.
- eion=None (numpy.ndarray) – Ion specific internal energy. Only used for tabulated EoS in FLASH.
- eele=None (numpy.ndarray) – Electron specific internal energy. Only used for tabulated EoS in FLASH.
- cvion=None (numpy.ndarray) – Ion heat capacity at constant volume. Ignored by FLASH.
- cvele=None (numpy.ndarray) – Electron heat capacity at constant volume. Ignored by FLASH.
- deidn=None (numpy.ndarray) – Number derivative of ion energy. Ignored by FLASH.
- deedn=None (numpy.ndarray) – Number derivative of electron energy. Ignored by FLASH.
- ngroups=None (int) – Number of energy groups.
- opac_bounds=None (numpy.ndarray) – Energy group boundaries.
- rosseland=None (numpy.ndarray) – Rosseland opacities. Only used for tabulated EoS in FLASH.
- orb=None (planck_abs) – Planck absorption opacity. Only used for tabulated EoS in FLASH.
- planck_emiss=None (numpy.ndarray) – Planck emission opacity. Only used for tabulated EoS in FLASH.
- sele=None (numpy.ndarray) – Electron entropy.
Examples
Here we open an HDF5 file containing EoS and Opacity data and write it to an IONMIX file:
>>> import opacplot2 as opp >>> op = opp.OpgHdf5.open_file('/path/to/infile.h5') >>> opp.writeIonmixFile('outfile.cn4', op['Znum'], op['Xnum'], numDens=op['idens'][:], temps=op['temp'][:], ngroups=op.Ng, opac_bounds=op['groups'][:], planck_absorb=op['opp_mg'][:], rosseland=op['opr_mg'][:], planck_emiss=op['emp_mg'][:])
MULTI (.opp, .opr, .eps)¶
-
class
opacplot2.OpgMulti(*cargs, **vargs)¶ Can be used either to parse or to write MULTIv5 tables.
OpgMultiis a subclass ofdict. Throughopen_file(), it can read opacity data (only) from MULTI files. Then, the data can be accessed through the key:value pairs of theOpgMultiinstance.Examples
If we are in a directory with the files
He_snp.eps.gz,He_snp.opp.gz,He_snp.opr.gz, andHe_snp.opz.gz, then the following would read their data into anOpgMultiobject:>>> import opacplot2 as opp >>> op = opp.OpgMulti.open_file('/path/to/current/dir', 'He_snp')
-
classmethod
open_file(folder, base_name, verbose=True)¶ Parse MULTI format from a file.
Parameters: - str (folder) – Name of directory containing MULTI files.
- base_name (str) – Base name of MULTI files.
- verbose (bool) – Verbose option.
Returns: Dictionary containing EoS and/or opacity data.
Return type:
-
toEosDict(Znum=None, Anum=None, Xnum=None, log=None)¶ This method creates a dictionary with keys that are common among the various EoS table formats.
-
write(prefix, fmin=None, fmax=None)¶ Write multigroup opacities to files specified by a prefix.
Parameters: - prefix (str) – Prefix to append to files that are written.
- fmin (float) – Minimum value for opacities to write.
- fmax (float) – Maximum value for opacities to write.
Examples
After filling an instance of
OpgMultiwith EoS/opacity data, one could call:>>> op_multi.write('multi_')
to write data files containing multigroup opacities specified by the ‘multi_’ prefix.
-
write2hdf(filename, Znum=None, Anum=None, Xnum=None)¶ Convert to HDF5 parameters.
Parameters: - filename (str) – Output filename.
- Znum (tuple) – Atomic numbers of elements.
- Anum (tuple) – Atomic masses of elements.
- Xnum (tuple) – Fractions of elements.
Examples
The atomic number and relative fractions must be given if they are not already parsed into an instance of
OpgMulti. If they are not,write2hdfwill raise aValueError.If we were in the same directory as the previous example, the following would write an HDF5 file with data from our MULTI files:
>>> import opacplot2 as opp >>> op = opp.OpgMulti.open_file('/path/to/current/dir', 'He_snp') >>> op.write2hdf('outfile.h5')
-
classmethod
Get all related multi Tables defined by a folder and a base name.
Parameters: - folder (str) – Folder containing the tables.
- base_name (str) – Base name of the table.
- verbose (bool) – Flag for verbose option.
SESAME ASCII (.ses)¶
-
class
opacplot2.OpgSesame(filename, precision, verbose=False)¶ This class is responsible for loading all SESAME formatted data files.
OpgSesamereads in a SESAME file. Each key:value pair of thedataattribute corresponds to a table ID and its data from the file, respectively.Parameters: - fn (str) – Name of file to open.
- precision (int) –
opacplot2.OpgSesame.SINGLEfor entry lengths of 15 oropacplot2.OpgSesame.Doublefor entry lengths of 22. - verbose (bool) – Verbose option.
-
data¶ dict
Dictionary of material IDs included in the SESAME file.
Examples
The
opacplot2.OpgSesame.datadictionary will hold the EoS data for the table referenced bytable_id. For example, if we are in a directory with the filesesame.ses:>>> import opacplot2 as opp >>> op = opp.OpgSesame('sesame.ses', opp.OpgSesame.SINGLE) >>> print(op.data.keys()) dict_keys([..., 13719]) # Table ID numbers; Aluminum. >>> data = op.data[13719] >>> print(sorted(data.keys())) dict_keys(['abar',...,'zmax']) # Dictionary containing EoS data.
Note
There are only handling functions for 300 series entries in the SESAME tables.
Data Prefixes¶
From Los Alamos National Laboratory, each SESAME table has five different parts of their EoS tables:
Table # Data Type opacplot2prefixTable 301 TotalEOS(304+305+306) total_Table 303 Ion EOS Plus Cold Curve (305 + 306) ioncc_Table 304 Electron EOS ele_Table 305 Ion EOS (Including Zero Point) ion_Table 306 Cold Curve (No Zero Point) cc_
If we wanted to print out all of the EoS data for the electrons:
>>> import opacplot2 as opp
>>> op = opp.OpgSesame('sesame.ses', opp.OpgSesame.SINGLE)
>>> data = op.data[13719]
>>> for key in data.keys(): # Table ID for aluminum.
... if 'cc_' == key[:3]:
... print(key+':')
... print(data[key])
Data Points¶
There are several top-level data points that are not included in a specific curve of the SESAME tables:
opacplot2Abbr.Phys. Meaning abarMean Atomic Mass bulkmodBulk Modulus excoefExchange Coefficient rho0Normal Density zmaxMean Atomic number
Furthermore, each table (301, ..., 305) prefixes these data points:
opacplot2Abbr.Phys. Meaning densDensity eintEnergy ndensNumber of Densities ntempNumber of Temperatures presPressures tempsTemperatures
From the example in the previous section, if we wanted to print out the density array of electrons, we would simply type:
>>> print(data['ele_dens'])
array([...]) # Electron density array.
PROPACEOS ASCII (.prp)¶
Warning
Handling for Propaceos EoS tables is not publicly distributed with opacplot2 and so its documentation will not be presented here.
HDF5¶
-
class
opacplot2.OpgHdf5¶ -
force_eval()¶ Load the whole table into memory.
-
classmethod
open_file(filename, explicit_load=False)¶ Open an HDF5 file containing opacity data.
Parameters: - filename (str) – Name of file to open.
- explicit_load (bool) – Option to load the whole file to memory.
Examples
To open a file:
>>> import opacplot2 as opp >>> op = opp.OpgHdf5.open_file('infile.h5') >>> print(op.keys()) dict_keys(['Anum', ..., 'Znum']) # OpgHdf5 is a dictionary. >>> print(op['Zf_DT']) array([...]) # Array for average ionization.
Notes
Loading the entire file into memory can be potentially dangerous. Use
explicit_loadwith caution.
-
write2file(filename, **args)¶ Write to an HDF5 output file.
Parameters: - filename (str) – Name of output file.
- args (dict) – Dictionary of data to write.
-
Data Points¶
Depending on what kind of data has been written to an HDF5 file, each HDF5
file may vary widely. Despite this fact, listed below are the naming conventions
opacplot2 uses for HDF5 data points that are relevant to IONMIX. The
abbreviations are keys unless otherwise stated to be an attribute to the
OpgHdf5 object.
opacplot2AbbrPhysical Meaning ZnumAtomic numbers XnumElement fractions idensNumber densities tempTemperature array Ng(attr)Number of energy groups groupsEnergy group boundaries opp_mgPlanck absorption opr_mgRosseland opacities emp_mgPlanck emissivity
For example, if we wanted to open up an HDF5 file named input.h5 and write it to an IONMIX file
named output.cn4, we could write:
>>> import opacplot2 as opp
>>> op = OpgHdf5.open_file('input.h5')
>>> opp.writeIonmixFile(outfile,
op['Znum'], op['Xnum'],
numDens=op['idens'][:], temps=op['temp'][:],
ngroups=op.Ng,
opac_bounds=op['groups'][:],
planck_absorb=op['opp_mg'][:],
rosseland=op['opr_mg'][:],
planck_emiss=op['emp_mg'][:])