qusp.model module¶
Provides support for modeling a universal quasar continuum.
Test laptop dev using:
time ./examples/fitspec.py --boss-root ~/data/boss -i test.txt -o fitspec-test -n 100 --verbose --sklearn --unweighted --z-col 3 --sn-col 5 --save-model --random
./examples/plotfitspec.py --boss-root ~/data/boss -i fitspec-test.hdf5 -o output/fitspec-test --force-y --save-model --examples 0 1 2 3 4
Test on darkmatter using:
time ./examples/fitspec.py --boss-root /data/boss -i sn-sorted.txt -o fitspec-test -n 1000 --verbose --sklearn --unweighted --z-col 3 --sn-col 5 --save-model --absscale 1 --random --tiltweight 1 --restnormweight 1 --obsnormweight 1e-1
./examples/plotfitspec.py --boss-root /data/boss -i fitspec-test.hdf5 -o output/fitspec-test --force-y --save-model --examples 150 300 450 600 750
Profile on darkmatter:
python -m cProfile -o profile-test.out ./examples/fitspec.py --boss-root /data/boss -i sn-sorted.txt -o specfits-test --verbose --sklearn --unweighted --z-col 3 --sn-col 5 --fix-norm --fix-tilt --obsnormweight 1e-2 --restnormweight 1 -n 10000
List top function calls by time:
import pstats
p = pstats.Stats('profile-test.out')
p.sort_stats('time').print_stats(10)
Generate call tree:
gprof2dot -f pstats profile-test.out | dot -Tpng -o profile-test.png
-
class
qusp.model.
ContinuumModel
(transmission_min, transmission_max, continuum_min, continuum_max, continuum_nparams, tiltwave, absorption_min, absorption_max, absorption_modelexp, absorption_scale, fix_transmission=False, continuum=None, verbose=False)¶ Bases:
object
Represents a linearized quasar continuum model.
Initializes a linearized quasar continuum model using the specified parameter limits and values.
Parameters: - transmission_min (float) – minimum observed frame wavelength bin center of transmission model.
- transmission_max (float) – maximum observed frame wavelength bin center of transmission model.
- continuum_min (float) – minimum rest frame wavelength bin center of continuum model.
- continuum_max (float) – maximum rest frame wavelength bin center of continuum model.
- continuum_nparams (int) – number of rest frame bins of continuum model.
- tiltwave (float) – pivot wavelength of rest frame spectral tilt.
- absorption_min (float) – minimum rest frame wavelength bin center of absorption model.
- absorption_max (float) – maximum rest frame wavelength bin center of absorption model.
- absorption_modelexp (float) – exponent of (1+z) factor of absorption model.
- absorption_scale (float) – internal scaling of absorption model coefficients.
- verbose (bool, optional) – whether or not to print verbose output.
-
static
add_args
(parser)¶ Add arguments to the provided command-line parser.
Parameters: parser (argparse.ArgumentParser) – an argument parser
-
add_continuum_constraint
(yvalue, wavemin, wavemax, weight)¶ Adds a constraint equation on the geometric mean of the continuum model in between the specified rest frame wavelengths.
Parameters:
-
add_observation
(target, flux, wave, ivar, unweighted=True)¶ Adds an observation to be fit. Returns the number of pixels added. The provided target argument must have an attribute named ‘z’ with the target’s redshift.
Note
Weighted fit not yet implemented.
Parameters: - target (
qusp.target.Target
) – a Target object - flux (numpy.array) – flux array
- wave (numpy.array) – wavelength array
- ivar (numpy.array) – ivar array
- unweighted (bool, optional) – ignore pixel variances. Defaults to True.
Returns: number of pixels added to model from this observation
Return type: npixels (int)
- target (
-
add_tilt_constraint
(weight)¶ Adds a constraint equation on the mean of the non-fixed spectral tilt params.
Parameters: weight (float) – weight to apply to constraint equation.
-
add_transmission_constraint
(yvalue, wavemin, wavemax, weight)¶ Adds a constraint equation for each of the transmission model params between the specified observed frame wavelengths.
Parameters:
-
finalize
()¶ Does final assembly of the sparse matrix representing the model.
-
static
from_args
(args)¶ Returns a dictionary of constructor parameter values based on the parsed args provided.
Parameters: args (argparse.Namespace) – argparse argument namespace Returns: a dictionary of ContinuumModel
constructor parameter values
-
get_chisq
(soln)¶ Calculates the chi-squared between the specified solution and the model y values.
Parameters: soln (numpy.array) – model parameter solution array Returns: value Return type: chisq (float)
-
get_model
()¶ Returns the assembled model matrix and corresponding y values
Returns: - A tuple of
(model, yvalues)
, where model is a scipy.sparse.csc_matrix
and yvalues is anumpy.array
.
- A tuple of
-
get_obs_chisq
(soln, obs_index)¶ Returns the chi-squared value of the specified observation index, obs_index, using the specified soln.
Parameters: - soln (numpy.array) – model parameter solution array
- obs_index (int) – observation index
Returns: value
Return type: chisq (float)
-
get_results
(soln)¶ Converts the provided solution to model params. Transforms log params to linear and inserts fixed model params.
Returns: a dictionary of model params Return type: results (dict)
-
save
(filename, soln, args, save_model=True, save_chisq=True)¶ Saves soln to the specified filename as an hdf5 file. Parsed results and fit meta data are also saved. Use the saveModel arg to indicate whether or not to save the raw data of the sparse matrix model.
Parameters: - filename (str) – filename of the hdf5 output to create
- soln (numpy.array) – model parameter solution array
- args (argparse.Namespace) – argparse argument namespace
- save_model (bool, optional) – whether or not to save the model matrix and y values. Defaults to True.
- save_chisq (bool, optional) – whether or not to save per observation chisq values. Defaults to True.
Returns: the output hdf5 file created
Return type: outfile (h5py.File)