Skip to content

Support for KPF noise analysis tool - #32

Merged
Yashvi-Sharma merged 8 commits into
mainfrom
kpf-config
Oct 9, 2026
Merged

Yashvi-Sharma merged 8 commits into
mainfrom
kpf-config

Conversation

@Yashvi-Sharma

Copy link
Copy Markdown
Collaborator

Added

  • KPF config, custom file loading and file identifier functions.
  • Raveled welch method in core
  • Noise analysis task and task results
  • KPF demo notebook, and tests.

Comment thread src/eregion/tasks/custom.py Outdated
else:
logger.debug(f"Found OFFSET key {offset_key[0]} in header for file {filename} HDU {i}")
offset = hdr[offset_key[0]]
input_data_array[i] = process_raw_numbers(data.view('>u4'), offset)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the array guaranteed to be already stored big-endian? Since view('>u4') doesn't convert values, it reinterprets the array's raw bytes as big-endian unsigned 32-bit integers.

You could convert by value with astype(np.uint32), which is correct whatever the input byte order

if data.dtype.kind == 'i' and data.dtype.itemsize == 4:
    data = data.view(data.dtype.byteorder + 'u4')
input_data_array[i] = process_raw_numbers(data.astype(np.uint32), offset)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I made the function more robust overall for expected KPF image data

)
if self.watch_mode:
now = time.time()
found_files = [f for f in found_files if now-os.path.getmtime(f) >= self.settle_time]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to add try/except in case file changes happen within that directory

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where try/except would go here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way

             if self.watch_mode:
                 now = time.time()
                settled = []
                for f in found_files:
                    try:
                        mtime = os.path.getmtime(f)
                    except FileNotFoundError:
                        # file changed after the scan
                        continue
                    if now - mtime >= self.settle_time:
                        settled.append(f)
                found_files = settled
             return found_files

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh you meant file changing by file getting deleted or renamed...it would be quite unrealistic if something like that happens in the milliseconds between scan and this block. If something else makes getmtime fail the try-except will hide it at the moment

@Yashvi-Sharma
Yashvi-Sharma requested a review from prkrtg October 9, 2026 22:19
@Yashvi-Sharma
Yashvi-Sharma merged commit 077d3c0 into main Oct 9, 2026
4 checks passed
@Yashvi-Sharma
Yashvi-Sharma deleted the kpf-config branch October 9, 2026 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants