Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-superonion committed Sep 13, 2023
1 parent ef1b005 commit ca87043
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
5 changes: 2 additions & 3 deletions bin/fpfs_process_descsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ def __init__(self, config_name):
self.sigma_as = cparser.getfloat("FPFS", "sigma_as")
self.sigma_det = cparser.getfloat("FPFS", "sigma_det")
self.rcut = cparser.getint("FPFS", "rcut")
# order of shear estimator
self.nnord = cparser.getint("FPFS", "nnord", fallback=4)
if self.nnord not in [4, 6]:
raise ValueError(
Expand Down Expand Up @@ -223,7 +222,7 @@ def run(self, fname):

det_fname = os.path.join(self.catdir, fname.split("/")[-1])
det_fname = det_fname.replace("image-", "det-")
if os.path.isfile(out_fname):
if os.path.isfile(out_fname) and os.path.isfile(det_fname):
print("Already has measurement for this simulation. ")
return
psf_array2, psf_array3, cov_elem = self.prepare_noise_psf(fname)
Expand All @@ -236,8 +235,8 @@ def run(self, fname):
elapsed_time = end_time - start_time
# Print the elapsed time
print(f"Elapsed time: {elapsed_time} seconds")
fpfs.io.save_catalog(out_fname, cat, dtype="shape", nnord=str(self.nnord))
fpfs.io.save_catalog(det_fname, det, dtype="position", nnord=str(self.nnord))
fpfs.io.save_catalog(out_fname, cat, dtype="shape", nnord=str(self.nnord))
return


Expand Down
64 changes: 56 additions & 8 deletions bin/simple_coadd_descsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,38 @@
# GNU General Public License for more details.
#
import os
import glob
import schwimmbad
import numpy as np
import astropy.io.fits as pyfits
from fpfs.io import save_image

# from fpfs.io import save_image
from argparse import ArgumentParser
from configparser import ConfigParser


def get_sim_fname(directory, ftype, min_id, max_id, nshear, nrot, band):
"""Generate filename for simulations
Args:
ftype (str): file type ('src' for source, and 'image' for exposure
min_id (int): minimum id
max_id (int): maximum id
nshear (int): number of shear
nrot (int): number of rotations
band (str): 'grizy' or 'a'
Returns:
out (list): a list of file name
"""
out = [
os.path.join(
directory, "%s-%05d_g1-%d_rot%d_%s.fits" % (ftype, fid, gid, rid, band)
)
for fid in range(min_id, max_id)
for gid in range(nshear)
for rid in range(nrot)
]
return out


band_map = {
"g": 0,
"r": 1,
Expand Down Expand Up @@ -80,10 +103,12 @@ def prepare(self, fname):
def prepare_image(self, fname):
blist = ["g", "r", "i", "z"]
self.prepare(fname)
gal_array = np.zeros((self.image_nx, self.image_nx), dtype=np.float32)
# dtp = np.float32
dtp = np.float64
gal_array = np.zeros((self.image_nx, self.image_nx), dtype=dtp)
weight_all = 0.0
for band in blist:
print("processing %s band" % band)
print("%s-band running" % band)
weight = w_map[band]
weight_all = weight_all + weight
fname2 = fname.replace("_g.fits", "_%s.fits" % band)
Expand All @@ -93,14 +118,16 @@ def prepare_image(self, fname):
return gal_array

def run(self, fname):
print("running on image: %s" % fname)
out_dir = self.img_dir
out_fname = os.path.join(out_dir, fname.split("/")[-1])
out_fname = out_fname.replace("_g.fits", "_a.fits")
if os.path.exists(out_fname):
print("Already has measurement for this simulation. ")
print("Already has image. ")
return
exposure = self.prepare_image(fname)
save_image(out_fname, exposure)
# save_image(out_fname, exposure)
pyfits.writeto(out_fname, exposure)
return


Expand All @@ -112,6 +139,18 @@ def run(self, fname):
type=str,
help="configure file name",
)
parser.add_argument(
"--min_id",
required=True,
type=int,
help="minimum ID, e.g. 0",
)
parser.add_argument(
"--max_id",
required=True,
type=int,
help="maximum ID, e.g. 4000",
)
group = parser.add_mutually_exclusive_group()
group.add_argument(
"--ncores",
Expand All @@ -130,8 +169,17 @@ def run(self, fname):
args = parser.parse_args()
pool = schwimmbad.choose_pool(mpi=args.mpi, processes=args.n_cores)
worker = Worker(args.config)
fname_list = glob.glob(os.path.join(worker.img_dir, "image-*_g.fits"))
fname_list = np.sort(fname_list) # [0:1]

band = "g"
fname_list = get_sim_fname(
worker.img_dir,
"image",
args.min_id,
args.max_id,
2,
2,
band,
)
for r in pool.map(worker.run, fname_list):
pass
pool.close()

0 comments on commit ca87043

Please sign in to comment.