pysep.dsep package¶
Submodules¶
pysep.dsep.calibrate module¶
Solar calibration for dsep module¶
Author: Thomas M. Boudreaux
Created: May 2021
Last Modified: May 2021
Provides functions which attempt to preform solar calibration for dsep models.
Functions¶
extract
LR_calib_solar
LRXZ_calib_solar
- pysep.dsep.calibrate.LRZX_calib_solar(model, initX, initZ, initML, refL=0, refR=0, refXZ=0.0229, endage=4570000000.0)¶
Generate calibrated X, Z, and ML for a stellar model by minimizing the difference between some set of luminosity, radius, and surface compositions.
- Parameters
model (pysep.dsep.stellarModel) – Already initalized stellarModel to evolve.
initX (float) – Initial guess for hydrogen mass fraction.
initZ (float) – Initial guess for metal mass fraction.
initML (float) – Initial guess for mixing length.
refL (float, default=0) –
Refernce log luminosity to calibrate against. Set to 0 assuming that these are given in solar luminosity units so LogL = 0 is solar
luminosity.
refR (float, default=0) – Refernce log radius to calibrate against. Set to 0 assuming that these are given in solar radius units so LogR = 0 is solar radius.
refXZ (float, default=0.0229) – refernce surface composition (Z/X)_surface to calibrate against. Default value is is set such that the default value is the solar surface composition.
endage (float, default=4.57e9) – Age to evolve model to, age refVec should come from. Defaulted to current solar age. Given in years.
- Returns
res – nelder mead minimization against solar reference of hydrogen mass fraction, metal mass fraction, and mixing length
- Return type
float
Examples
Given some already loaded stellarModel called modelA, using the default solar control namelist file from the io module, the following example will provide solar calibrated results for X, Z, and Mixing length
>>> calibration = LRZX_calib_solar(modelA, 0.7, 0.02, 1.9)
- pysep.dsep.calibrate.LR_calib_solar(model, initX, initML, refL=0, refR=0, endage=4570000000.0)¶
Calculate the root mean squared similarity (of the luminosity and radius vector) between a model of particular X and mixing length and a refernce vector (such as solar luminosity and solar radius).
- Parameters
model (pysep.dsep.stellarModel) – Already initalized stellarModel to evolve.
X (float) – Hydrogen mass fraction to rescale model to
ML (float) – Mixing length to rescale model to
refVec (np.ndarray) – Reference vector of luminosity and radius to compare the results from the rescaled model evolution to.
endage (float, default=4.57e9) – Age to evolve model to, age refVec should come from. Defaulted to current solar age. Given in years.
- Returns
res – dual_annealing minimization against solar composition of hydrogen mass fraction and mixing length
- Return type
float
Examples
Given some already loaded stellarModel called modelA, using the default solar control namelist file from the io module, the following example will provide solar calibrated results for X and Mixing Length.
>>> calibration = LR_calib_solar(modelA, 0.7, 1.9)
- pysep.dsep.calibrate.basic_solar_calib(model, tol={'ML': 0.005, 'X': 1e-05}, eta=0.025)¶
Calibrate X and Mixing Length against Log(R) and Log(L) for the sun
- Parameters
model (pysep.dsep.stellarModel) – initial model. X and cmixla will be modified but all other parameters will stay constant
tol (dict, default={'X': 1e-5, 'ML': 5e-3}) – dictionary with numeric tolerance for when to halt optimization of X and ML. Difference between new model X,ML and old model X,ML must drop below both tolerances simultaniously for optimization to halt
eta (float, default=0.025) – scale of perturbations to introduces to the next guess for X and ML this is the standard deviation of a gaussian centered at the previous guess for X and ML
- Returns
rsclx (float) – X which lead to the best solar model
cmixla (float) – mixing length which lead to the best solar model
- pysep.dsep.calibrate.calibrate_Z_post_XML(model, tol={'ML': 0.005, 'X': 1e-05, 'Z': 1e-05}, eta=0.025)¶
Calibrate X and Mixing Length against Log(R) and Log(L) for the sun
- Parameters
model (pysep.dsep.stellarModel) – initial model. X and cmixla will be modified but all other parameters will stay constant
tol (dict, default={'X': 1e-5, 'ML': 5e-3}) – dictionary with numeric tolerance for when to halt optimization of X and ML. Difference between new model X,ML and old model X,ML must drop below both tolerances simultaniously for optimization to halt
eta (float, default=0.025) – scale of perturbations to introduces to the next guess for X and ML this is the standard deviation of a gaussian centered at the previous guess for X and ML
- Returns
rsclx (float) – X which lead to the best solar model
cmixla (float) – mixing length which lead to the best solar model
- pysep.dsep.calibrate.extract(model, iputs, oputs)¶
Take a set of input parameters, evolve a model over them, and then save the final model results for a given key.
- Parameters
model (pysep.dsep.stellarModel) – Already initalized stellarModel to evolve.
iputs (list[(int, str, float),...]) – List of tuples containing information on how to change the control namelist file of model. the first value in each tuple is the dsep run number (as defined in the control namelist file) the second is the key to change in that run and the third is the value to set that key to.
oputs (list[str,...]) – List of keys from the iso file to save the output from the final model.
- Returns
array of size n of keys[0..n] taken from the final model in the iso file
- Return type
numpy.ndarray
Examples
Let’s say you want to evolve a model using three different values for the rescaled X then. Given some already loaded stellarModel called modalA, using the default solar control namelist file provided at pysep.io.nml.control.defaults.solar, the following example will evolve that with three different rescaled X values and return the endage and surface composition for each evolutionary run on its final model.
>>> testParameters = [(0, 'RSCLX', 0.7), (0, 'RSCLX', 0.8), (0, 'RSCLX', 0.9)] >>> finalModel = extract(modelA, testParameters, ['Age', '(Z/X)_surf'])
pysep.dsep.dsepModel module¶
dsep stellarModel module¶
Author: Thomas M. Boudreaux
Created: May 2021
Last modified: June 2022
dsep stellarModel module. The stellarModel handels symlinking files, evolving models, stashing models, accessing model outputs, and cleaning up after a model is done.
Classes¶
- stellarModel
dsep wrapper which takes care of setting up enviroment, unit files, and output data access.
- class pysep.dsep.dsepModel.stellarModel(outputDir, control, physics, opacf, premsf, fermi=(Fname: fermi.tab, Unit: 15), bckur=(Fname: atmk1990p00.tab, Unit: 38), bcphx95=(Fname: z_p0d0.afe_p0d0.dat, Unit: 95), bcphx96=(Fname: z_m0d5.afe_p0d0.dat, Unit: 96), bcphx97=(Fname: z_m0d7.afe_p0d0.dat, Unit: 97), bcphx98=(Fname: z_m1d0.afe_p0d0.dat, Unit: 98), bcphx99=(Fname: z_m1d5.afe_p0d0.dat, Unit: 99), branch=None, default=True, loadOnly=False, mass=None)¶
Bases:
object
This class is a “dsep model”. The idea here is that it provides the primary interface between python and dsep.
- output¶
Path where dsep will save all results to. Will always resolve to an absolute path.
- Type
str
- control¶
Control namelist file object. Will be written to a temporary file and then system linked to the correct unit file by the model object.
- physics¶
Physics namelist file object. Will be written to a temporary file and then system linked to the correct unit file by the model object.
- premsf¶
premfs_file object to be used in evolution. Will be symlinked to proper unit file.
- fermi¶
fermi conductive opacity file object to be used in evolution. Will be symlinked to proper unit file.
- bckur¶
bckur file object to be used in evolution. Will be symlinked to proper unit file.
- opacf¶
opacf_file object to be used in evolution. Will be symlinked to proper unit file.
- bcphx95¶
bcphx95 file object to be used in evolution. Will be symlinked to proper unit file.
- bcphx96¶
bcphx96 file object to be used in evolution. Will be symlinked to proper unit file.
- bcphx97¶
bcphx97 file object to be used in evolution. Will be symlinked to proper unit file.
- bcphx98¶
bcphx98 file object to be used in evolution. Will be symlinked to proper unit file.
- bcphx99¶
bcphx99 file object to be used in evolution. Will be symlinked to proper unit file.
- branch¶
Git branch to consider the locate the executable from. If a branch is set the model will look for the executable called dsepX.<branch>
- Type
str
- default¶
If default is true the model will look for an executable called dsepX instead of looking for one with the branch extension.
- Type
bool
Examples
Creating a stellar model for a 1 solar mass gs98 composition star.
>>> from pysep.dsep import stellarModel as sm >>> from pysep.opac.opal.defaults import GS98hz >>> from pysep.prems.defaults import m100.gs98 >>> from pysep.io.nml.control.defaults import solar >>> from pysep.io.nml.control.defaults import phys1
>>> model = sm(".", solar, phys1, GS98hz, m100.gs98)
Evolving this model is as simple as
>>> model.evolve()
If you want to access some information about an model after it has been evolved you can access both the track file and the iso file
>>> iso, isoMetadata = model.iso() >>> trk, trkMetadata = model.track()
You can also access these with getitem
>>> iso. isoMetadata = model['iso'] >>> trk, trkMetadata = model['trk']
The form of the iso, trk, and metadata variables is given in more detail in the io.iso and io.trk modules.
What if you want to read in a different bckur file from disk?
>>> from pysep.dsep import stellarModel as sm >>> from pysep.opac.opal.defaults import GS98hz >>> from pysep.prems.defaults import m100.gs98 >>> from pysep.io.nml.control.defaults import solar >>> from pysep.io.nml.control.defaults import phys1 >>> from pysep.dm.filetypes import bckur_file
>>> bckurPath = "./atmk1990p00.tab" >>> bckur = bckur_file(bckurPath) >>> model = sm(".", solar, phys1, GS98hz, m100.gs98, bckur=bckur) >>> model.evolve()
By default the bckur, bcphx95, bcphx96, bcphx97, bcphx98, and bcphx99 parameters are all set for a model so that you can get up and running a little more quickly. However, the opacity file, premain sequence model, physics, and control namelist files all must be passed every time.
However, you can always load your own versions of any file. Lets say you had a control namelist file called cont.nml in the local directory which you wanted to use
>>> from pysep.io.nml.control import load >>> customControlNamelist = load('cont.nml')
>>> from pysep.io.nml.control.defaults import phys1 >>> from pysep.opac.opal.defaults import GS98hz >>> from pysep.prems.defaults import m100.gs98 >>> from pysep.dsep import stellarModel as sm
>>> model = sm(".", customControlNamelist, phys1, GS98hz, m100.gs98) >>> model.evolve()
The output from dsep runs will save to whatever directory was specified as the first parameter to the stellarModel constructor. If you want to be able to access the model object latter (not nessisairy but may help with convience) you can “stash” the model which will simply pickle it to the same directory as the dsep output was saved. The model will save with the name model.dsep.
>>> model.stash()
- as_dict(data=False) dict ¶
Convert dsep model to a dict representation
- Parameters
data (bool, default=False) – save output data in dump dict
- Returns
dump – Dictionary representation
- Return type
dict
Examples
Let’s say you have some model called modelA and it has been evolved and you want to save that model so you can quickly load it up again (note this is the python model, all dsep output is always saved; however, it can be helpful to have the python model so you have a reproducable enviroment easily)
>>> modelDict = modelA.as_dict()
This is now a dictionary you can interact with as a normal dict.
- copy()¶
- evolve(debug=False, autoLoad=False, alert=False)¶
Evolve a dsep model using pysep.dsep.utils.run_dsep. This assumes the unit files habe already been symlinked (the constructor for this class should have taken care of that).
- Parameters
debug (bool, default=False) – Run the dsep executable with the gdb debugger. dsep executable must have been compiled with symbols.
autoLoad (bool, default=False) – automatically and imediatly load both the iso and track files into memory when the dsep program finishes running.
alert (bool, default=False) – Run with additional stdout debugging output. This includes printing which input files are linked to which output files and printing out all unit files with their links right before the dsepX executable is called.
- Returns
- Return type
None
Examples
Given some modelA which has already been instantiated evolve that model. This will actually call the dsep executable and produce all the output normally expected from that.
>>> modelA.evolve()
If the dsep executable has been compiled with symbols such that it can be run with gdb then the debug flag can be set and the executable will be run through gdb (thus providing the user with the interactive gdb prompt).
>>> modelA.evolve(debug=True)
By default once the model is evolved it will not automatically read in the dsep output data. This is just under the assumption it might not us used immediatly so why spend time and memory when you might not want it. However, if you know that you do want both the iso and track file output immediatbly loaded in you can save some code with the autoLoad flag.
>>> modelA.evolve(autoLoad=True)
- get_composition(forceRescaleSimilarity: bool = False, ID: int = - 1) Tuple[float, float, float] ¶
Get the composition of a model in a safe way. I.e. will check to make sure all reportings of the composition in the model are self consistent (post rescale). If multiple rescale runs are present then DSEP will take the final rescaleing run to be the one with the authoriative composition unless forceRescaleSimilarity is set to True, in which case all rescaleing runs must match.
- Parameters
forceRescaleSimilarity (bool, default=Fasle) – if True will force validate that all rescaleing runs have the same composition. If the function detectes that this is not true then an error will be raised
ID (int, default=-1) – ID of rescaling run to check composition of. If forceRescaleSimilarity is set to True this parameter should not matter. However, if that is false and you want to check some run other than the final run you can modify that here. This just gets passed as a list index so normal python indexing rules apply (positive from 0 to count from the first run up and negative from -1 to count from the last run down). The default value of -1 returns the compositions of the final rescaling run. Note that if ID != -1 this function will not check for Z complience with ZALEX.
- Returns
X (float) – Hydrogen Mass Fraction
Y (float) – Helium Mass Fraction
Z (float) – Metal Mass Fraction
- Raises
MassFractionError – If the compositions dont properly validate
MassFractionError – If rsclz does not match zalex
- get_mass()¶
Get a guarenteed accurate version of the mass of a model. This differs from the mass attribute of the model class (which is intended to be used when speed is most important) in that this function will account for mass rescaleing used in the control namelist file. The final mass rescale will be taken as the final mass of the model. Again note, this function totally ignores the value set by the mass argument to this class.
- Returns
mass – Mass of the final model to be evolved. This will be compared between the premsmodel and any rescalign masses used. Note that this assumes that the mass in the prems header is accurate
- Return type
float
- iso() pandas.core.frame.DataFrame ¶
Functional call to the __getitem__ method for the key iso
- Returns
- Return type
pandas.DataFrame
- Raises
RuntimeError – If the parser is not able to retrive a valid dataframe representation of the iso file contents.
Examples
Assuming the model has already been evolved and is called modelA
>>> iso = modelA.iso() >>> print(type(iso)) pandas.DataFrame
Note that this is equivilent to
>>> iso = modelA['iso'] >>> print(type(iso)) pandas.DataFrame
- log()¶
Get the contents of the short file log
- Returns
Dictionary of the short file with three keys, PHYSICSNamelist, CONTROLNamelist, and LOG. The first two are read from the short file NOT from the actual input, therefore they can be used to validate that the namelist files are being read in okay. The LOG key is everything after them.
- Return type
dict
- mod()¶
Get the contents of a model file. Currently only return the binary model. In future check if binary model is availible and if not fall back on ascii model. Will only work if the model has some model
- Returns
Dictionary with two keys: headers which is the headers for each card and cards wich is the 6xJSON array describing the run of parameters with radius for each NBN model.
- Return type
dict
- stash(path=None, data=False, compress=True)¶
Save dsep model to disk so that it can be easily reloaded latter. Model will be stored as a json file
- Parameters
path (str, optional) – Path to save model to. If not set it will save to the output directory as model.dsep
data (bool, default=False) – If true the entire output of dsep will be stored in the dump, otherwise they will not be and only references to them will be stored. This is very important for portability
compress (bool, default=True) – If true zlib will be used to compress parts of the json file saves (both input and output files). If false that will not happen. If compression is enabled a flag will be added to the dictionary called “compress” and set to true to that the loading function knows to decompress. Note that compression will slow down stashing.
- trk() pandas.core.frame.DataFrame ¶
Functional call to the __getitem__ method for the key track
- Returns
- Return type
pandas.DataFrame
Examples
Assuming the model has already been evolved and is called modelA
>>> trk = modelA.trk() >>> print(type(trk)) pandas.DataFrame
Note that this is equivilent to
>>> trk = modelA['track'] >>> print(type(trk)) pandas.DataFrame
- update_composition(X: Optional[float] = None, Y: Optional[float] = None, Z: Optional[float] = None, ID: int = 0)¶
Self consistently update the composition of DSEP stellar model. Only two of the three classical compositions have to be passed, tho the function will work if all three are passed. Will update composition in rescaling run in addition to zalex for low-temperature opacities.
- Parameters
X (float,optional) – Hydrogen mass fraction
Y (float,optional) – Helium mass fraction
Z (float,optional) – Metal Mass fraction
ID (int, default=0) – ID of rescaling run to set compositions for
pysep.dsep.load module¶
**Author:**Thomas M. Boudreaux
**Last Modified:**February 2022
Utilities for loading dsep models from Disl
Functions¶
- load_model
Load previously stashed dsep model and attempt to update paths so that all its functions are still usable.
- pysep.dsep.load.load_model(path: str, loadOnly: bool = True, verbose: bool = False, forceEndCard: bool = False, contentSizeThreshold: int = 100)¶
Load previously stashed dsep model and attempt to update paths so that all its functions are still usable.
- Parameters
path (str) – path to stashed dsep model (JSON file)
loadOnly (bool, default=True) – If true the loaded DSEP model will not be able to be evolved. This is helpful for passing data to computers which may not have DSEP installed on them.
verbose (bool, default=False) – If true print out some debugging info to stdout
forceEndCard (bool, default=True) – If true then models will only be allowed to be read if an end card is identified. If not an exception will be thrown. NOTE: In the future this will become the default behavior. However, currently the default is to attempt to read models without end cards to maintain more seemless backwards compatibility.
contentSizeThreshold (int, default=100) – threshold in number of charecters between intro and endcard to consider file broken (really could be closer to ten thousand or 100 thousand charecters but 100 is okay). If there are less charecters than this between the first 3 and last three bytes of the file then the file will be flagged as broken.
- Returns
mod (pysep.dsep.stellarModel) – Stellar model object. This will be portable to any computer. If the input an output paths are exist at the same location on the loading client then they will be used, otherwise, assuming the model has been stashed with data, all missing files will be stored in a temporary directory so that they can be accessed.
tmpDir (tempfile.TemporaryDirectory) – Temporary Directory where files are stored. It is important to keep this in scope so that the files don’t get deleted prematurly.
- Raises
DSEPModelFormatError – If no end card is present and forceEndCard is set to True
DSEPModelFormatError – If there are no bytes between the intro and the end card (total file size is 6 bytes)
DSEPModelFormatError – If there are less than contentSizeThreshold bytes between the intro and the endcard (total file size is less than or equal to 6+contentSizeThreshold bytes)
Examples
Given some stellarModel which has been saved to disk with stash() to /home/janesmith/DSEP/output/model.dsep here is an example of how to load it back.
>>> from pysep.dsep.load import load_model >>> model, tdir = load_model("/home/janesmith/DSEP/output/model.dsep")
You can now interact with this model the same as you would any model. If it has been evolved you will be able to call the iso and track files just as regular.
pysep.dsep.utils module¶
Author: Thomas M. Boudreaux
Created: November 10 2020
Last Modified: September 2021
Python script to run DSEP portably. This script will automatically update paths that are relevant so you don’t have to manually do that.
Functions¶
- config_env
Configure enviroment for DSEP to run. Sets paths to data tables nessisarity for DSEP to run. These paths are then key-valued to the relevant unit number DSEP expects.
- config_output_files
Read in the control namelist file and update all releavant paths in that file for the local system.
Clear all fortran unit files in the current working directory. Sesolve physics and control namelist file paths to absolute paths, and link these to the correct unit numbers in the dictionary. Link the output files to the correct unit numbers in the dictionary. Finally, symbolically link all the key-value pairs in the dictioary to unit files and actual files on disk. After sucessfully running all Unit files nessisairy for DSEP to run will be present in the current working directory and linked to their requisite files eleswhere on disk. A new file will exist, with the same name as the control namelist file but with _ul appened (for updated local). This file will have the correct paths for the local system inside of it. This is generated automatically every time, and this is actually the control namelist file ultimately used by DSEP.
- run_dsep
Configure the system and Invoke the DSEP executable
- pysep.dsep.utils.config_env(branch: Optional[str] = None, default: bool = True) str ¶
Configure enviroment for DSEP to run. Sets paths to data tables nessisarity for DSEP to run. These paths are then key-valued to the relevant unit number DSEP expects.
- Parameters
branch (str, optional) – git branch of executable to run.
default (bool, default=True) – if true use the despX executable in the dsepX root root path
- Returns
prog – absolute path to the DSEP executable.
- Return type
str
- Raises
OSError – If the path to the dsep executable does not exist.
Examples
Let’s say you want to get the absolute path to the DSEP executable. You do not want to get any specific branch and just want the executable named dsepX by the makefile by default. Lets also assume that the DSEPRoot enviromental variable is equal to DSEPRoot=/home/janesmith/DSEP.
>>> dsepXPath = config_env() >>> print(dsepXPath) /home/janesmith/DSEP/dsepX/dsepX
Let’s say that you now want to get the path to the dsep executable compiled on the foo branch
>>> dsepXPath = config_env(branch='foo', default=False) >>> print(dsepXPath) /home/janesmith/DSEP/dsepX/build/dsepX.foo
- pysep.dsep.utils.config_output_files(template: str, ext: str = '.ext') dict ¶
Read in the control namelist file and update all releavant paths in that file for the local system.
Clear all fortran unit files in the current working directory. Sesolve physics and control namelist file paths to absolute paths, and link these to the correct unit numbers in the dictionary. Link the output files to the correct unit numbers in the dictionary. Finally, symbolically link all the key-value pairs in the dictioary to unit files and actual files on disk. After sucessfully running all Unit files nessisairy for DSEP to run will be present in the current working directory and linked to their requisite files eleswhere on disk. A new file will exist, with the same name as the control namelist file but with _ul appened (for updated local). This file will have the correct paths for the local system inside of it. This is generated automatically every time, and this is actually the control namelist file ultimately used by DSEP.
- Parameters
template (path) – template path to where output files names with .ext extension. .ext extension will be replaced with relevant extensions.
ext (str, default=".ext") – extension to look for and replace in default filename with dsep output file extensions.
- Returns
runFort – dictionary with the paths to all of the system linked files indexed by their integer unit numbers.
- Return type
dict
Examples
Let’s say you want your output files to live at /home/janesmith/DSEP/output and have the general form of m100.solar.extension where extension is different on a file to file basis (such as .iso, .track, .short, and so on). The following example will create these files and system link all these files to the corrent unit files in the current working directory.
>>> config_output_files("/home/janesmith/DSEP/output/m100.solar.ext")
- pysep.dsep.utils.get_iso_closest_to_age(iso, age)¶
- pysep.dsep.utils.get_model_closest_to_age(model, age)¶
- pysep.dsep.utils.hash_file(filename)¶
“This function returns the SHA-1 hash of the file passed into it
- pysep.dsep.utils.run_dsep(outDir: str, cnml, pnml, prog: str, dfiles: list, templateFilename: str, debug: bool = False, rr: bool = False, alert: bool = False) dict ¶
Configure the system and Invoke the DSEP executable
- Parameters
outDir (dict) – directory to where output files will be saved
cnml (pysep.io.nml.control.control.cnml) – control namelist file object
pnml (pysep.io.nml.physics.physics.pnml) – physics namelist file object
prog (str) – path to DSEP executable
dfiles (list([pysep.dm.generic_file])) – list of files, objects inheriting from gerneric_file to locally symlink. Such as opac and prems files.
templateFilename (str) – default filename with .ext extension, .ext extension will be replaced with approprite extension for each output file.
debug (bool, default=False) – run dsep with gdb debugger
rr (bool, default=False) – run with the rr reverse debuger (will overwrite gdb)
alert (bool, default=False) – Run with additional stdout debugging output. This includes printing which input files are linked to which output files and printing out all unit files with their links right before the dsepX executable is called.
- Returns
outputForts – dictionary with the paths to all of the system linked files indexed by their integer unit numbers. This includes input and output files.
- Return type
dict
Examples
Below is an example of how to run dsep with run_dsep. This can be thought of as the manual, or non object oriented interface to dsep through pysep.
>>> from pysep.io.nml.control.defaults import solar >>> from pysep.io.nml.physics.defaults import phys1 >>> from pysep.prems.defaults import m100_gs98 >>> from pysep.opac.opal.defaults import GS98hz >>> from pysep.opac.conduct.defaults import fermi >>> from pysep.atm.kur.defaults import atmk1990p00 >>> from pysep.atm.phx.defaults import z_p0d0_afe_p0d0 >>> from pysep.atm.phx.defaults import z_m0d5_afe_p0d0 >>> from pysep.atm.phx.defaults import z_m0d7_afe_p0d0 >>> from pysep.atm.phx.defaults import z_m1d0_afe_p0d0 >>> from pysep.atm.phx.defaults import z_m1d5_afe_p0d0
>>> outDir = "/home/janesmith/DSEP/output" >>> dfiles = [m100_gs98, GS98hz, atmk1900p00, fermi, z_p0d0_afe_p0d0, >>> z_m0d5_afe_p0d0, z_m0d7_afe_p0d0, z_m1d0_afe_p0d0, >>> z_m1d5_afe_p0d0]
>>> executable = config_env() >>> templateFileName = "m100.solar.ext"
>>> outputFiles = run_dsep(outDir, solar, phys1, executable, dfiles, >>> templateFileName)
While this method of calling dsep does work, using the stellarModel object and its evolve method should generally be prefered.
Module contents¶
Module for calling DSEP. Handels setting up the enviroment so that the dsep executable can run as well as the stellarModel class which packages all of the nice stuff up together in one place.
Sub modules¶
stellarModel -> pysep.dsep.dsepModel.model
Example
Creating a stellar model for a 1 solar mass gs98 composition star.
>>> from pysep.dsep import stellarModel as sm
>>> from pysep.opac.opal.defaults import GS98hz
>>> from pysep.prems.defaults import m100.gs98
>>> from pysep.io.nml.control.defaults import solar
>>> from pysep.io.nml.control.defaults import phys1
>>> model = sm(".", solar, phys1, GS98hz, m100.gs98)
Evolving this model is as simple as
>>> model.evolve()
If you want to access some information about an model after it has been evolved you can access both the track file and the iso file
>>> iso, isoMetadata = model.iso()
>>> trk, trkMetadata = model.track()
You can also access these with getitem
>>> iso. isoMetadata = model['iso']
>>> trk, trkMetadata = model['trk']
The form of the iso, trk, and metadata variables is given in more detail in the io.iso and io.trk modules.
What if you want to read in a different bckur file from disk?
>>> from pysep.dsep import stellarModel as sm
>>> from pysep.opac.opal.defaults import GS98hz
>>> from pysep.prems.defaults import m100.gs98
>>> from pysep.io.nml.control.defaults import solar
>>> from pysep.io.nml.control.defaults import phys1
>>> from pysep.dm.filetypes import bckur_file
>>> bckurPath = "./atmk1990p00.tab"
>>> bckur = bckur_file(bckurPath)
>>> model = sm(".", solar, phys1, GS98hz, m100.gs98, bckur=bckur)
>>> model.evolve()
By default the bckur, bcphx95, bcphx96, bcphx97, bcphx98, and bcphx99 parameters are all set for a model so that you can get up and running a little more quickly. However, the opacity file, premain sequence model, physics, and control namelist files all must be passed every time.
However, you can always load your own versions of any file. Lets say you had a control namelist file called cont.nml in the local directory which you wanted to use
>>> from pysep.io.nml.control import load
>>> customControlNamelist = load('cont.nml')
>>> from pysep.io.nml.control.defaults import phys1
>>> from pysep.opac.opal.defaults import GS98hz
>>> from pysep.prems.defaults import m100.gs98
>>> from pysep.dsep import stellarModel as sm
>>> model = sm(".", customControlNamelist, phys1, GS98hz, m100.gs98)
>>> model.evolve()
The output from dsep runs will save to whatever directory was specified as the first parameter to the stellarModel constructor. If you want to be able to access the model object latter (not nessisairy but may help with convience) you can “stash” the model which will simply pickle it to the same directory as the dsep output was saved. The model will save with the name model.dsep.
>>> model.stash()
If you want to load a model again in you can (assuming you are in the same directory as the model.dsep file) do the following:
>>> from pysep.dsep.utils import load_model
>>> model = load_model("./model.dsep")