Skip to content

Commit

Permalink
keep_masked_pixels is read from config
Browse files Browse the repository at this point in the history
  • Loading branch information
Naim Goksel Karacayli committed Aug 2, 2022
1 parent 4a8aa96 commit f0abe71
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 23 deletions.
3 changes: 0 additions & 3 deletions py/picca/delta_extraction/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def __init__(self, filename):
self.__format_corrections_section()
self.masks = None
self.num_masks = None
self.keep_masked_pixels = False
self.__format_masks_section()
self.data = None
self.__format_data_section()
Expand Down Expand Up @@ -504,8 +503,6 @@ def __format_masks_section(self):
raise ConfigError("In section [masks], variable 'num masks' "
"must be a non-negative integer")

self.keep_masked_pixels = section.getboolean("keep pixels", fallback=False)

# check that arguments are valid
for key in section.keys():
if key not in accepted_masks_options:
Expand Down
8 changes: 5 additions & 3 deletions py/picca/delta_extraction/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Mask:
Arguments
---------
keep_masked_pixels: bool (default: False)
Determines the method to mask pixels. If true, sets ivar to 0.
config: configparser.SectionProxy
Parsed options to initialize class
Methods
-------
Expand All @@ -37,9 +37,11 @@ class Mask:
If keep_masked_pixels=True, then points to _set_ivar_to_zero.
Otherwise, points to _remove_pixels.
"""
def __init__(self, keep_masked_pixels=False):
def __init__(self, config):
"""Initialize class instance"""
self.los_id = {}

keep_masked_pixels = config.getboolean("keep pixels", fallback=False)

if keep_masked_pixels:
self._masker = _set_ivar_to_zero
Expand Down
4 changes: 2 additions & 2 deletions py/picca/delta_extraction/masks/absorber_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AbsorberMask(Mask):
logger: logging.Logger
Logger object
"""
def __init__(self, config, keep_masked_pixels=False):
def __init__(self, config):
"""Initialize class instance.
Arguments
Expand All @@ -45,7 +45,7 @@ def __init__(self, config, keep_masked_pixels=False):
"""
self.logger = logging.getLogger(__name__)

super().__init__(keep_masked_pixels)
super().__init__(config)

# first load the absorbers catalogue
filename = config.get("filename")
Expand Down
9 changes: 3 additions & 6 deletions py/picca/delta_extraction/masks/bal_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ class BalMask(Mask):
logger: logging.Logger
Logger object
"""
def __init__(self, config, keep_masked_pixels=False):
def __init__(self, config):
"""Initializes class instance.
Arguments
---------
config: configparser.SectionProxy
Parsed options to initialize class
keep_masked_pixels: bool (default: False)
Determines the method to mask pixels. If true, sets ivar to 0.
Raise
-----
MaskError if there are missing variables
Expand All @@ -82,7 +79,7 @@ def __init__(self, config, keep_masked_pixels=False):
"""
self.logger = logging.getLogger(__name__)

super().__init__(keep_masked_pixels)
super().__init__(config)

filename = config.get("filename")
if filename is None:
Expand Down Expand Up @@ -237,4 +234,4 @@ def apply_mask(self, forest):

# do the actual masking
for param in Forest.mask_fields:
self._masker(forest, param, w)
self._masker(forest, param, w)
7 changes: 2 additions & 5 deletions py/picca/delta_extraction/masks/dla_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ class DlaMask(Mask):
mask: astropy.Table
Table containing specific intervals of wavelength to be masked for DLAs
"""
def __init__(self, config, keep_masked_pixels=False):
def __init__(self, config):
"""Initializes class instance.
Arguments
---------
config: configparser.SectionProxy
Parsed options to initialize class
keep_masked_pixels: bool (default: False)
Determines the method to mask pixels. If true, sets ivar to 0.
Raise
-----
MaskError if there are missing variables
Expand All @@ -66,7 +63,7 @@ def __init__(self, config, keep_masked_pixels=False):
"""
self.logger = logging.getLogger(__name__)

super().__init__(keep_masked_pixels)
super().__init__(config)

# first load the dla catalogue
filename = config.get("filename")
Expand Down
4 changes: 2 additions & 2 deletions py/picca/delta_extraction/masks/lines_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class LinesMask(Mask):
Table with the observed-frame wavelength of the lines to mask. This usually
contains the sky lines.
"""
def __init__(self, config, keep_masked_pixels=False):
def __init__(self, config):
"""Initialize class instance.
Arguments
---------
config: configparser.SectionProxy
Parsed options to initialize class
"""
super().__init__(keep_masked_pixels)
super().__init__(config)

mask_file = config.get("filename")
if mask_file is None:
Expand Down
2 changes: 1 addition & 1 deletion py/picca/delta_extraction/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def read_masks(self):
self.logger.info(f"Reading masks. There are {num_masks} masks")

for MaskType, mask_arguments in self.config.masks:
mask = MaskType(mask_arguments, self.config.keep_masked_pixels)
mask = MaskType(mask_arguments)
self.masks.append(mask)

t1 = time.time()
Expand Down
4 changes: 3 additions & 1 deletion py/picca/tests/delta_extraction/mask_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def test_mask(self):
Load a Mask instace and check that method apply_mask is not initialized.
"""
mask = Mask()
config = ConfigParser()
config.read_dict({"masks": {}})
mask = Mask(config['masks'])
expected_message = (
"Function 'apply_mask' was not overloaded by child class")
with self.assertRaises(MaskError) as context_manager:
Expand Down

0 comments on commit f0abe71

Please sign in to comment.