Skip to content

Commit

Permalink
Merge pull request #69 from oirlab/port_parse_subarray_map_step
Browse files Browse the repository at this point in the history
Refactoring of parse_subarray_map_step and test
  • Loading branch information
zonca committed Jul 9, 2024
2 parents 7e24590 + 3ca065b commit 435f167
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -677,4 +677,22 @@ properties:
title: Number of pixels in detector y-axis direction
type: integer
fits_keyword: DETYSIZ
blend_table: True
blend_table: True
subarray_map:
title: Subarray map
type: array
items:
type: object
properties:
xstart:
title: Starting pixel in axis 1 direction
type: integer
ystart:
title: Starting pixel in axis 2 direction
type: integer
xsize:
title: Number of pixels in axis 1 direction
type: integer
ysize:
title: Number of pixels in axis 2 direction
type: integer
41 changes: 26 additions & 15 deletions liger_iris_pipeline/parse_subarray_map/parse_subarray_map_step.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import numpy as np

from jwst.stpipe import Step
from jwst import datamodels
from .. import datamodels
import stdatamodels

__all__ = ["ParseSubarrayMapStep"]

SUBARRAY_DQ_BIT = 4


# NOTE: xstart/ystart use 1-based indexing
def parse_subarray_map(subarray_map):
subarray_metadata = []
for subarray_id in range(1, 10 + 1):
Expand All @@ -34,18 +35,28 @@ class ParseSubarrayMapStep(Step):

def process(self, input):

with datamodels.open(input) as input_model:

if "subarr_map" in input_model:
self.log.info("Parsing the SUBARR_MAP extension")
result = input_model.copy()
for each in parse_subarray_map(result["subarr_map"]):
result.meta.subarray_map.append(each)
result.dq[result["subarr_map"] != 0] = np.bitwise_or(
result.dq[result["subarr_map"] != 0], 2 ** SUBARRAY_DQ_BIT
)
else:
self.log.info("No SUBARR_MAP extension found")
result = input_model
if isinstance(input, str):
input_model = datamodels.open(input)
else:
input_model = input

if "subarr_map" in input_model:

self.log.info("Parsing the SUBARR_MAP extension")

result = input_model.copy()

# Create metadata from image ID map
for each in parse_subarray_map(result["subarr_map"]):
result.meta.subarray_map.append(each)

# Indicate subarrays in dq flags
result.dq[result["subarr_map"] != 0] = np.bitwise_or(
result.dq[result["subarr_map"] != 0],
2 ** SUBARRAY_DQ_BIT
)
else:
self.log.info("No SUBARR_MAP extension found")
result = input_model

return result
259 changes: 0 additions & 259 deletions liger_iris_pipeline/tests/test_parse_subarray_map.ipynb

This file was deleted.

Loading

0 comments on commit 435f167

Please sign in to comment.