Python Scripts

There are several Python (the scripting language) scripts written to prepare input for and analyse the output of python (the C code).

Some of the more useful scripts/modules are documented below. Alternatively, you can generate documentation for all the scripts by navigating to docs/pydocs and running write_docs.py. The resulting output file can be found here.

Todo

Finish adding modules below.

py_read_output

Synopsis:

This program enables one to read outputs from the Python radiative transfer code. Where possible, we use the astropy.io module to read outputs. There are also a number of routines for processing and reshaping various data formats

see https://github.com/agnwinds/python/wiki/Useful-python-commands-for-reading-and-processing-outputs for usage

Usage:

Arguments:

py_read_output.read_convergence(root)

check convergence in a diag file

py_read_output.read_emissivity(root)

Read macro atom emissivities from a root diag file. Returns two arrays, kpkt_emiss and matom_emiss.

py_read_output.read_pf(root)

reads a Python .pf file and returns a dictionary

Parameters
rootfile or str

File, filename to read.

new:

True means the Created column exists in the file

Returns
pf_dict

Dictionary object containing parameters in pf file

py_read_output.read_pywind(filename, return_inwind=False, mode='2d', complete=True)

read a py_wind output file using np array reshaping and manipulation

Parameters
filenamefile or str

File, filename to read, e.g. root.ne.dat

return_inwind: Bool

return the array which tells you whether you are partly, fully or not inwind.

mode: string

can be used to control different coord systems

Returns
x, z, value: masked arrays

value is the quantity you are concerned with, e.g. ne

py_read_output.read_pywind_summary(filename, return_inwind=False, mode='2d')

read a py_wind output file using np array reshaping and manipulation

Parameters
filenamefile or str

File, filename to read, e.g. root.ne.dat

return_inwind: Bool

return the array which tells you whether you are partly, fully or not inwind.

mode: string

can be used to control different coord systems

Returns
d: astropy.Table.table.table object

value is the quantity you are concerned with, e.g. ne

py_read_output.read_spectrum(filename)

Load data from a spectrum output file from the radiative transfer code Python

Parameters:

filename : file or str

File, filename, or generator to read. If the filename extension is .gz or .bz2, the file is first decompressed. Note that generators should return byte strings for Python 3k.

Returns

Success: spectrum returns a Table of class astropy.table.table.Table

Failure returns 1

py_read_output.read_spectrum_to_class(filename, new=True)

reads a Python .spec file and places in specclass array, which is returned

Parameters
filenamefile or str

File, filename to read.

new:

True means the Created column exists in the file

Returns

Success: spectrum returns a spectrum class cls.specclass

Failure returns 1

py_read_output.setpars()

set some standard parameters for plotting

py_read_output.thinshell_read(root)

Read py_wind output filename for thin shell models with one cell

py_read_output.write_pf(root, pf_dict)

writes a Python .pf file from a dictionary

Parameters
rootfile or str

File, filename to write.

pf_dict:

dictionary to write

Returns
pf_dict

Dictionary object containing parameters in pf file

py_plot_output

Synopsis:

various plotting routines for making standard plots from Python outputs

Usage:

Either import as a module in a python session e.g. import py_plot_output as p

or run from the command line e.g.

py_plot_output root mode [roots to compare]

Arguments:
root

root filename to analyse

mode

mode of plotting wind plot of common wind quantites ions plot of common ions spec spectrum for different viewing angles spec_comps components contributing to total spectrum e.g. disk, wind compare compare the root to other roots to compare all make all the above plots

py_plot_output.make_spec_comparison_plot(s_array, labels, fname='comparison', smooth_factor=10, angles=True, components=False)

make a spectrum comparison plot from array of astropy.table.table.Table objects. Saves output as “spectrum_%s.png” % (fname)

Parameters:
s_array: array-like of astropy.table.table.Table objects

table containing spectrum data outputted from Python

labels: array-like

strings of labels for each spectrum

fname: str

filename to save as e.g. sv

smooth_factor: int

factor you would like to smooth by, default 10

angles: Bool

Would you like to plot the viewing angle spectra?

components: Bool

would you like to plot the individual components e.g. Disk Wind

Returns:

Success returns 0 Failure returns 1

py_plot_output.make_spec_plot(s, fname, smooth_factor=10, angles=True, components=False, with_composite=False)

make a spectrum plot from astropy.table.table.Table object. Saves output as “spectrum_%s.png” % (fname)

Parameters:
s: astropy.table.table.Table

table containing spectrum data outputted from Python

fname: str

filename to save as e.g. sv

smooth_factor: int

factor you would like to smooth by, default 10

angles: Bool

Would you like to plot the viewing angle spectra?

components: Bool

would you like to plot the individual components e.g. Disk Wind

Returns:

Success returns 0 Failure returns 1

py_plot_output.make_spec_plot_from_class(s, fname, smooth_factor=10, angles=True, components=False)

make a spectrum plot from py_classes.specclass object. Saves output as “spectrum_%s.png” % (fname)

Parameters:
s: specclass object

table containing spectrum data outputted from Python

fname: str

filename to save as e.g. sv

smooth_factor: int

factor you would like to smooth by, default 10

angles: Bool

Would you like to plot the viewing angle spectra?

components: Bool

would you like to plot the individual components e.g. Disk Wind

Returns:

Success returns 0 Failure returns 1

py_plot_output.make_wind_plot(d, fname, var=None, shape=(4, 2), axes='log', den_or_frac=0, fname_prefix='wind', lims=None)

make a wind plot from astropy.table.table.Table object. Saves output as “spectrum_%s.png” % (fname)

Parameters:
d: astropy.table.table.Table

table containing wind data outputted from Python if == None then this routine will get the data for you

fname: str

filename to save as e.g. sv

var: array type

array of string colnames to plot

angles: Bool

Would you like to plot the viewing angle spectra?

components: Bool

would you like to plot the individual components e.g. Disk Wind

axes: str

lin or log axes

den_or_frac: int

0 calculate ion densities 1 calculate ion fractions

lims: array-like

limits of plot, specified as ((xmin,xmax), (ymin, tmax)) can be array or tuple. Default is Nonetype.

Returns:

Success returns 0 Failure returns 1

py_plot_util

Synopsis:

various utilities for processing Python outputs and plotting spectra and wind properties

Usage:

Arguments:

py_plot_util.get_flux_at_wavelength(lambda_array, flux_array, w)

Find the flux at wavelength w

Parameters:
lambda_array: array-like

array of wavelengths in angstroms. 1d

flux_array: array-like

array of fluxes same shape as lambda_array

w: float

wavelength in angstroms to find

Returns:
f: float

flux at point w

py_plot_util.get_pywind_summary(fname, vers='', den_or_frac=0)

run version vers of py_wind on file fname.wind_save and generate the complete wind summary as output

produce the output fname.complete to read

if den_or_frac is 1, return fractions, otherwise densities

py_plot_util.parse_rcparams(fname='params.rc')

parse the file params.rc and set values in matplotlib.rcparams

file should be of format

font.family : serif mathtext.fontset : custom

py_plot_util.read_pywind_smart(filename, return_inwind=False)

read a py_wind file using np array reshaping and manipulation

DEPRECATED

py_plot_util.run_py_wind(fname, vers='', cmds=None, ilv=None)

run version vers of py_wind on file fname.wind_save

py_plot_util.smooth(x, window_len=20, window='hanning')

smooth data x by a factor with window of length window_len

py_plot_util.wind_to_masked(d, value_string, return_inwind=False, mode='2d')

turn a table, one of whose colnames is value_string, into a masked array based on values of inwind

Parameters:
d: astropy.table.table.Table object

data, probably read from .complete wind data

value_string: str

the variable you want in the array, e.g. “ne”

return_inwind: Bool

return the array which tells you whether you are partly, fully or not inwind.

Returns:
x, z, value: Floats

value is the quantity you are concerned with, e.g. ne

run_check

Synopsis:

Sumarize a model run with python, ultimately generating an html file with various plots, etc.

Command line usage (if any):

run_check.py root1 [root2 …]

run_check.py root1.pf [root2.pf …]

run_check -all

run_check -h

Description:

This routine performs basic checks on one or more python runs and creates an html file for each that is intended to provide a quick summary of a run.

The user can enter the runs to be tested from the command line, either in the form of a set of root names or .pf names. Wildcarding, e.g *.pf can be used. *.out.pf files will be ignored.

Alternatively to process all of the files in a directory, one can use the switch -all (which supercedes anything else).

In all cases the routine checks to see if the appropriate wind_save file exists before attempting to run.

-h delivers this documentation

Primary routines:

doit - processes a single file steer - processes the command line and calls doit for each file.

Notes:

run_check.check_completion(root)

Verify that the run actually completed and provide information about the timeing, from the .sig file

run_check.doit(root='ixvel', outputfile='out.txt')

Create a summary of a Python run, which will enough information that one can assess whether the run was successful

Description:

Notes:

History:

run_check.how_many_dimensions(filename)

Check whether a windsave file is one or two dimenaions

run_check.make_html(root, converge_plot, te_plot, tr_plot, spec_tot_plot, spec_plot, nspectra=3, complete_message=['test'], errors=['test', 'test2'])

Make an html file that collates all the results

run_check.plot_converged(root, converged, converging, t_r, t_e, hc)

Make a plot of the convergence statistics in the diag directroy

run_check.py_error(root)

Run py_error.py and capture the output to the screen

Note:

py_error could be refactored so that it did not need to be run from the command line, but this is the simplest way to capture the outputs at present

run_check.read_diag(root)

Get convergence and possibly other information from the diag file

run_check.steer(argv)

Process the command line

run_check.windsave2table(root)

Run windsave2table

import_cyl

Synopsis:

Read the master file produced by windsave2table for a model created in cylindrical coordinates and produce a file which can be imported into Python and run

Command line usage (if any):

import_cyl.py rootname where rootname is the rootname of the mastertable or windsave file

Description:

This operates on the mastertable produced by windsavetable

Primary routines:

doit

Notes:

import_cyl.doit(root='cv', outputfile='')

Read a master.txt file for models in cylindrical coordinates and produce a file which can be read in to python

Description:

Notes:

History:

import_cyl.read_file(filename, char='')

Read a file and split it into words, eliminating comments

char is an optional parameter used as the delimiter for splitting lines into words. Otherwise white space is assumed.

import_cyl.read_table(filename='foo.txt', format='')

Read a file using astropy.io.ascii and return this

Description:

Notes:

History: