Skip to content

Commit 8b654b9

Browse files
committed
function added but not tested
1 parent 8578eef commit 8b654b9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

phrosty/pipeline.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import nvtx
1010
import pathlib
1111
import re
12+
import shutil
1213
import tracemalloc
1314

1415
# Imports ASTRO
@@ -215,6 +216,7 @@ def __init__( self, object_id, ra, dec, band, science_images, template_images, n
215216
self.image_base_dir = pathlib.Path( self.config.value( 'photometry.phrosty.paths.image_base_dir' ) )
216217
self.dia_out_dir = pathlib.Path( self.config.value( 'photometry.phrosty.paths.dia_out_dir' ) )
217218
self.scratch_dir = pathlib.Path( self.config.value( 'photometry.phrosty.paths.scratch_dir' ) )
219+
self.temp_dir = pathlib.Path( self.config.value( 'photometry.phrosty.paths.temp_dir' ) )
218220
self.ltcv_dir = pathlib.Path( self.config.value( 'photometry.phrosty.paths.ltcv_dir' ) )
219221

220222
self.object_id = object_id
@@ -591,6 +593,19 @@ def make_lightcurve( self ):
591593
def write_fits_file( self, data, header, savepath ):
592594
fits.writeto( savepath, data, header=header, overwrite=True )
593595

596+
def clear_contents( self, dir ):
597+
for f in self.dir.iterdir():
598+
try:
599+
if f.is_dir():
600+
shutil.rmtree( f )
601+
else:
602+
f.unlink()
603+
604+
except:
605+
print( f'Oops! Deleting {f} from {dir} did not work.' )
606+
607+
608+
594609
def __call__( self, through_step=None ):
595610
if self.mem_trace:
596611
tracemalloc.start()
@@ -824,6 +839,9 @@ def log_fits_write_error( savepath, x ):
824839
SNLogger.info( f"After make_lightcurve, memory usage = \
825840
{tracemalloc.get_traced_memory()[1]/(1024**2):.2f} MB" )
826841

842+
if self.nuke_temp_dir:
843+
self.clear_contents( self.temp_dir )
844+
827845
# ======================================================================
828846

829847

0 commit comments

Comments
 (0)