ObsData#

class jetset.data_loader.ObsData(cosmo=None, data_table=None, dupl_filter=False, data_set_filter=None, UL_filtering=False, UL_value=None, UL_CL=0.95, **keywords)[source]#

Bases: object

Legacy-compatible observational SED container for fitting workflows.

Notes

Wraps an input table, applies optional filtering (datasets, duplicates, upper limits), computes derived log-space columns, and exposes arrays used by minimization and plotting utilities.

Attributes Summary

gammapy_table

Return data as a Gammapy-compatible flux-points table.

metadata

Return metadata dictionary excluding internal bookkeeping keys.

table

Return the working observational table.

Methods Summary

add_systematics(syst[, nu_range, dataset])

Add fractional systematic uncertainty in quadrature.

filter_UL([val])

Remove rows considered upper limits by error threshold.

filter_data_set(filters[, exclude, silent])

Filter rows by dataset label.

filter_freq([nu_min, nu_max, exclude])

Filter rows by frequency interval.

filter_time([T_min, T_max, exclude])

Filter rows by time interval.

find_time_span([dataset, silent, get_values])

Compute time-span summary for selected rows.

get_data_points([log_log, skip_UL, frame, ...])

Return data arrays ready for plotting or fitting.

get_data_sets()

Return unique dataset labels present in the table.

get_gammapy_table()

Build a Gammapy flux-points table from the current data.

get_time_span([dataset])

Return time-span summary for one dataset or all data.

group_data([N_bin, bin_width, ...])

Rebin data in logarithmic-frequency bins.

lin_to_log([val, err])

Wrapper to convert linear values/errors to log10 space.

load(file_name)

Load a serialized ObsData instance from disk.

log_to_lin([log_val, log_err])

Wrapper to convert log10 values/errors back to linear space.

plot_sed([plot_obj, frame, color, fmt, ms, ...])

Plot observational SED points.

plot_time_spans([save_as])

Plot time coverage per dataset on a single figure.

remove_dupl_entries(data)

remove duplicate entries

reset_data()

Reset working data to the original loaded dataset.

save(file_name)

Serialize this ObsData instance to disk.

set_UL([val])

Flag upper limits from an error-threshold criterion.

set_error(error_value[, nu_range, dataset, ...])

Set relative statistical errors on selected rows.

set_fake_error(val)

Set fallback relative errors used in fits and plotting.

set_zero_error([val, replace_zero])

Mark and optionally replace non-positive uncertainty values.

show_data_sets()

Print currently available dataset labels.

show_time_span([dataset])

Print time-span summary for one dataset or all data.

Attributes Documentation

gammapy_table#

Return data as a Gammapy-compatible flux-points table.

metadata#

Return metadata dictionary excluding internal bookkeeping keys.

Parameters:

skip (list, optional) – Keys to exclude from the returned dictionary.

Returns:

Metadata key/value pairs currently set on the object.

Return type:

dict

table#

Return the working observational table.

Methods Documentation

add_systematics(syst, nu_range=None, dataset=None)[source]#

Add fractional systematic uncertainty in quadrature.

Parameters:
  • syst (float) – Relative systematic term (for example 0.1 for 10%).

  • nu_range (tuple, optional) – Frequency interval (nu_min, nu_max) where the systematic is applied.

  • dataset (str, optional) – Dataset label where the systematic is applied.

filter_UL(val=None)[source]#

Remove rows considered upper limits by error threshold.

Parameters:

val (float, optional) – Error threshold; defaults to self.UL_value.

filter_data_set(filters, exclude=False, silent=False)[source]#

Filter rows by dataset label.

Parameters:
  • filters (str) – Comma-separated dataset names.

  • exclude (bool, optional) – If False keep only listed datasets; if True remove them.

  • silent (bool, optional) – Suppress informational prints when True.

filter_freq(nu_min=None, nu_max=None, exclude=False)[source]#

Filter rows by frequency interval.

Parameters:
  • nu_min (float, optional) – Minimum frequency in Hz to include.

  • nu_max (float, optional) – Maximum frequency in Hz to include.

  • exclude (bool, optional) – If True, remove selected rows instead of keeping them.

filter_time(T_min=None, T_max=None, exclude=False)[source]#

Filter rows by time interval.

Parameters:
  • T_min (float, optional) – Minimum T_start (MJD) to include.

  • T_max (float, optional) – Maximum T_stop (MJD) to include.

  • exclude (bool, optional) – If True, remove selected rows instead of keeping them.

find_time_span(dataset=None, silent=True, get_values=False)[source]#

Compute time-span summary for selected rows.

Parameters:
  • dataset (str, optional) – Dataset label. If omitted, uses all rows.

  • silent (bool, optional) – If False, print the summary.

  • get_values (bool, optional) – If True, return summary values.

Returns:

Returns (T_start, T_stop, DT, n_points) when get_values=True, otherwise None.

Return type:

tuple or None

get_data_points(log_log=False, skip_UL=False, frame='obs', density=False)[source]#

Return data arrays ready for plotting or fitting.

Parameters:
  • log_log (bool, optional) – If True, return log10-transformed arrays.

  • skip_UL (bool, optional) – If True, exclude rows flagged as upper limits.

  • frame ({"obs", "src"}, optional) – Output frame of returned arrays.

  • density (bool, optional) – If True, return density-style values (divide by frequency).

Returns:

(x, y, dx, dy) arrays in the requested frame/scale.

Return type:

tuple

get_data_sets()[source]#

Return unique dataset labels present in the table.

Returns:

Dataset labels.

Return type:

list

get_gammapy_table()[source]#

Build a Gammapy flux-points table from the current data.

Returns:

Table with e_ref, e2dnde and e2dnde_err columns plus metadata.

Return type:

astropy.table.Table

get_time_span(dataset=None)[source]#

Return time-span summary for one dataset or all data.

Parameters:

dataset (str, optional) – Dataset label. If omitted, uses all rows.

Returns:

(T_start, T_stop, DT, n_points) in MJD units.

Return type:

tuple

group_data(N_bin=None, bin_width=None, correct_dispersions=True, nu_min=None, nu_max=None)[source]#

Rebin data in logarithmic-frequency bins.

Parameters:
  • N_bin (int, optional) – Number of bins. Mutually exclusive with bin_width.

  • bin_width (float, optional) – Log10-bin width. Mutually exclusive with N_bin.

  • correct_dispersions (bool, optional) – Apply weighted-mean dispersion correction inside each bin.

  • nu_min (float, optional) – Lower bound of rebinning interval in Hz.

  • nu_max (float, optional) – Upper bound of rebinning interval in Hz.

lin_to_log(val=None, err=None)[source]#

Wrapper to convert linear values/errors to log10 space.

Parameters:
  • val (array-like, optional) – Linear values.

  • err (array-like, optional) – Linear errors associated with val.

Returns:

Converted values and, when provided, propagated log errors.

Return type:

array-like or list

static load(file_name)[source]#

Load a serialized ObsData instance from disk.

Parameters:

file_name (str) – Pickle file path.

Returns:

Loaded object with data sorted by frequency.

Return type:

ObsData

log_to_lin(log_val=None, log_err=None)[source]#

Wrapper to convert log10 values/errors back to linear space.

Parameters:
  • log_val (array-like, optional) – Log10 values.

  • log_err (array-like, optional) – Errors in log10 space.

Returns:

Converted linear values and, when provided, propagated errors.

Return type:

array-like or list

plot_sed(plot_obj=None, frame='obs', color=None, fmt='o', ms=4, mew=0.5, figsize=None, show_dataset=False, density=False)[source]#

Plot observational SED points.

Parameters:
  • plot_obj (jetset.plot_sedfit.PlotSED, optional) – Existing plot object; if omitted a new one is created.

  • frame ({"obs", "src"}, optional) – Frame used for plotting.

  • color (str, optional) – Matplotlib color.

  • fmt (str, optional) – Marker format.

  • ms (float, optional) – Marker size.

  • mew (float, optional) – Marker edge width.

  • figsize (tuple, optional) – Figure size used only when creating a new plot.

  • show_dataset (bool, optional) – If True, plot each dataset label as a separate series.

  • density (bool, optional) – If True, plot density representation.

Returns:

Plot object containing added data traces.

Return type:

jetset.plot_sedfit.PlotSED

plot_time_spans(save_as=None)[source]#

Plot time coverage per dataset on a single figure.

Parameters:

save_as (str, optional) – Optional output path where the figure is saved.

Returns:

Generated figure.

Return type:

matplotlib.figure.Figure

remove_dupl_entries(data)[source]#

remove duplicate entries

Parameters:

data – (array) 2-dim array storing the the table of the data.

Returns msk:

a boolean array to mask the duplicated entries

Note

One entry is flagged as duplicated as each comlum in a row of the data table is equal to the corresponding elements of another row

reset_data()[source]#

Reset working data to the original loaded dataset.

Notes

Rebuilds internal tables from the unfiltered source copy.

save(file_name)[source]#

Serialize this ObsData instance to disk.

Parameters:

file_name (str) – Pickle output path.

set_UL(val=None)[source]#

Flag upper limits from an error-threshold criterion.

Parameters:

val (float, optional) – Threshold applied to dnuFnu (or log equivalent) to define UL points. If omitted, uses self.UL_value.

set_error(error_value, nu_range=None, dataset=None, data_msk=None)[source]#

Set relative statistical errors on selected rows.

Parameters:
  • error_value (float) – Relative error factor; applied as error_value * nuFnu.

  • nu_range (tuple, optional) – Frequency interval (nu_min, nu_max) to target.

  • dataset (str, optional) – Dataset label to target.

  • data_msk (array-like of bool, optional) – Additional boolean mask combined with internal selection masks.

set_fake_error(val)[source]#

Set fallback relative errors used in fits and plotting.

Parameters:

val (float) – Relative error assigned to the dnuFnu_fake columns.

set_zero_error(val=0.2, replace_zero=True)[source]#

Mark and optionally replace non-positive uncertainty values.

Parameters:
  • val (float, optional) – Relative replacement error used when replace_zero=True.

  • replace_zero (bool, optional) – If True, replace zero/negative errors with a fallback value.

show_data_sets()[source]#

Print currently available dataset labels.

Notes

Labels are read from the dataset column of the working table.

show_time_span(dataset=None)[source]#

Print time-span summary for one dataset or all data.