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.Additive[source]¶
Bases:
ModelBase for additive photon-flux components;
typeis locked to'add'.- property type¶
Model type tag, always
'add'.
- 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 comment¶
Concatenated per-component comments, one line per component.
- property expr¶
Parenthesized expression assembled from the two operands.
- 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.
- property tdict¶
Lookup table mapping
'<t1><op><t2>'strings to the composite type.A value of
Falsemarks an illegal combination.
- class bayspec.model.model.FrozenConst(value)[source]¶
Bases:
MathematicFrozen scalar used to wrap numeric literals in composite expressions.
- 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.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.- 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.
- 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 cdicts¶
Mapping from
exprto each component’sconfigdict.
- property cfg¶
Flat
SuperDictof every config parameter across components.
- property cfg_info¶
Tabular
Infoview of every configuration parameter.
- 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_ctsspec¶
conv_ctsratedivided by bin width.- Type:
Convolved count density
- property conv_rate_to_flux¶
Like
rate_to_fluxbut using the convolved-model count rate.
- conv_rate_to_fluxdensity(E=1, T=None, unit='Fv')[source]¶
Like
rate_to_fluxdensity()but using convolved count rates.
- property conv_re_ctsrate¶
Convolved count rate using the re-binned detector response.
- property conv_re_ctsspec¶
Convolved count density on the re-binned response.
- 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.
- convolve_dataunit(dataunit)[source]¶
Convolve the model with a single
DataUnit.- Parameters:
dataunit – A
DataUnit.- Returns:
A
(ctsrate, ctsspec)tuple.
- 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.
- property cts_to_erg¶
- property cts_to_flx¶
- 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.
- 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'.
- 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'.
- property ergspec_at_rsp¶
- property fdicts¶
Mapping from
exprto each component’sfunccallable.
- property fit_to¶
Return the
Datathis model is bound to, or raise if unset.- Raises:
AttributeError – If no data has been assigned.
- 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'.
- property flxspec_at_rsp¶
- 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.
- 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'.
- property mdicts¶
Mapping from
exprto component model; overridden by composites.
- 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.
- nouspec(E, T=None)[source]¶
Dimensionless factor applied by multiplicative/mathematical models.
- Raises:
TypeError – If the model type is not
'mul'or'math'.
- property par¶
Flat
SuperDictof every fit parameter across components.
- 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_info¶
Tabular
Infoview of parameters with frozen ones tagged.
- property par_mean¶
Per-parameter posterior mean (or frozen value when applicable).
- property par_median¶
Per-parameter posterior median (or frozen value).
- property par_sample¶
Summary statistics of the posterior parameter matrix.
- property par_truth¶
Per-parameter truth value (or frozen value); may contain
None.
- property pdicts¶
Mapping from
exprto each component’sparamsdict.
- 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'.
- phtspec(E, T=None)[source]¶
Photon flux density \(N(E)\) in photons/cm²/s/keV.
- Raises:
TypeError – If the model type is not
'add'.
- 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.
- phtspec_sample(E, T=None)[source]¶
Return posterior summaries of the photon spectrum at
(E, T).Sibling methods
nouspec_sample,flxspec_sample,ergspec_sample,phtflux_sample,ergflux_sample,phtflux_ratio_sample, andergflux_ratio_samplefollow the same pattern on their respective quantities.
- 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.
- property pvalues¶
Tuple of current parameter values, preserving
parorder.
- property rate_to_flux¶
Per-unit ratio of integrated energy flux to observed net 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.
- property re_cts_to_erg¶
- property re_cts_to_flx¶
- property re_cts_to_pht¶
- property re_ergspec_at_rsp¶
- property re_flxspec_at_rsp¶
- property re_phtspec_at_rsp¶
- 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.
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.