Skip to content

Commit

Permalink
Merge pull request #2 from drlaw1558/drl_combine1d
Browse files Browse the repository at this point in the history
Add median filtering to background spectrum
  • Loading branch information
hayescr authored Oct 22, 2024
2 parents 9490e30 + 496dd4f commit abe14d0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions jwst/master_background/master_background_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from stdatamodels.properties import merge_tree
from stdatamodels.jwst import datamodels
from scipy.signal import medfilt

from jwst.datamodels import ModelContainer
from jwst.stpipe import record_step_status
Expand All @@ -25,6 +26,7 @@ class MasterBackgroundStep(Step):
save_background = boolean(default=False) # Save computed master background
force_subtract = boolean(default=False) # Force subtracting master background
output_use_model = boolean(default=True)
median_kernel = integer(default=1)
"""

def process(self, input):
Expand All @@ -51,6 +53,10 @@ def process(self, input):
has already been applied and, if so, the master background step is skipped.
If set to True, the step logic is bypassed and the master background is subtracted.
median_kernel : integer, optional
Optional user-supplied kernel with which to moving-median boxcar filter the master background
spectrum. Must be an odd integer.
Returns
-------
result : `~jwst.datamodels.ImageModel`, `~jwst.datamodels.IFUImageModel`, `~jwst.datamodels.ModelContainer`
Expand Down Expand Up @@ -140,6 +146,12 @@ def process(self, input):
exptime_key='exposure_time',
)

# If requested, apply a moving-median boxcar filter to the master background spectrum
if (self.median_kernel > 1):
self.log.info('Applying moving-median boxcar of width %i',self.median_kernel)
master_background.spec[0].spec_table['surf_bright'] = medfilt(
master_background.spec[0].spec_table['surf_bright'], kernel_size=[self.median_kernel])

background_data.close()

result = ModelContainer()
Expand Down

0 comments on commit abe14d0

Please sign in to comment.