Skip to content

Commit

Permalink
Fix stellar (#344)
Browse files Browse the repository at this point in the history
* add min image count

* use outputmeta

* zero out f corona in subtraction
  • Loading branch information
jmbhughes authored Dec 11, 2024
1 parent 0f6c0b8 commit e2ab02a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 3 additions & 0 deletions punchbowl/level3/f_corona_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ def subtract_f_corona_background(data_object: NDCube,

interpolated_model[np.isinf(data_object.uncertainty.array)] = 0

original_mask = data_object.data[...] == 0
data_object.data[...] = data_object.data[...] - interpolated_model
data_object.data[original_mask] = 0
data_object.uncertainty.array[:, :] -= interpolated_model
data_object.uncertainty.array[original_mask] = 0
return data_object

@punch_task
Expand Down
2 changes: 1 addition & 1 deletion punchbowl/level3/polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def convert_polarization(

output_meta = NormalizedMetadata.load_template("PTM", "3")
output_meta["DATE-OBS"] = input_data.meta["DATE-OBS"].value
output = NDCube(data=new_data, wcs=new_wcs, meta=input_data.meta)
output = NDCube(data=new_data, wcs=new_wcs, meta=output_meta)

logger.info("convert2bpb finished")
output.meta.history.add_now("LEVEL3-convert2bpb", "Convert MZP to BpB")
Expand Down
12 changes: 6 additions & 6 deletions punchbowl/level3/stellar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from math import floor
from datetime import datetime

import numpy as np
Expand Down Expand Up @@ -34,6 +33,7 @@ def generate_starfield_background(
n_sigma: float = 5,
map_scale: float = 0.01,
target_mem_usage: float = 1000,
min_images:int = 5,
reference_time: datetime | None = None) -> [NDCube, NDCube]:
"""Create a background starfield_bg map from a series of PUNCH images over a long period of time."""
logger = get_run_logger()
Expand All @@ -51,7 +51,7 @@ def generate_starfield_background(
msg = "filenames cannot be empty"
raise ValueError(msg)

shape = [int(floor(132 / map_scale)), int(floor(360 / map_scale))]
shape = [int(np.floor(132 / map_scale)), int(np.floor(360 / map_scale))]
starfield_wcs = WCS(naxis=2)
# n.b. it seems the RA wrap point is chosen so there's 180 degrees
# included on either side of crpix
Expand All @@ -68,7 +68,7 @@ def generate_starfield_background(
filenames,
attribution=False,
frame_count=False,
reducer=GaussianReducer(n_sigma=n_sigma),
reducer=GaussianReducer(n_sigma=n_sigma, min_size=min_images),
starfield_wcs=starfield_wcs,
processor=PUNCHImageProcessor(0),
target_mem_usage=target_mem_usage)
Expand All @@ -80,7 +80,7 @@ def generate_starfield_background(
filenames,
attribution=False,
frame_count=False,
reducer=GaussianReducer(n_sigma=n_sigma),
reducer=GaussianReducer(n_sigma=n_sigma, min_size=min_images),
starfield_wcs=starfield_wcs,
processor=PUNCHImageProcessor(1),
target_mem_usage=target_mem_usage)
Expand All @@ -92,7 +92,7 @@ def generate_starfield_background(
filenames,
attribution=False,
frame_count=False,
reducer=GaussianReducer(n_sigma=n_sigma),
reducer=GaussianReducer(n_sigma=n_sigma, min_size=min_images),
starfield_wcs=starfield_wcs,
processor=PUNCHImageProcessor(2),
target_mem_usage=target_mem_usage)
Expand All @@ -102,7 +102,7 @@ def generate_starfield_background(
logger.info("Preparing to create outputs")

meta = NormalizedMetadata.load_template("PSM", "3")
meta["DATE-OBS"] = reference_time
meta["DATE-OBS"] = str(reference_time)
out_wcs, _ = calculate_helio_wcs_from_celestial(starfield_m.wcs, meta.astropy_time, starfield_m.starfield.shape)
output = NDCube(np.stack([starfield_m.starfield, starfield_z.starfield, starfield_p.starfield], axis=0),
wcs=out_wcs, meta=meta)
Expand Down

0 comments on commit e2ab02a

Please sign in to comment.