Skip to content

Commit 01fee37

Browse files
committed
Add docs to RealGalaxyCatalog.close()
(#1333)
1 parent 50cc4d9 commit 01fee37

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

galsim/real.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ def __init__(self, file_name=None, sample=None, dir=None, preload=False, logger=
548548
logger.debug('RealGalaxyCatalog %s has %d objects',self.file_name,self.nobjects)
549549

550550
self._preload = preload
551-
self.loaded_files = {}
552551
self.saved_noise_im = {}
552+
self.loaded_files = {}
553553
# The pyfits commands aren't thread safe. So we need to make sure the methods that
554554
# use pyfits are not run concurrently from multiple threads.
555555
self.gal_lock = Lock() # Use this when accessing gal files
@@ -647,13 +647,22 @@ def __del__(self):
647647
self.close()
648648

649649
def close(self):
650+
"""Close all loaded files.
651+
652+
Usually it is a performance improvement to keep the various input files open while using
653+
the RealGalaxyCatalog, especially if the access of the galaxies is in semi-random order.
654+
However, if you want to release the memory tied up in these files before the
655+
RealGalaxyCatalog goes out of scope, then this method will release the memroy directly.
656+
"""
650657
# Need to close any open files.
651658
# Make sure to check if loaded_files exists, since the constructor could abort
652659
# before it gets to the place where loaded_files is built.
653660
if hasattr(self, 'loaded_files'):
654661
for f in self.loaded_files.values():
655662
f.close()
656-
self.loaded_files = {}
663+
self.loaded_files.clear()
664+
# Also release the memory in the noise images, even though this is usually negligible.
665+
self.saved_noise_im.clear()
657666

658667
def getNObjects(self) : return self.nobjects
659668
def __len__(self): return self.nobjects

0 commit comments

Comments
 (0)