diskpy.pychanga package

Module contents

Created on Wed Jul 15 16:37:00 2015

@author: ibackus

diskpy.pychanga.make_director(sigma_min, sigma_max, r, resolution=1200, filename=’snapshot’)[source]

Makes a director dictionary for ChaNGa runs based on the min/max surface density, maximum image radius, and image resolution for a gaseous protoplanetary disk. The created dictionary can be saved with diskpy.utils.configsave

The method is to use an example director file (saved as default.director) which works for one simulation and scale the various parameters accordingly. default.director should have a commented line in it which reads:

#sigma_max float

where float is the maximum surface density of the simulation in simulation units.

ARGUMENTS

sigma_min : float
The surface density that corresponds to 0 density on the image (ie the minimum threshold). Required for setting the dynamic range
sigma_max : float
Maximum surface density in the simulation
r : float
Maximum radius to plot out to
resolution : int or float
Number of pixels in image. The image is shape (resolution, resolution)
filename : str
prefix to use for saving the images. Example: if filename=’snapshot’, then the outputs will be of form ‘snapshot.000000000.ppm’

RETURNS

director : dict
A .director dictionary. Can be saved with diskpy.utils.configsave
diskpy.pychanga.make_param(snapshot, filename=None)[source]

Generates a default param dictionary. Can be saved using diskpy.utils.configsave

EXAMPLE

snapshot = pynbody.load(‘snapshot.std’) # Load snapshot param_dict = make_param(snapshot) # Make default param dict diskpy.utils.configsave(param_dict, ‘snapshot.param’, ftype=’param’) # Save

Optionally, the user can set the snapshot filename manually

diskpy.pychanga.units_from_param(param)[source]

Figures out the simulation units from a .param file

ARGUMENTS

param : str or param dict (see configparser)
Simulation .param file or param dict loaded by configparser Can also be a list or numpy array of these in which case a list of units dicts is returned

RETURNS

units : dict
A dictionary of the units used in the simulation, returned as pynbody units
diskpy.pychanga.setup_param(param, snapshot=None, r_orb=1.0, n_orb=10.0, n_image=None, n_snap=100, n_check=None)[source]

Sets up the following for a .param file:

nSteps dDumpFrameStep iOutInterval iCheckInterval

ARGUMENTS

param : str or param_dict (see diskpy.utils.configparser, configsave)
parameter file for the simulation, must already have dDelta and units set properly IF a str, assumed to be a filename
snapshot : str or TipsySnap(see pynbody) or None
Snapshot for the simulation. Needed to estimate the outer orbital period. IF a str, assumed to be a filename IF None, the file pointed to by param is used
r_orb : float
radius to calculate the outer orbital period at as a fraction of the radius of the farthest out particle. Must be between 0 and 1
n_orb : float
number of outer orbital periods to run simulation for
n_image : int or None
Total number of frames to dump (ie, dDumpFrameStep) If None, defaults to n_snap
n_snap : int
Total number of simulation outputs
n_check : int or None
Total number of simulation checkpoints. If None, defaults to n_snap
diskpy.pychanga.setup_units(m, x)[source]
Sets up units for a ChaNGa simulation, defined by position and mass units.
  • time unit = \(\sqrt{L_{unit}^3/G M_{unit}}\)
  • velocity unit = \(L_{unit}/T_{unit}\)
  • temperature units = Kelvin
Parameters:

m, x : Unit, string, or SimArray

Define the mass and position units

Returns:

units : dict

A dictionary containing the units

diskpy.pychanga.load_acc(filename, param_name=None, low_mem=False)[source]

Loads accelerations from a ChaNGa acceleration file (.acc2), ignoring the star particle. ASSUMES A SINGLE STAR PARTICLE

IF param_name is None, a .param file is searched for, otherwise param_name should be a string specifying a .param file name

IF no param_file is found, the defaults are used:
length unit: AU mass unit : Msol

Setting low_mem=True decreases memory usage by about 2x but also increases readtime by about 2x

diskpy.pychanga.walltime(filename, verbose=True)[source]

Reads walltime information from a ChaNGa .log file.

** ARGUMENTS **

filename : str
Filename of the .log file to load

** RETURNS **

wall_per_step : array
Wall time per step in seconds
diskpy.pychanga.get_fnames(fprefix, directory=None)[source]
Finds the filenames of ChaNGa simulation outputs. They are formatted as:
fprefix.000000

i.e., fprefix followed by ‘.’ and a 6 digit number

ARGUMENTS

fprefix : str
Prefix of the simulation outputs
directory : str (optional)
Directory to search through. Default is current working directory

RETURNS

fnames : list
A list containing the matching filenames
diskpy.pychanga.snapshot_time(f, paramname=None)[source]

Gets the physical time of a snapshot. t=0 corresponds to the initial conditions.

diskpy.pychanga.read_rung_dist(filename)[source]

Reads the rungdistribution from ChaNGa stdout that has been saved to a disk by grepping the file for “Rung dist” and interpreting the output.

Returns:

rung_dist : array

Rung distribution for all big steps. An array of integers of shape (num big steps, num rungs)

diskpy.pychanga.getpar(key, param={})[source]

Attempts to retrieve the key from param or from the ChaNGa default param options. Raises ValueError if key not found in either.

Parameters:

key : object

param : str or dict

Paramname or param dict (see diskpy.utils.configparser). If not supplied, only the ChaNGa defaults are searched

Returns:

value

The value, taken from param if present, otherwise taken from the ChaNGa default params

diskpy.pychanga.est_time_step(param_name, preset=’default’, dDelta0=100, changa_args=”, runner_args=”)[source]

A routine to automatically estimate a reasonable time-step size for ChaNGa. The idea is to have about half the particles fall into the lowest rung (ie the big time step). This is done by calculating the rung distribution for a large time step by running ChaNGa and killing ChaNGa once it has output rung distribution.

NOTE: this is still fairly alpha. A better version would probably not just run ChaNGa and then try to kill it. To be safe, a local ChaNGa preset should probably be used.

ARGUMENTS

param_name : str
Filename for a ChaNGa .param file which defines parameters for the snapshot. The snapshot must already be saved to disk
preset : str
changa_runner preset to use. See diskpy.global_settings
dDelta0 : int or float
Some large time step that should place all the particles at higher rungs.
changa_args : str
Additional command line arguments to pass to changa. CANNOT include -n (number of time steps) or -dt (timestep size)
runner_args : str
Additional command line arguments to pass to the runner, ie to charmrun or mpirun

RETURNS

dDelta : float
Estimated reasonable time step that places half the particles on the lowest rung (ie the big time step)
diskpy.pychanga.changa_run(command, verbose=True, force_wait=False, log_file=None, return_success=False, require_success=False)[source]

A wrapper for running ChaNGa

ARGUMENTS

command : str
A full command line command for running ChaNGa. Can be produced from defaults using ICgen_utils.changa_command
verbose : bool
(optional) Flag for printing ChaNGa output to stdout. If True - stdout is printed. This will effectively makes changa_run wait on ChaNGa completion
force_wait : bool
(optional) Default = False If set, forces wait on ChaNGa before completion
log_file : str
(optional) filename, if passed, the stdout will be also copied to log_file
return_success : bool
If set, returns the success of the run, i.e. checks to see if the simulation finished properly.
require_success : bool
If true, a RuntimeError will be raised if ChaNGa does not exit successfully

RETURNS

p : subprocess.Popen
A process object created by subprocess.Popen for the ChaNGa command
success : bool
IF return_success is set to True, the status of the run is returned instead of p.

status : bool

diskpy.pychanga.changa_command(param_name, preset=’default’, changa_bin=None, changa_args=”, runner_args=”, restart_dir=None)[source]

A utility for created command line commands for running ChaNGa

ARGUMENTS

param_name : str
Filename of the .param file used for ChaNGa
preset : str
if None or ‘default’, the default preset is used Presets are defined in global_settings
changa_bin : str
Path to the ChaNGa binary to use. If None, defaults are used Overrides preset binary
changa_args : str
Additional user supplied arguments for ChaNGa
runner_args : str
Additional user supplied arguments for the runner (ie charmrun or mpirun)
restart_dir : str
(optional) If set, this will be treated as a restart. All changa args will be ignored.

RETURNS

command : str
A command line command for running ChaNGa