bayspec.model package¶
Subpackages¶
- bayspec.model.astro package
- bayspec.model.local package
- Submodules
- bayspec.model.local.additive module
- bayspec.model.local.mathematic module
- Module contents
- bayspec.model.user package
- bayspec.model.xspec package
Submodules¶
bayspec.model.model module¶
Spectral model base classes and the composition algebra.
Model defines the functional contract (func(E, T, O)), parameter
and config dictionaries, convolution with detector responses, and
posterior-aware evaluators. Additive/Multiplicative/
Mathematic are thin base classes that fix the type tag, and
CompositeModel implements the arithmetic (+, -, *, /) plus the
convolution call operator (conv(add) etc.) used to build
multi-component expressions.
- class bayspec.model.model.Model[source]¶
Bases:
objectBase class for a spectral model component.
Subclasses override
func()with the model’s analytical form and populateconfig(Cfgentries – frozen values like redshift) andparams(Parentries – fittable quantities). Thetypetag –'add','mul','conv'or'math'– drives which derived spectra (phtspec,flxspec,ergspec,nouspec) are available and how composition is type-checked.- Variables:
expr – Short expression used in tables and composite names.
type – One of
'add','mul','conv','math'.comment – Free-form description.
config –
OrderedDictof configurationCfgentries.params –
OrderedDictof fitParentries.
- func(E, T=None, O=None)[source]¶
Evaluate the model at energies
Eand optional timeT.Additive models return a photon flux density in photons/cm²/s/keV; multiplicative and mathematical models return a dimensionless factor.
Ois a nested model argument used by convolution operators.- Parameters:
E – Scalar or array of energies in keV.
T – Optional time or time array.
O – Optional nested model passed down by a convolution.
- Returns:
The model value at the given sampling; subclass-specific.
- property mdicts¶
Mapping from
exprto component model; overridden by composites.
- property fdicts¶
Mapping from
exprto each component’sfunccallable.
- property cdicts¶
Mapping from
exprto each component’sconfigdict.
- property pdicts¶
Mapping from
exprto each component’sparamsdict.
- property cfg¶
Flat
SuperDictof every config parameter across components.
- property par¶
Flat
SuperDictof every fit parameter across components.
- property pvalues¶
Tuple of current parameter values, preserving
parorder.
- property all_config¶
List of per-config rows with component, label, and value.
- property all_params¶
List of per-parameter rows with value, prior, posterior, and frozen flag.
- property cfg_info¶
Tabular
Infoview of every configuration parameter.
- property par_info¶
Tabular
Infoview of parameters with frozen ones tagged.
- save(savepath)[source]¶
Dump the config and parameter tables under
savepath.- Parameters:
savepath – Directory path. Created if missing.
- property fit_to¶
Return the
Datathis model is bound to, or raise if unset.- Raises:
AttributeError – If no data has been assigned.
- integ(egrid, tgrid, ngrid)[source]¶
Trapezoidal-integrate the model over each
ngrid-point bin.- Parameters:
egrid – Flattened energy grid, shaped
(nbin * ngrid,).tgrid – Matching flattened time grid.
ngrid – Sub-grid size per bin used to reshape
egrid.
- Returns:
Integrated photon flux per bin.
- Raises:
TypeError – If the model type is not
'add'.
- convolve_response(response, time=None)[source]¶
Convolve the model with a single
Responseand return count-rate/spec.- Parameters:
response – A
Response.time – Optional time broadcast across photon bins.
- Returns:
A
(ctsrate, ctsspec)tuple.
- convolve_dataunit(dataunit)[source]¶
Convolve the model with a single
DataUnit.- Parameters:
dataunit – A
DataUnit.- Returns:
A
(ctsrate, ctsspec)tuple.
- convolve_data(data)[source]¶
Convolve the model with every unit of a
Datacontainer.- Parameters:
data – A
Data.- Returns:
A
(ctsrate_list, ctsspec_list)tuple, one entry per unit.
- property conv_ctsrate¶
Convolved count rate per unit against the bound
fit_todata.
- property conv_ctsrate_f64¶
Same as
conv_ctsratebut cast tofloat64for statistics.
- property conv_re_ctsrate¶
Convolved count rate using the re-binned detector response.
- property conv_ctsspec¶
conv_ctsratedivided by bin width.- Type:
Convolved count density
- property conv_re_ctsspec¶
Convolved count density on the re-binned response.
- property phtspec_at_rsp¶
Photon spectrum sampled at the response channel midpoints.
Sibling properties
re_phtspec_at_rsp,flxspec_at_rsp,re_flxspec_at_rsp,ergspec_at_rsp,re_ergspec_at_rspfollow the same pattern, using either the full or re-binned channel grid.
- property re_phtspec_at_rsp¶
- property flxspec_at_rsp¶
- property re_flxspec_at_rsp¶
- property ergspec_at_rsp¶
- property re_ergspec_at_rsp¶
- property cts_to_pht¶
Per-bin conversion factor from convolved counts to photon density.
re_cts_to_pht,cts_to_flx,re_cts_to_flx,cts_to_ergandre_cts_to_ergfollow the same pattern for the photon/flux/ energy spectra on the full or re-binned grids.
- property re_cts_to_pht¶
- property cts_to_flx¶
- property re_cts_to_flx¶
- property cts_to_erg¶
- property re_cts_to_erg¶
- property rate_to_flux¶
Per-unit ratio of integrated energy flux to observed net count rate.
- property conv_rate_to_flux¶
Like
rate_to_fluxbut using the convolved-model count rate.
- rate_to_fluxdensity(E=1, T=None, unit='Fv')[source]¶
Per-unit conversion from net count rate to flux density at
(E, T).- Parameters:
E – Energy at which the flux density is evaluated.
T – Optional time.
unit –
'NE'(photon flux density),'Fv'(energy flux density), or'Jy'.
- Returns:
A list of per-unit conversion factors.
- Raises:
ValueError – If
unitis not recognized.
- conv_rate_to_fluxdensity(E=1, T=None, unit='Fv')[source]¶
Like
rate_to_fluxdensity()but using convolved count rates.
- phtspec(E, T=None)[source]¶
Photon flux density \(N(E)\) in photons/cm²/s/keV.
- Raises:
TypeError – If the model type is not
'add'.
- nouspec(E, T=None)[source]¶
Dimensionless factor applied by multiplicative/mathematical models.
- Raises:
TypeError – If the model type is not
'mul'or'math'.
- flxspec(E, T=None)[source]¶
Energy flux density \(F_\nu = E \, N(E)\) in erg/cm²/s/keV.
- Raises:
TypeError – If the model type is not
'add'.
- ergspec(E, T=None)[source]¶
Energy spectrum \(\nu F_\nu = E^2 \, N(E)\) in erg/cm²/s.
- Raises:
TypeError – If the model type is not
'add'.
- phtflux(emin, emax, ngrid, time=None)[source]¶
Integrated photon flux over
[emin, emax]in photons/cm²/s.- Parameters:
emin – Lower energy bound in keV.
emax – Upper energy bound in keV.
ngrid – Number of log-spaced grid points.
time – Optional time broadcast across the grid.
- Raises:
TypeError – If the model type is not
'add'.
- ergflux(emin, emax, ngrid, time=None)[source]¶
Integrated energy flux over
[emin, emax]in erg/cm²/s.- Raises:
TypeError – If the model type is not
'add'.
- property par_mean¶
Per-parameter posterior mean (or frozen value when applicable).
- property par_median¶
Per-parameter posterior median (or frozen value).
- property par_best¶
Per-parameter posterior best-fit sample (or frozen value).
- property par_best_ci¶
Per-parameter best-fit confidence bounds (or frozen value).
- property par_truth¶
Per-parameter truth value (or frozen value); may contain
None.
- mean_phtspec(E, T=None)[source]¶
Photon spectrum evaluated at the posterior mean parameter vector.
The family
{mean,median,best,best_ci,truth}_{pht,nou,flx,erg}spec,_{pht,erg}flux, and_{pht,erg}flux_ratioall follow the same pattern: setparfrom the named posterior summary, then evaluate the spectrum, integrated flux, or flux ratio.truth_*variants raiseValueErrorwhen any parameter lacks a truth value.
- property posterior_nsample¶
Number of posterior draws; equals
1when every parameter is frozen.
- property posterior_sample¶
(nsample, npar)matrix of posterior draws.Frozen parameters are filled with their fixed value so the matrix is rectangular.
- sample_statistic(sample)[source]¶
Summarize a draw matrix with mean, median, and 1/2/3-sigma intervals.
- Parameters:
sample –
(nsample, ...)array of draws.- Returns:
Dict with keys
mean,median,Isigma,IIsigma,IIIsigma.
- property par_sample¶
Summary statistics of the posterior parameter matrix.
- class bayspec.model.model.Additive[source]¶
Bases:
ModelBase for additive photon-flux components;
typeis locked to'add'.- property type¶
Model type tag, always
'add'.
- class bayspec.model.model.Multiplicative[source]¶
Bases:
ModelBase for dimensionless multiplicative components;
typeis'mul'.- property type¶
Model type tag, always
'mul'.
- class bayspec.model.model.Mathematic[source]¶
Bases:
ModelBase for dimensionless mathematical components;
typeis'math'.- property type¶
Model type tag, always
'math'.
- class bayspec.model.model.FrozenConst(value)[source]¶
Bases:
MathematicFrozen scalar used to wrap numeric literals in composite expressions.
- class bayspec.model.model.CompositeModel(m1, op, m2)[source]¶
Bases:
ModelBinary combination of two models under
+/-/*///().The composite’s type is inferred from
type_operationviatdict; invalid combinations raiseValueError. Duplicate component names are made unique with a numeric suffix.- property expr¶
Parenthesized expression assembled from the two operands.
- property type¶
Derived composite type looked up in
tdict.- Raises:
ValueError – If the operand-type pair is not an allowed combination.
AssertionError – If either operand has an unknown type tag.
- property comment¶
Concatenated per-component comments, one line per component.
- func(E, T=None, O=None)[source]¶
Evaluate the composite by dispatching on
op.For
'()',m1is called withO=m2so convolution-style operators receive the nested model.- Raises:
ValueError – If
opis not recognized.
- property mdicts¶
Merged component mapping from both operands.
- type_operation()[source]¶
Return the resulting type for the current
(m1, op, m2)triple.- Raises:
ValueError – If the operand-type pair is not a legal combination.
AssertionError – If either operand has an unknown type tag.
- property tdict¶
Lookup table mapping
'<t1><op><t2>'strings to the composite type.A value of
Falsemarks an illegal combination.
Module contents¶
Model subpackages: local components, astromodels bridges, and xspec wrappers.
Top-level re-exports are kept disabled so that importing bayspec.model
does not pull in xspec/astromodels at import time. Import the relevant
submodule explicitly when needed.