8000 JP-2664: Fix NRS-MOS source ids to be 5 digits and positive by tapastro · Pull Request #6915 · spacetelescope/jwst · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

JP-2664: Fix NRS-MOS source ids to be 5 digits and positive #6915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pipeline
- Fixed the logic used in the `calwebb_tso3` pipeline to check for null
photometry results. [#6912]

- Check source_ids in `calwebb_spec3` and force into 5 digit positive number,
if available [#6915]

ramp_fitting
------------

Expand Down
34 changes: 34 additions & 0 deletions jwst/pipeline/calwebb_spec3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from collections import defaultdict
import os.path as op
import numpy as np

from .. import datamodels
from ..associations.lib.rules_level3_base import format_product
Expand Down Expand Up @@ -162,6 +163,39 @@ def process(self, input):
for name, model in multislit_to_container(source_models).items()
]

# Check for negative and large source_id values
if len(sources) > 99999:
self.log.critical("Data contain more than 100,000 sources;"
"filename does not support 6 digit source ids.")
raise Exception

available_src_ids = set(np.arange(99999) + 1)
used_src_ids = set()
for src in sources:
src_id, model = src
src_id = int(src_id)
used_src_ids.add(src_id)
if 0 < src_id <= 99999:
available_src_ids.remove(src_id)

hotfixed_sources = []
# now find and reset bad source_id values
for src in sources:
src_id, model = src
src_id = int(src_id)
# Replace ids that aren't positive 5-digit integers
if src_id < 0 or src_id > 99999:
src_id_new = available_src_ids.pop()
self.log.info(f"Source ID {src_id} falls outside allowed range.")
self.log.info(f"Reassigning {src_id} to {str(src_id_new).zfill(5)}.")
# Replace source_id for each model in the SourceModelContainers
for contained_model in model:
contained_model.source_id = src_id_new
src_id = src_id_new
hotfixed_sources.append((str(src_id), model))

sources = hotfixed_sources

# Process each source
for source in sources:

Expand Down
0