Skip to content

Commit

Permalink
Merge pull request #913 from igmhub/optional-stack-delta-correction
Browse files Browse the repository at this point in the history
Optional stack delta correction
  • Loading branch information
iprafols committed Jul 22, 2022
2 parents 2ebaeda + 3471aa6 commit 355245e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
22 changes: 19 additions & 3 deletions py/picca/delta_extraction/expected_fluxes/dr16_expected_flux.py
Expand Up @@ -16,7 +16,7 @@
accepted_options = [
"iter out prefix", "limit eta", "limit var lss", "min num qso in fit",
"num bins variance", "num iterations", "num processors", "order", "out dir",
"use constant weight", "use ivar as weight"
"use constant weight", "use ivar as weight", "force stack delta to zero"
]

defaults = {
Expand All @@ -29,6 +29,7 @@
"order": 1,
"use constant weight": False,
"use ivar as weight": False,
"force stack delta to zero": True
}


Expand Down Expand Up @@ -133,6 +134,9 @@ class Dr16ExpectedFlux(ExpectedFlux):
use_ivar_as_weight: boolean
If "True", use ivar as weights (implemented as eta = 1, sigma_lss = fudge = 0).
force_stack_delta_to_zero: boolean
If "True", continuum is corrected by stack_delta.
"""

def __init__(self, config):
Expand All @@ -156,6 +160,7 @@ def __init__(self, config):
self.order = None
self.use_constant_weight = None
self.use_ivar_as_weight = None
self.force_stack_delta_to_zero = None
self.__parse_config(config)

# initialize variables
Expand Down Expand Up @@ -376,6 +381,12 @@ def __parse_config(self, config):
"Missing argument 'use ivar as weight' required by Dr16ExpectedFlux"
)

self.force_stack_delta_to_zero = config.getboolean("force stack delta to zero")
if self.force_stack_delta_to_zero is None:
raise ExpectedFluxError(
"Missing argument 'force stack delta to zero' required by Dr16ExpectedFlux"
)

# this should be a read-only function as it is called in a parallelized way
# TODO: consider making this not a function to minimize future bugs
def compute_continuum(self, forest):
Expand Down Expand Up @@ -955,10 +966,15 @@ def populate_los_ids(self, forests):
if forest.bad_continuum_reason is not None:
continue
# get the variance functions and statistics
stack_delta = self.get_stack_delta(forest.log_lambda)
eta = self.get_eta(forest.log_lambda)

mean_expected_flux = forest.continuum * stack_delta
# assignment operator (=) creates a reference, such that
# mean_expected_flux points to forest.continuum and
# forest.continuum gets modified within if statement
mean_expected_flux = np.copy(forest.continuum)
if self.force_stack_delta_to_zero:
stack_delta = self.get_stack_delta(forest.log_lambda)
mean_expected_flux *= stack_delta
weights = self.get_continuum_weights(forest, mean_expected_flux)
# this is needed as the weights from get_continuum_weights are
# divided by the continuum model squared, in this case mean_expected_flux
Expand Down
1 change: 1 addition & 0 deletions py/picca/tests/delta_extraction/data/.config.ini
Expand Up @@ -56,6 +56,7 @@ use ivar as weight = False
out dir = /Users/iperezra/software/picca/py/picca/tests/delta_extraction/results/config_tests/
num processors = 1
min num qso in fit = 100
force stack delta to zero = True

[correction arguments 0]
filename = /Users/iperezra/software/picca/py/picca/tests/delta_extraction/data/delta_attributes.fits.gz
Expand Down
Expand Up @@ -298,6 +298,7 @@
"- `order`: Order of the polynomial for the continuum fit. **Type: int, Required: no, Default: 1**\n",
"- `use constant weight`: If \"True\", set all the delta weights to one (implemented as eta = 0, sigma_lss = 1, fudge = 0) **Type: bool, Required: no, Default: False**\n",
"- `use ivar as weight`: If \"True\", use ivar as weights (implemented as eta = 1, sigma_lss = fudge = 0) **Type: bool, Required: no, Default: False**\n",
"- `force stack delta to zero`: If \"True\" (Default), continuum is corrected by stack_delta. **Type: bool, Required: no, Default: True**\n",
"\n",
"### TrueContinuum\n",
"- `input directory`: Directory to spectra files. **Type: str, Required: yes**\n",
Expand Down

0 comments on commit 355245e

Please sign in to comment.