Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wfss_contam use datamodel in with context
When the DataModel is cleaned up (__del__ is called) during garbage collection it will close any opened hdulists. This will make any subsequent attempts to load data from the hdulist fail (with ValueError: I/O operation on closed file). DataModel prior to the below PR contained a self reference which created a reference cycle which made python fail to collect the object during generation 0 passes with the garbage collector. This meant that the hdulist was not immediately closed when the model fell out of scope. Code in wfss_contam relied on this persistance as the model created in the following line is no longer referenced on subsequent lines. dimage = datamodels.open(dir_image_name).data python will attempt to clean up the opened data model and fail, keeping the hdulist (stored at dir_image_name) open. This allowed later lines that reference dimage to load the array data within the hdulist. Fixing the reference cycle in stdatamodels in this PR: spacetelescope/stdatamodels#109 makes the datamodel more easily garbage collected which causes wfss_contam to fail due to the hdulist closing when the model is collected. To keep the model in scope, the above line is replaced with a with context to make it explicit that the datamodel is held open which it's contents are read. update changes
- Loading branch information