growpacity package

Submodules

growpacity.growpacity module

growpacity.growpacity.BBflux(T=<Quantity 5780. K>, wl=<Quantity 0.0001 cm>)

Returns the flux spectrum of a black body at wavelength λ and temperature T. The flux is calculated assuming:

f = exp(h*c/(λkT))
B(λ) = 2hc^2/λ^5 / (f - 1)
u(λ) = 2h^2c^3 / (^6T^2) * exp / (exp-1)

Arguments

Tarray-like [K] or astropy.units.Quantity

the temperature of the black body.

wlarray-like [cm] or astropy.units.Quantity

the wavelengths to sample on.

Returns

Bastropy.units.Quantity [erg/(cm^2 s cm)]

the black body flux at the requested wavelengths

dB/dTastropy.units.Quantity [erg/(cm^2 s K cm)]

the derivative of the black body flux with respect to temperature

class growpacity.growpacity.OpacityCalculator(amin=<Quantity 1.e-05 cm>, q_min=-4.5, q_max=-2.5, Nq=9, amax_min=<Quantity 1.e-05 cm>, amax_max=<Quantity 1. cm>, Namax=14, T_min=<Quantity 1. K>, T_max=<Quantity 3000. K>, NT=100, optool_args='', dirc='data/', name='', read_in=False)

Bases: object

Master class that handles the opacity calculations. This is the meat of the code: basically call OpTool repeatedly over the range of grain size distributions requested, and then compute Rosseland and Planck means and store them into files. I’m defining it as a class, in case you would like to use it in python format in another project where you want access to metadata.

Input (when marked with […], can be an astropy Quantity that defaults to unit “…”)

Arguments

aminfloat or astropy.units.Quantity [μm]

minimum grain size for all distributions

q_minfloat

smallest powerlaw exponent within the range of distributions

q_maxfloat

largest powerlaw exponent within the range of distributions

Nqint

number of samples between q_min and q_max. Linear spacing.

amax_minfloat or astropy.units.Quantity [μm]

smallest maximum grain size within the range of distributions

amax_maxfloat or astropy.units.Quantity [μm]

largest maximum grain size within the range of distributions

Namaxint

number of samples between amax_min and amax_max. Logarithmic spacing.

T_minfloat or astropy.units.Quantity [K]

smallest temperature to sample when computing means

T_maxfloat or astropy.units.Quantity [K]

largest temperature to sample when computing means

NTint

number of samples between T_min and T_max. Logarithmic spacing.

optool_argsstr

additional arguments to be passed to optool, beyond grain size distributions (e.g., composition).

dircstr

directory to save the data (about 20KB/file for absorption coefficients, 230B*NT/file for mean opacities).

namestr

identifier to be appended to the file name.

The complete filenames will be:

{dirc}/{name}_a{amax}_q{q}.inp for absorption coefficients {dirc}/{name}_a{amax}_q{q}.dat for mean opacities

build_mean_opacities(overwrite=False)

Loop over all files of absorption coefficients and print ASCII files with the respective temperature-dependent mean opacities. If not overwrite, it skips existing files with that name.

compute_and_store_master_arrays(overwrite=False)

Stores 1D arrays of q, amax T, and the 3D arrays of kappa_Rosseland(q, amax, T) and kappa_Planck(q, amax, T). If overwrite and a file exists, skip it.

compute_master_arrays()

Loads all files of mean opacities and combines them into master arrays of κ(q, amax, T).

execute_optool(quiet=False, suppress_dots=True, overwrite=False)

Repeatedly calls OpTool over the range of amax and q requested.

Arguments

quietbool, optional [False]

If quiet, suppresses all output from this function.

suppress_dotsbool, optional [True]

If suppress_dots, hides all the dots (“progress bar”) in OpTool output.

overwritebool, optional [False]

If overwrite, re-runs optool even if the output file exists.

get_filename(amax, q)

Helper function that returns the file name (excluding prepended ‘dustkappa/kappaRP’) for a given amax and q.

load_master_arrays()

If master arrays have already been computed, load them directly.

growpacity.growpacity.compute_mean_opacities(T, filename)

Computes Rosseland and Planck means from a given file with absorption coefficients.

Arguments

Tarray-like or astropy.units.Quantity [K]

array of temperatures at which to compute the means.

filenamestr

path to the file with absorption coefficients.

Returns

kRastropy.units.Quantity [cm^2/g]

Rosseland mean opacities at the requested temperatures.

kPastropy.units.Quantity [cm^2/g]

Planck mean opacities at the requested temperatures.

growpacity.growpacity.evaluate_mean_opacities(q_arr, amax_arr, T_arr, kappa_arr, q, amax, T, use_scipy=False)
Wrapper around either:

the (normally) numba-jitted function __evaluate_mean_opacity_numba or the scipy-based function __evaluate_mean_opacities_scipy,

to allow for array-like inputs for q, amax, and T.

Arguments

q_arr1D array

1D array of powerlaw exponents

amax_arr1D array

1D array of maximum grain sizes [cm]

T_arr1D array

1D array of temperatures [K]

kappa_arr3D array

3D array of opacities [cm^2/g]

qfloat or array-like

requested powerlaw exponent

amaxfloat or array-like [cm] or astropy.units.Quantity

requested maximum grain size

Tfloat or array-like [K] or astropy.units.Quantity

requested temperature

use_scipybool, optional [False]

Whether to use the scipy-based function for evaluation. If False (default), uses the numba-jitted function. The scipy function is used automatically if numba is not installed, and might be faster for very large arrays. If both numba and scipy are not installed, the function falls back to a non-jitted version of the numba function. This will be slow.

Returns

kappa

the interpolated opacity [cm^2/g]

growpacity.growpacity.read_optool_file(filename)

Reads an optool output file and returns the wavelength, absorption, scattering, and asymmetry coefficients.

growpacity.growpacity.toQuantity(array, unit=Unit(dimensionless))

Checks if an array is an astropy Quantity. Converts it to one if not.

In that case, unit must be provided in the form of either plain text (compatible with astropy.units.Unit), or as an astropy.units.Unit.

Arguments

arrayarray-like or astropy.units.Quantity

Input array or quantity.

unitstr or astropy.units.Unit, optional

The unit to convert to if array is not a Quantity.

Returns

astropy.units.Quantity

The input array as a Quantity.

Module contents