Skip to content

reading and processing outputs

Knox S. Long edited this page Aug 9, 2018 · 6 revisions

The py_progs folder contains some programs for reading outputs. Add the py_progs folder to your $PYTHONPATH. you might want to import the following modules:

import py_read_output as rd
import py_plot_output as plot
import pylab as p
import py_plot_util as util

Astropy

To read ASCII outputs, Python mostly uses the astropy.io.ascii module. To install astropy type

pip install astropy

or visit the astropy website

Reading Spectra

With the new (as of November 2014) file formats which are consistent with astropy, one can read a spectrum, or spec_tot file with the following commands

from astropy.io import ascii
spectrum = ascii.read(filename)

one can then a spectrum with the column headings, e.g.

p.plot(spectrum["Lambda"], spectrum["A10P0.50"])

and view the column headings with

print s.colnames                      

Alternatively, use the py_read_output module to read into an astropy.table.table.Table object

spectrum = rd.read_spectrum(filename)

one can then plot a spectrum as above, or use py_plot_output to make a standard plot from an astropy.table.table.Table object:

plot.make_spec_plot(spectrum, filename)

Reading Wind properties

To read a wind file, you first need to have compiled py_wind. You can then run this from a python shell to generate a complete summary of wind properties by typing

util.get_pywind_summary(filename)

you can then read the data from filename.complete into an astropy Table

data = rd.read_pywind_summary(filename)

and reshape into a masked array for a given colname, e.g. ne or lum_lines

x,z,ne = util.wind_to_masked (data, "ne")

contour plots can then be created with

p.contourf(z,x,np.log10(ne))      # note that contourf takes z as first argument

Alternatively, running the following will make a standard set of contourf plots for the user

plot.make_wind_plot(data, filename, var = ["ne", "te", "tr", "IP", "nphot", "v", "w", "ionC4"], shape=(4,2) )

and if data is set to Nonetype then the program will actually run py_wind and read in filename.complete for you.

Adding extra variables

Sometimes, certain variables aren't stored in the .complete file. In this case, you need to run py_wind to printout the relevant variable to file and then add a column to the data you have read in. For example, if you want to add ionC6 to the "data" astropy.table you have defined above:

util.run_py_wind(filename, cmds=["1","i","0","6","6","q"])
x,z,ion_data = rd.read_pywind(filename + ".ionC6.dat")
ion_data_column = astropy.table.Column(ion_data.flatten(), "ionC6")
data.add_column(ion_data_column)

This is a fairly convoluted and hacky way to add the data into the astropy.table object, which should be improved. You can also just make an individual plot of the ion_data without having to add it on to the data structure:

p.pcolormesh(x,z,ion_data)

Read a parameter file

pf = rd.read_pf("sv")

View the disk mdot rate

print pf['disk.mdot(msol/yr)']

Additionally there are two routines that can be run from the command line to produce standard plots of the spectra.

These routines require astropy and scipy to have been installed

  • plot_spec.py rootname produces a plot of the final spectra (at each inclination angle)
  • plot_tot.py rootname produces a plot of the total spectra (of various types) for the last ionization cycle

In both cases, one can additional help by invoking the routine with a -h switch. By default, the spectra are smoothed. The amount of smoothing can be contrlled by command line switches.

The results are .png files.