Repository navigation
Support for KPF noise analysis tool - #32
Conversation
…g half-written files, isinstance bug
| 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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
might be good to add try/except in case file changes happen within that directory
There was a problem hiding this comment.
I don't see where try/except would go here?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Added