Skip to content

Commit

Permalink
Merge branch 'main' into rcal-930-l3wcs
Browse files Browse the repository at this point in the history
  • Loading branch information
schlafly authored Jan 23, 2025
2 parents 1133fbd + f8a98f1 commit 1596319
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 82 deletions.
1 change: 1 addition & 0 deletions changes/1474.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove units from reference file datamodels.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ dependencies = [
"photutils >=1.13.0",
"pyparsing >=2.4.7",
"requests >=2.26",
# "roman_datamodels>=0.22.0,<0.23.0",
"roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git",
"roman_datamodels>=0.23.0,<0.24.0",
#"roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git",
"scipy >=1.14.1",
# "stcal>=1.10.0,<1.11.0",
"stcal @ git+https://github.com/spacetelescope/stcal.git@main",
Expand Down
2 changes: 1 addition & 1 deletion romancal/dark_current/dark_current_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def process(self, input):
# Do the dark correction
out_model = input_model
nresultants = len(input_model.meta.exposure["read_pattern"])
out_model.data -= dark_model.data[:nresultants].value
out_model.data -= dark_model.data[:nresultants]
out_model.pixeldq |= dark_model.dq
out_model.meta.cal_step.dark = "COMPLETE"

Expand Down
4 changes: 2 additions & 2 deletions romancal/dark_current/tests/test_dark.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ def test_dark_step_subtraction(instrument, exptype):
# populate data array of science cube
for i in range(0, 20):
ramp_model.data[0, 0, i] = i
darkref_model.data[0, 0, i] = i * 0.1 * darkref_model.data.unit
darkref_model.data[0, 0, i] = i * 0.1
orig_model = ramp_model.copy()

# Perform Dark Current subtraction step
result = DarkCurrentStep.call(ramp_model, override_dark=darkref_model)

# check that the dark file is subtracted frame by frame from the science data
diff = orig_model.data - darkref_model.data.value
diff = orig_model.data - darkref_model.data

# test that the output data file is equal to the difference found when subtracting
# reffile from sci file
Expand Down
9 changes: 4 additions & 5 deletions romancal/photom/photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ def photom_io(input_model, photom_metadata):

# Store the conversion factor in the meta data
log.info(f"photmjsr value: {conversion:.6g}")
input_model.meta.photometry.conversion_megajanskys = conversion.value
input_model.meta.photometry.conversion_megajanskys = conversion

# Get the scalar conversion uncertainty factor
uncertainty_conv = photom_metadata["uncertainty"]

# Store the uncertainty conversion factor in the meta data
log.info(f"uncertainty value: {uncertainty_conv:.6g}")
input_model.meta.photometry.conversion_megajanskys_uncertainty = (
uncertainty_conv.value
)
input_model.meta.photometry.conversion_megajanskys_uncertainty = uncertainty_conv

# Return updated input model
return input_model
Expand All @@ -56,9 +54,10 @@ def save_area_info(input_model, photom_parameters):
"""

# Load the average pixel area values from the photom reference file header
area_ster = photom_parameters["pixelareasr"].value
area_ster = photom_parameters["pixelareasr"]

# Copy the pixel area values to the input model
log.debug(f"pixel_area = {area_ster}")
input_model.meta.photometry.pixel_area = area_ster

# Return updated input model
Expand Down
26 changes: 10 additions & 16 deletions romancal/photom/tests/test_photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,13 @@ def create_photom_wfi_image(min_r=3.1, delta=0.1):
nrows = len(optical_element)

# Create sample photometry keyword values
photmjsr = (
np.linspace(min_r, min_r + (nrows - 1.0) * delta, nrows)
* u.megajansky
/ u.steradian
)
uncertainty = (
np.linspace(min_r / 20.0, min_r / 20.0 + (nrows - 1.0) * delta / 20.0, nrows)
* u.megajansky
/ u.steradian
photmjsr = np.linspace(min_r, min_r + (nrows - 1.0) * delta, nrows)
uncertainty = np.linspace(
min_r / 20.0, min_r / 20.0 + (nrows - 1.0) * delta / 20.0, nrows
)

# Create sample area keyword values
area_ster = 2.31307642258977e-14 * u.steradian
area_ster = 2.31307642258977e-14
pixelareasr = np.ones(nrows, dtype=np.float64) * area_ster

# Bundle values into a list
Expand Down Expand Up @@ -131,32 +125,32 @@ def test_apply_photom1():
output_model = photom.apply_photom(input_model, photom_model)

# Set reference photometry
area_ster = 2.31307642258977e-14 * u.steradian
area_ster = 2.31307642258977e-14

# Tests for pixel areas
assert np.isclose(
output_model.meta.photometry.pixel_area,
area_ster.value,
area_ster,
atol=1.0e-7,
)

# Set reference photometry
phot_ster = 3.5 * u.megajansky / u.steradian
phot_ster = 3.5

# Tests for photometry
assert np.isclose(
output_model.meta.photometry.conversion_megajanskys,
phot_ster.value,
phot_ster,
atol=1.0e-7,
)

# Set reference photometric uncertainty
muphot_ster = 0.175 * u.megajansky / u.steradian
muphot_ster = 0.175

# Tests for photometric uncertainty
assert np.isclose(
output_model.meta.photometry.conversion_megajanskys_uncertainty,
muphot_ster.value,
muphot_ster,
atol=1.0e-7,
)

Expand Down
11 changes: 4 additions & 7 deletions romancal/ramp_fitting/ramp_fit_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import TYPE_CHECKING

import numpy as np
from astropy import units as u
from roman_datamodels import datamodels as rdd
from roman_datamodels import maker_utils
from roman_datamodels import stnode as rds
Expand Down Expand Up @@ -109,8 +108,8 @@ def ols_cas22(self, input_model, readnoise_model, gain_model, dark_model):

resultants = input_model.data
dq = input_model.groupdq
read_noise = readnoise_model.data.value
gain = gain_model.data.value
read_noise = readnoise_model.data
gain = gain_model.data
read_time = input_model.meta.exposure.frame_time

# Force read pattern to be pure lists not LNodes
Expand All @@ -121,9 +120,7 @@ def ols_cas22(self, input_model, readnoise_model, gain_model, dark_model):
# add dark current back into resultants so that Poisson noise is
# properly accounted for
tbar = np.array([np.mean(reads) * read_time for reads in read_pattern])
resultants += (
dark_model.dark_slope.to(u.DN / u.s).value[None, ...] * tbar[:, None, None]
)
resultants += dark_model.dark_slope[None, ...] * tbar[:, None, None]

# account for the gain
resultants *= gain
Expand All @@ -148,7 +145,7 @@ def ols_cas22(self, input_model, readnoise_model, gain_model, dark_model):
dq = output.dq.astype(np.uint32)

# remove dark current contribution to slopes
slopes -= dark_model.dark_slope.to(u.DN / u.s).value * gain
slopes -= dark_model.dark_slope * gain

# Propagate DQ flags forward.
ramp_dq = get_pixeldq_flags(dq, input_model.pixeldq, slopes, err, gain)
Expand Down
33 changes: 6 additions & 27 deletions romancal/ramp_fitting/tests/test_ramp_fit_cas22.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import numpy as np
import pytest
from astropy import units as u
from astropy.time import Time
from roman_datamodels import maker_utils
from roman_datamodels.datamodels import (
Expand Down Expand Up @@ -272,23 +271,11 @@ def generate_wfi_reffiles(
gain_ref["meta"]["useafter"] = Time("2022-01-01T11:11:11.111")

if randomize:
gain_ref["data"] = u.Quantity(
(rng.random(shape) * 0.5).astype(np.float32) * ingain,
u.electron / u.DN,
dtype=np.float32,
)
gain_ref["data"] = (rng.random(shape) * 0.5).astype(np.float32) * ingain
else:
gain_ref["data"] = u.Quantity(
np.ones(shape).astype(np.float32) * ingain,
u.electron / u.DN,
dtype=np.float32,
)
gain_ref["data"] = np.ones(shape).astype(np.float32) * ingain
gain_ref["dq"] = np.zeros(shape, dtype=np.uint16)
gain_ref["err"] = u.Quantity(
(rng.random(shape) * 0.05).astype(np.float32),
u.electron / u.DN,
dtype=np.float32,
)
gain_ref["err"] = (rng.random(shape) * 0.05).astype(np.float32)

gain_ref_model = GainRefModel(gain_ref)

Expand All @@ -303,15 +290,9 @@ def generate_wfi_reffiles(
rn_ref["meta"]["exposure"]["frame_time"] = 666

if randomize:
rn_ref["data"] = u.Quantity(
(rng.random(shape) * rnoise).astype(np.float32),
u.DN,
dtype=np.float32,
)
rn_ref["data"] = ((rng.random(shape) * rnoise).astype(np.float32),)
else:
rn_ref["data"] = u.Quantity(
np.ones(shape).astype(np.float32) * rnoise, u.DN, dtype=np.float32
)
rn_ref["data"] = np.ones(shape).astype(np.float32) * rnoise

rn_ref_model = ReadnoiseRefModel(rn_ref)

Expand All @@ -327,9 +308,7 @@ def generate_wfi_reffiles(
dark_ref["meta"]["exposure"]["type"] = "WFI_IMAGE"
dark_ref["meta"]["exposure"]["frame_time"] = 666

dark_ref["dark_slope"] = u.Quantity(
np.zeros(shape).astype(np.float32) * 0.01, u.DN / u.s, dtype=np.float32
)
dark_ref["dark_slope"] = np.zeros(shape).astype(np.float32) * 0.01

dark_ref_model = DarkRefModel(dark_ref)

Expand Down
10 changes: 6 additions & 4 deletions romancal/regtest/test_wfi_photom.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ def test_absolute_photometric_calibration(rtdata, ignore_asdf_paths):
)
assert photom_out.meta.cal_step.photom == "COMPLETE"

convval = 0.73678
step.log.info(
"DMS140 MSG: Photom megajansky conversion calculated? : "
+ str(
math.isclose(
photom_out.meta.photometry.conversion_megajanskys,
0.3324,
convval,
abs_tol=0.0001,
)
)
)
assert math.isclose(
photom_out.meta.photometry.conversion_megajanskys, 0.3324, abs_tol=0.0001
photom_out.meta.photometry.conversion_megajanskys, convval, abs_tol=0.0001
)

step.log.info(
Expand All @@ -86,19 +87,20 @@ def test_absolute_photometric_calibration(rtdata, ignore_asdf_paths):
abs_tol=1.0e-17,
)

uncval = 0.02866405
step.log.info(
"DMS140 MSG: Photom megajansky conversion uncertainty calculated? : "
+ str(
math.isclose(
photom_out.meta.photometry.conversion_megajanskys_uncertainty,
0.0,
uncval,
abs_tol=1.0e-6,
)
)
)
assert math.isclose(
photom_out.meta.photometry.conversion_megajanskys_uncertainty,
0.0,
uncval,
abs_tol=1.0e-6,
)

Expand Down
Loading

0 comments on commit 1596319

Please sign in to comment.