Model#
- class jetset.base_model.Model(name='no_name', nu_size=200, model_type='base_model', scale='lin-lin', cosmo=None, nu_min=None, nu_max=None)[source]#
Bases:
objectBase class for analytical and numerical SED models.
Attributes Summary
Return the package version used to create this model.
Methods Summary
add_user_par(name, val[, units, val_min, ...])Add a user-defined parameter to the model.
build_table([restframe])Build SED table for the current model state.
clone()Return a deep clone of the model via in-memory serialization.
dep_func_get_default_args(par_func)Validate dependency-function arguments against model parameters.
eval([fill_SED, nu, get_model, loglog, label])Evaluate model fluxes.
get_par_by_name(par_name)Return parameter by name.
get_par_by_type(par_type)Return first parameter matching a parameter type.
get_residuals(data[, log_log, filter_UL])Compute residuals between observed data and model prediction.
lin_func(lin_nu)Return model values in linear space.
load_model(file_name_or_obj[, from_string])Load a serialized model.
log_func(log_nu)Return model values in log10 space.
make_dependent_par(par, depends_on, par_expr)Make dependent par.
plot_model([plot_obj, clean, sed_data, ...])Plot model SED and optional spectral components.
save_model(file_name)Serialize the model to disk.
sed_table([restframe])Return SED table, evaluating the model if needed.
set_fit_range([down_tol, up_tol])Set fit ranges for numeric parameters.
set_nu_grid([nu_min, nu_max, nu_size])Set model frequency-grid settings.
set_par(par_name, val)Set a parameter value by name.
Display best-fit parameter values.
Print model summary and parameters.
show_pars([sort_key])Display model parameters.
Attributes Documentation
- version#
Return the package version used to create this model.
- Returns:
Version string.
- Return type:
str
Methods Documentation
- add_user_par(name, val, units='', val_min=None, val_max=None)[source]#
Add a user-defined parameter to the model.
- Parameters:
name (str) – Parameter name.
val (float) – Initial value.
units (str, optional) – Parameter units label.
val_min (float, optional) – Lower physical bound.
val_max (float, optional) – Upper physical bound.
- build_table(restframe='obs')[source]#
Build SED table for the current model state.
- Parameters:
restframe ({'obs', 'src'}, optional) – Frame used to build frequency/flux columns.
- clone()[source]#
Return a deep clone of the model via in-memory serialization.
- Returns:
Cloned model instance.
- Return type:
- dep_func_get_default_args(par_func)[source]#
Validate dependency-function arguments against model parameters.
- Parameters:
par_func (callable) – Function used as dependency expression.
- Returns:
Ordered list of parameter names accepted by
par_func.- Return type:
list of str
- Raises:
RuntimeError – If
par_funcuses argument names not present in the model.
- eval(fill_SED=True, nu=None, get_model=False, loglog=False, label=None, **kwargs)[source]#
Evaluate model fluxes.
- Parameters:
fill_SED (bool, optional) – If
True, update the model SED object after evaluation.nu (array-like or float, optional) – Frequency grid in Hz (or log10(Hz) if
loglogisTrue). If omitted, the internalnu_min/nu_max/nu_sizegrid is used.get_model (bool, optional) – If
True, return evaluated values.loglog (bool, optional) – If
True, treat input/output frequency and model values in log10 space.label (str, optional) – Reserved for subclasses/plotting integrations.
**kwargs – Extra keyword arguments accepted for subclass compatibility.
- Returns:
Evaluated model array when
get_modelisTrue, otherwiseNone.- Return type:
ndarray or None
- get_par_by_name(par_name)[source]#
Return parameter by name.
- Parameters:
par_name (str) – Parameter name.
- Returns:
Matching parameter, if found.
- Return type:
ModelParameter or None
- get_par_by_type(par_type)[source]#
Return first parameter matching a parameter type.
- Parameters:
par_type (str) – Parameter type label.
- Returns:
Matching parameter, if found.
- Return type:
ModelParameter or None
- get_residuals(data, log_log=False, filter_UL=True)[source]#
Compute residuals between observed data and model prediction.
- Parameters:
data (ObsData or table-like) – Input data table containing
nu_data,nuFnu_data,dnuFnu_dataandULcolumns.log_log (bool, optional) – If
True, return frequency axis in log10(Hz).filter_UL (bool, optional) – If
True, exclude upper-limit points.
- Returns:
(nu_axis, residuals).- Return type:
tuple of ndarray
- lin_func(lin_nu)[source]#
Return model values in linear space.
- Parameters:
lin_nu (ndarray) – Frequency array in Hz.
- Returns:
Model values in linear
nuFnuunits.- Return type:
ndarray
- classmethod load_model(file_name_or_obj, from_string=False)[source]#
Load a serialized model.
- Parameters:
file_name_or_obj (str or bytes or file-like) – Serialized model source accepted by the pickle loader.
from_string (bool, optional) – If
True, interpretfile_name_or_objas in-memory content.
- Returns:
Reconstructed and evaluated model instance.
- Return type:
- Raises:
RuntimeError – If deserialization fails or object type is not valid.
- log_func(log_nu)[source]#
Return model values in log10 space.
- Parameters:
log_nu (ndarray) – Frequency array in log10(Hz).
- Returns:
Model values in log10 space.
- Return type:
ndarray
- make_dependent_par(par, depends_on, par_expr, verbose=True, set_par_expr_source_code=True, master_pars=None)[source]#
Make dependent par.
- Parameters:
par (object) – Parameter object or parameter name.
depends_on (object) – Names of master parameters used by the dependency.
par_expr (object) – Expression defining a dependent parameter.
verbose (bool, optional) – If
True, print additional information.set_par_expr_source_code (bool, optional) – If
True, store source code for the dependency expression.master_pars (object, optional) – Master-parameter objects used by the dependency.
- plot_model(plot_obj=None, clean=False, sed_data=None, frame='obs', skip_components=False, label=None, line_style='-', density=False)[source]#
Plot model SED and optional spectral components.
- Parameters:
plot_obj (PlotSED, optional) – Existing plotting object. If omitted, a new one is created.
clean (bool, optional) – If
True, clear existing model lines fromplot_obj.sed_data (ObsData, optional) – Optional observed data used by the plotting helper.
frame ({'obs', 'src'}, optional) – Output frame for plotting.
skip_components (bool, optional) – If
True, do not plot individual spectral components.label (str, optional) – Label for the model curve.
line_style (str, optional) – Matplotlib line style.
density (bool, optional) – If
True, use density representation in plotting helper.
- Returns:
Plot object with model curves added.
- Return type:
- save_model(file_name)[source]#
Serialize the model to disk.
- Parameters:
file_name (str) – Output pickle file path.
- sed_table(restframe='obs')[source]#
Return SED table, evaluating the model if needed.
- Parameters:
restframe ({'obs', 'src'}, optional) – Frame used to build frequency/flux columns.
- Returns:
SED table for the current model state.
- Return type:
astropy.table.Table or None
- set_fit_range(down_tol=0.1, up_tol=100)[source]#
Set fit ranges for numeric parameters.
- Parameters:
down_tol (float, optional) – Multiplicative factor for lower fit bound.
up_tol (float, optional) – Relative factor for upper fit bound.
- set_nu_grid(nu_min=None, nu_max=None, nu_size=None)[source]#
Set model frequency-grid settings.
- Parameters:
nu_min (float, optional) – Minimum frequency in Hz.
nu_max (float, optional) – Maximum frequency in Hz.
nu_size (int, optional) – Number of samples in the grid.