spacetelescope / jwst

Python library for science observations from the James Webb Space Telescope
https://jwst-pipeline.readthedocs.io/en/latest/
Other
567 stars 167 forks source link

model_blender produces incorrect observation time #8753

Closed stscijgbot-jp closed 1 month ago

stscijgbot-jp commented 1 month ago

Issue JP-3732 was created on JIRA by Brett Graham:

When "blending" metadata to produce outputs for some steps (like resample, calwebb_coron3 and cube build) the observation time (TIME-OBS) are combined in a way that can produce an incorrect result. Here is a minimal example:


import jwst.datamodels
from jwst.model_blender.blendmeta import blendmodels
m0 = jwst.datamodels.ImageModel()
m0.meta.instrument.name = 'NIRCAM'
m0.meta.filename = 'foo.fits'
m1 = jwst.datamodels.ImageModel()
m1.meta.instrument.name = 'NIRCAM'
m1.meta.filename = 'bar.fits'
t0 = "15:48:12.751"
t1 = "15:48:12.755"
m0.meta.observation.time = t0
m1.meta.observation.time = t1
o = jwst.datamodels.ImageModel()
blendmodels(o, [m0, m1])
print(type(o.meta.observation.time))
print(o.meta.observation.time)
assert o.meta.observation.time == t0 ```
The above code should produce a result with observation (start) time of 15:48:12.751 (the minimum as determined by m0) but instead produces 15:48:12.750999 (1 microsecond error).

 
stscijgbot-jp commented 1 month ago

Comment by David Law on JIRA:

Is this a bug or a floating point precision limitation?  Given that the individual measurements are only given to 3 decimal places, any rounding error at the sixth decimal place when combining them would not be significant.

braingram commented 1 month ago

I would say this is a bug. It's caused by: https://github.com/spacetelescope/jwst/blob/c2d87f7a2c8c4e383b0b4c961d802205ca0b280f/jwst/model_blender/blendrules.py#L128 which incorrectly handles the float/int/time conversion introducing floating point errors. The conversions are unnecessary as the input time strings have matching lexical and chronological sorting and can be blended without converting them to times. This would allow removal of the _isotime function and the error.

stscijgbot-jp commented 1 month ago

Comment by Melanie Clarke on JIRA:

Fixed by #8759