Model Usage¶
pysep provides a handy interface to call DSEP. Note that because pysep is still under development the interface may be subject to change; however, the majority of it is locked in at this point. Therefore, most of what is in this help documnt should be applicable for the forseable future.
The basic operating principal of the pysep interface is to package every file that would be linked as a fort.# as a python object. These can then be manipulated within python. Finally, a “StellarModel” takes in all these python objects and handels setting up the enviroment (i.e. symlinking the fort.# files) and running the dsepX executable.
There are “defaut” files prepacked within pysep in addition to routines to read in any custom files which may be desired.
Here is a simple example using only “default” files
from pysep.io.nml.control.defaults import solar
from pysep.io.nml.physics.defaults import phys1Low
from pysep.prems.defaults import m100_GS98
from pysep.opac.opal.defaults import GS98hz
from pysep.dsep import stellarModel as sm
outputPath = "."
# set up the model
model = sm(outputPath, solar, phys1Low, GS98hz, m100_GS98)
# run the dsep executable with the given control namelist file (in this case solar)
model.evolve()
# save the model object so it can be loaded back into pysep in the future
model.stash()
Now lets say you wanted to modify the endage on the evolution run of dsep so that the model evolves till DSEP crashes out, you could instead do
from pysep.io.nml.control.defaults import solar
from pysep.io.nml.physics.defaults import phys1Low
from pysep.prems.defaults import m100_GS98
from pysep.opac.opal.defaults import GS98hz
from pysep.dsep import stellarModel as sm
outputPath = "."
solar[1]['endage'] = -solar[1]['endage']
# set up the model
model = sm(outputPath, solar, phys1Low, GS98hz, m100_GS98)
# run the dsep executable with the given control namelist file (in this case solar)
model.evolve()
# save the model object so it can be loaded back into pysep in the future
model.stash()
Finally, lets say you had some other opacity file and premain sequence model you wanted to use in place of one of the defaults packaged with dsep
from pysep.io.nml.control.defaults import solar
from pysep.io.nml.physics.defaults import phys1Low
from pysep.dm.filetypes import opacf_file, premsf_file
from pysep.dsep import stellarModel as sm
outputPath = "."
opacFilePath "./opalFormatedOpacFile"
premsFilePath="./premsFile"
opac = opacf_file(opacFilePath)
prems = premsf_file(premsFilePath)
solar[1]['endage'] = -solar[1]['endage']
# set up the model
model = sm(outputPath, solar, phys1Low, opac, prems)
# run the dsep executable with the given control namelist file (in this case solar)
model.evolve()
# save the model object so it can be loaded back into pysep in the future
model.stash()
Reading DSEP output¶
pysep provides the ability to read dsep output. You can either use the included functions directly (if you don’t want to load up a full StellarModel) or you access the results from a StellarModel within the object.
An example of directly reading an iso and track file is given below
import pysep.io.iso import read_iso
import pysep.io.trk import read_trk
isoFile = read_iso("path/to/iso/file")
trkFile = read_trk("path/to/trk/file")
Here isoFile and trkFile are both pandas dataframes. Note that reading in the trk file can be quite slow right now. One current task is to rewrite that parser in C/C++ to speed up the reading.
If instead you wanted to access the results from a StellarModel you could do
from pysep.io.nml.control.defaults import solar
from pysep.io.nml.physics.defaults import phys1Low
from pysep.prems.defaults import m100_GS98
from pysep.opac.opal.defaults import GS98hz
from pysep.dsep import stellarModel as sm
outputPath = "."
solar[1]['endage'] = -solar[1]['endage']
# set up the model
model = sm(outputPath, solar, phys1Low, GS98hz, m100_GS98)
# run the dsep executable with the given control namelist file (in this case solar)
model.evolve()
print(model['iso'])
print(model['track'])
If you ran a StellarModel and stashed it and want to access it in the future you can simply use
from pysep.dsep.utils import load_model
path = "path/to/stashed/model.dsep/file"
model = load_model(path)
print(model['iso'])
print(model['track'])
Other things¶
In addition to the functions given above, pysep currently has a few more abilities. In no particular order
1) Query opacities from the TOPS web form and put them into a form dsep will understand
2) Generate pre main sequence models for arbitrary chemical compositions over a range of masses
3) Automatically read in a directory full of either iso or trk files
Over time I will expand pysep to give more control over dsep from within python. For now though this is at least somewhat helpful.