Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/besta/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@

from besta.postprocess import (
enclosed_fraction_map,
pit_from_discrete_posterior,
pdf_stats,
photoz_metrics,
weighted_quantiles,
)

from besta.utils import available_memory_bytes
from besta.logging import get_logger

os.environ.setdefault("OMP_NUM_THREADS", "1")
Expand Down
18 changes: 13 additions & 5 deletions src/besta/pipeline_modules/base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ def prepare_observed_spectra(
if not (instrumental_lsf == 0).all():
self.config["lsf"] = instrumental_lsf

if options.get_bool("use_features", default=True):
self.get_feature_weights(options)
self.config["weights"] *= self.config["feature_weights"]
_log("Configuration done.")

def prepare_galaxy(self, options):
Expand Down Expand Up @@ -811,6 +814,7 @@ def prepare_losvd_kernel(self, options):
_log("Configuration done")

def get_feature_weights(self, options):
"""TODO"""
logger.info("Computing feature weights from input spectra")
# Estimate the continuum
continuum, continuum_err = spectrum.estimate_continuum(
Expand All @@ -824,12 +828,10 @@ def get_feature_weights(self, options):
self.config["continuum"] = continuum
self.config["continuum_err"] = continuum_err
# Favour features over/under continuum
w = (np.abs(self.config["flux"] - continuum) / continuum_err)**2
weight_powlaw = options.get_double("feature_weight_powlaw", 2.0)
w = (np.abs(self.config["flux"] - continuum) / continuum_err)**weight_powlaw
w = np.where(np.isfinite(w), w, 0.0)
w_sum = np.nansum(w)
if w_sum <= 0:
raise ValueError("Feature-based weights sum to zero; please check the input data or disable feature-based weighting.")
w /= w_sum
w /= w.max()
self.config["feature_weights"] = w

def measure_emission_lines(self, solution: DataBlock, **kwargs):
Expand Down Expand Up @@ -1054,6 +1056,12 @@ def plot_solution(self, solution: DataBlock, figname=None, plot_lines=True):
ax.set_yscale("symlog", linthresh=1.0)
ax.set_xlabel("Wavelength (AA)")

twax = ax.twinx()
twax.fill_between(
np.array(self.config["wavelength"]), 0.0, weights,
color="lime", alpha=0.2, label="Weights")
twax.set_ylabel("Weight")

ax = axs[1, 1]
ax.hist(
chi2,
Expand Down
Loading