Skip to content

Commit

Permalink
Merge branch 'master' into mprocdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
penaguerrero authored Apr 19, 2024
2 parents 95a43ef + e4ddbcd commit 6df20ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 77 deletions.
12 changes: 7 additions & 5 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ assign_wcs
associations
------------

- Ensure NRS IFU exposures don't make a spec2 association for grating/filter combinations
- Ensure NRS IFU exposures don't make a spec2 association for grating/filter combinations
where the nrs2 detector isn't illuminated. Remove dupes in mkpool. [#8395]

- Match NIRSpec imprint observations to science exposures on mosaic tile location
Expand All @@ -41,7 +41,7 @@ extract_1d
general
-------

- Removed deprecated stdatamodels model types ``DrizProductModel``,
- Removed deprecated stdatamodels model types ``DrizProductModel``,
``MIRIRampModel``, and ``MultiProductModel``. [#8388]

outlier_detection
Expand Down Expand Up @@ -81,6 +81,8 @@ tweakreg

- Output source catalog file now respects ``output_dir`` parameter. [#8386]

- Improved how a image group name is determined. [#8426]


1.14.0 (2024-03-29)
===================
Expand All @@ -96,7 +98,7 @@ ami
- Additional optional input arguments for greater user processing flexibility.
See documentation for details. [#7862]

- Bad pixel correction applied to data using new NRM reference file to calculate
- Bad pixel correction applied to data using new NRM reference file to calculate
complex visibility support (M. Ireland method implemented by J. Kammerer). [#7862]

- Make ``AmiAnalyze`` and ``AmiNormalize`` output conform to the OIFITS standard. [#7862]
Expand Down Expand Up @@ -131,7 +133,7 @@ charge_migration
as DO_NOT_USE. This group, and all subsequent groups, are then flagged as
CHARGELOSS and DO_NOT_USE. The four nearest pixel neighbor are then flagged
in the same group. [#8336]

- Added warning handler for expected NaN and inf clipping in the
``sigma_clip`` function. [#8320]

Expand Down Expand Up @@ -417,7 +419,7 @@ tweakreg

- Fixed a bug that caused failures instead of warnings when no GAIA sources
were found within the bounding box of the input image. [#8334]

- Suppress AstropyUserWarnings regarding NaNs in the input data. [#8320]

wfs_combine
Expand Down
31 changes: 0 additions & 31 deletions jwst/tweakreg/tests/test_tweakreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,6 @@ def test_is_wcs_correction_small(offset, is_good):
assert step._is_wcs_correction_small(wcs, twcs) == is_good


@pytest.mark.parametrize(
"groups, all_group_names, common_name",
[
([['abc1_cal.fits', 'abc2_cal.fits']], [], ['abc']),
(
[
['abc1_cal.fits', 'abc2_cal.fits'],
['abc1_cal.fits', 'abc2_cal.fits'],
['abc1_cal.fits', 'abc2_cal.fits'],
['def1_cal.fits', 'def2_cal.fits'],
],
[],
["abc", "abc1", "abc2", "def"],
),
([['cba1_cal.fits', 'abc2_cal.fits']], [], ['Group #1']),
([['cba1_cal.fits', 'abc2_cal.fits']], ['Group #1'], ['Group #2']),
([['cba1_cal.fits', 'abc2_cal.fits']], None, ['Unnamed Group']),
]
)
def test_common_name(groups, all_group_names, common_name):
for g, cn_truth in zip(groups, common_name):
group = []
for fname in g:
model = ImageModel()
model.meta.filename = fname
group.append(model)

cn = tweakreg_step._common_name(group, all_group_names)
assert cn == cn_truth


def test_expected_failure_bad_starfinder():

model = ImageModel()
Expand Down
51 changes: 10 additions & 41 deletions jwst/tweakreg/tweakreg_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,35 +279,30 @@ def process(self, input):
g = grp_img[0]
if len(g) == 0:
raise AssertionError("Logical error in the pipeline code.")
group_name = _common_name(g)
imcats = list(map(self._imodel2wcsim, g))
# Remove the attached catalogs
for model in g:
del model.catalog
self.log.info("* Images in GROUP '{}':".format(group_name))
self.log.info(f"* Images in GROUP '{imcats[0].meta['group_id']}':")
for im in imcats:
im.meta['group_id'] = group_name
self.log.info(" {}".format(im.meta['name']))
self.log.info(f" {im.meta['name']}")

self.log.info('')

elif len(grp_img) > 1:
# create a list of WCS-Catalog-Images Info and/or their Groups:
imcats = []
all_group_names = []
for g in grp_img:
if len(g) == 0:
raise AssertionError("Logical error in the pipeline code.")
else:
group_name = _common_name(g, all_group_names)
wcsimlist = list(map(self._imodel2wcsim, g))
# Remove the attached catalogs
for model in g:
del model.catalog
self.log.info("* Images in GROUP '{}':".format(group_name))
self.log.info(f"* Images in GROUP '{wcsimlist[0].meta['group_id']}':")
for im in wcsimlist:
im.meta['group_id'] = group_name
self.log.info(" {}".format(im.meta['name']))
self.log.info(f" {im.meta['name']}")
imcats.extend(wcsimlist)

self.log.info('')
Expand Down Expand Up @@ -511,7 +506,6 @@ def process(self, input):
)

return images


def _write_catalog(self, image_model, catalog, filename):
'''
Expand Down Expand Up @@ -560,7 +554,6 @@ def _write_catalog(self, image_model, catalog, filename):

return image_model


def _is_wcs_correction_small(self, wcs, twcs):
"""Check that the newly tweaked wcs hasn't gone off the rails"""
if self.use2dhist:
Expand Down Expand Up @@ -606,41 +599,17 @@ def _imodel2wcsim(self, image_model):
wcsinfo={'roll_ref': refang['roll_ref'],
'v2_ref': refang['v2_ref'],
'v3_ref': refang['v3_ref']},
meta={'image_model': image_model, 'catalog': catalog,
'name': model_name}
meta={
'image_model': image_model,
'catalog': catalog,
'name': model_name,
'group_id': image_model.meta.group_id,
}
)

return im


def _common_name(group, all_group_names=None):
file_names = [path.splitext(im.meta.filename)[0].strip('_- ')
for im in group]

cn = path.commonprefix(file_names)

if all_group_names is None:
if not cn:
return 'Unnamed Group'
else:
if not cn or cn in all_group_names:
# find the smallest group number to make "Group #..." unique
max_id = 1
if not cn:
cn = "Group #"
for name in all_group_names:
try:
cid = int(name.lstrip(cn))
if cid >= max_id:
max_id = cid + 1
except ValueError:
pass
cn = f"{cn}{max_id}"
all_group_names.append(cn)

return cn


def _parse_catfile(catfile):
if catfile is None or not catfile.strip():
return None
Expand Down

0 comments on commit 6df20ca

Please sign in to comment.