From 1ac27a2b45cb0d74213a005d9a583f9f87180453 Mon Sep 17 00:00:00 2001 From: kfanning Date: Thu, 16 Mar 2023 15:44:00 -0400 Subject: [PATCH] Added option to allow overwriting of files --- bin/downsample_randoms.py | 6 ++++-- bin/run_imputation.py | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/downsample_randoms.py b/bin/downsample_randoms.py index a023c5c..fe324b4 100644 --- a/bin/downsample_randoms.py +++ b/bin/downsample_randoms.py @@ -9,6 +9,8 @@ parser.add_argument('--survey', '-s', default='y1mock', help='Survey to use (typically main or y1mock)') parser.add_argument('--version', '-v', default=0, help='catalog version, for mocks this is mock number') parser.add_argument('--impversion', '-i', default=None, help='override version for imputation, default None == same as version') +parser.add_argument('--overwrite', '-o', action='store_true', help='Set flag to allow overwriting of existing files')\ + # add dir management # catdir (for base catalogs for reading, no writing) # temp dir (intermediate files like logging, nn cats, etc) @@ -46,5 +48,5 @@ randcats = Table.read(os.path.join(catdir, f'{uargs.tracer}_S_0_clustering.ran.fits')) new_randn = cat.downsample_randoms_by_ntile(randcatn, comp_ntile) new_rands = cat.downsample_randoms_by_ntile(randcats, comp_ntile) -new_rands.write(os.path.join(impute_dir, f'{uargs.tracer}_S_0_clustering.ran.fits'), format='fits') -new_randn.write(os.path.join(impute_dir, f'{uargs.tracer}_N_0_clustering.ran.fits'), format='fits') +new_rands.write(os.path.join(impute_dir, f'{uargs.tracer}_S_0_clustering.ran.fits'), format='fits', overwrite=uargs.overwrite) +new_randn.write(os.path.join(impute_dir, f'{uargs.tracer}_N_0_clustering.ran.fits'), format='fits', overwrite=uargs.overwrite) diff --git a/bin/run_imputation.py b/bin/run_imputation.py index 0fbc410..f175860 100644 --- a/bin/run_imputation.py +++ b/bin/run_imputation.py @@ -9,6 +9,8 @@ parser.add_argument('--version', '-v', default=0, help='catalog version, for mocks this is mock number') parser.add_argument('--impversion', '-i', default=None, help='override version for imputation, default None == same as version') parser.add_argument('--nobackground', '-nb', action='store_true', help='Skip imputing "background" (close to random) galaxies.') +parser.add_argument('--overwrite', '-o', action='store_true', help='Set flag to allow overwriting of existing files')\ + # add dir management # catdir (for base catalogs for reading, no writing) # temp dir (intermediate files like logging, nn cats, etc) @@ -46,7 +48,7 @@ imps = impute.ImputeModel(obs_nncat, mis_nncat_s) imps_cat = imps.run(skip_background=uargs.nobackground) -imps.impute_details.write(os.path.join(stagedir, f'{uargs.tracer}_S_impute_details.fits')) -impn.impute_details.write(os.path.join(stagedir, f'{uargs.tracer}_N_impute_details.fits')) -imps_cat.write(os.path.join(impute_dir, f'{uargs.tracer}_S_clustering.dat.fits')) -impn_cat.write(os.path.join(impute_dir, f'{uargs.tracer}_N_clustering.dat.fits')) +imps.impute_details.write(os.path.join(stagedir, f'{uargs.tracer}_S_impute_details.fits'), overwrite=uargs.overwrite) +impn.impute_details.write(os.path.join(stagedir, f'{uargs.tracer}_N_impute_details.fits'), overwrite=uargs.overwrite) +imps_cat.write(os.path.join(impute_dir, f'{uargs.tracer}_S_clustering.dat.fits'), overwrite=uargs.overwrite) +impn_cat.write(os.path.join(impute_dir, f'{uargs.tracer}_N_clustering.dat.fits'), overwrite=uargs.overwrite)