You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"ReferenceError: weakly-referenced object no longer exists" with FITS columns #4345
I feel that in principle what the user was doing here should have worked. The "Delayed" data mechanism being used here for the columns is a hold-over from much older versions of PyFITS, and needs to be reworked.
This would actually be addressed by the plan I've long had for refactoring FITS I/O so that the I/O details for reading an individual array (where that could also be a single column in a table) are fully separated from the HDU object itself, which is somewhat more ephemeral.
The way this would work is that all the details of the data structure for a FITS file would be determined from the header(s) when the file is first read, and cached in a data structure that associates the info with that file (along with a timestamp) or file-like object. When using mmap this might also hold an existing mmap to the file, though I'm less sure of how I feel about that. Anyways, point being, a "delayed read" of an array would work by looking into this cache for the physical details about where to find the array data, and then return it, without going through the HDU object itself. This would also speed up the "convenience" functions, since they can access cached details about a file without having to re-read all the file's headers each time the same file is accessed.
This has been my plan for a long time but it hasn't been high priority.
@embray for table operation this would be the fix with pyfits to mergre table
hdulist1 = pyfits.open(table1)
hdulist2 = pyfits.open(table2)
t1 = hdulist1[1].columns
t2 = hdulist2[1].columns
new_columns = t1 + t2
hdu = pyfits.BinTableHDU.from_columns(new_columns)
hdu.writeto(outtable)
#explicitly close the HDUs; might free up memory
hdulist1.close()
hdulist2.close()
@AMAN3003 Those examples assume table1 and table are just filenames for some FITS files containing binary tables--as the first argument to fits.open is a filename or file-like object.
Please don't take this the wrong way, but if you weren't able to understand the meaning of the above Traceback this issue is far too advanced to be worth your time.
In [6]: with fits.open("lower.fits") as hdul1, fits.open("upper.fits") as hdul2:
...: new_columns = hdul1[1].columns + hdul2[1].columns
...: hdu = fits.BinTableHDU.from_columns(new_columns)
so will just close this as "wontfix" (one should keep a reference to the parent HDU/HDUList).
Activity
AMAN3003 commentedon Feb 7, 2016
@embray for table operation this would be the fix with pyfits to mergre table
hdulist1 = pyfits.open(table1)
hdulist2 = pyfits.open(table2)
t1 = hdulist1[1].columns
t2 = hdulist2[1].columns
new_columns = t1 + t2
hdu = pyfits.BinTableHDU.from_columns(new_columns)
hdu.writeto(outtable)
#explicitly close the HDUs; might free up memory
hdulist1.close()
hdulist2.close()
AMAN3003 commentedon Feb 7, 2016
@embray but when I tried to use any table operation in astropy it result in the following error
from astropy.table import Table, hstack
In [33]: t1 = Table.read(table1)
NameError Traceback (most recent call last)
in ()
----> 1 t1 = Table.read(table1)
NameError: name 'table1' is not defined
@embray do I Need to create table if so then where
embray commentedon Feb 8, 2016
@AMAN3003 Those examples assume
table1andtableare just filenames for some FITS files containing binary tables--as the first argument tofits.openis a filename or file-like object.Please don't take this the wrong way, but if you weren't able to understand the meaning of the above Traceback this issue is far too advanced to be worth your time.
AMAN3003 commentedon Feb 8, 2016
@embray I did understand the meaning of the above but could you provide sample table fits file to fix this issue
embray commentedon Feb 17, 2016
You can find example tables in the test data, but you'll also note that this issue has been labeled "Package-expert" since I submitted it.
saimn commentedon Dec 4, 2025
This works
so will just close this as "wontfix" (one should keep a reference to the parent HDU/HDUList).