From a3c2766cc55f99a234f2d1ec2f6146ccda3cb019 Mon Sep 17 00:00:00 2001 From: fangyuedong Date: Mon, 2 Dec 2024 16:24:19 +0800 Subject: [PATCH] * Restrict the saturation bleeding trails and bad columns. So they cannot go across channels. * Add free_mem method in CatalogBase.py. Thus class that inhrits this base class can then implement this function to free used memory. --- catalog/C9_Catalog.py | 4 ++++ observation_sim/instruments/chip/effects.py | 10 +++++++++- observation_sim/mock_objects/CatalogBase.py | 3 +++ observation_sim/sim_steps/add_objects.py | 6 +++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/catalog/C9_Catalog.py b/catalog/C9_Catalog.py index 7081abc..8dc629f 100644 --- a/catalog/C9_Catalog.py +++ b/catalog/C9_Catalog.py @@ -468,6 +468,10 @@ class Catalog(CatalogBase): 0., 0., 0., 0., 0., 0., 0., 0., 0., -1, 0.) self.objs.append(obj) + + def free_mem(self, **kward): + self.starDDL.freeGlobeData() + del self.starDLL def _load(self, **kwargs): self.objs = [] diff --git a/observation_sim/instruments/chip/effects.py b/observation_sim/instruments/chip/effects.py index 7c4c7dc..0f835d2 100644 --- a/observation_sim/instruments/chip/effects.py +++ b/observation_sim/instruments/chip/effects.py @@ -84,7 +84,7 @@ def BadColumns(GSImage, seed=20240309, chipid=1, logger=None): rgdn = Generator(PCG64(int(seed*1.3))) nbadsecA, nbadsecD = rgn.integers(low=1, high=5, size=2) - collen = rgcollen.integers(low=int(ysize*0.1), high=int(ysize*0.7), size=(nbadsecA+nbadsecD)) + collen = rgcollen.integers(low=int(ysize*0.1), high=int(ysize*0.5), size=(nbadsecA+nbadsecD)) xposit = rgxpos.integers(low=int(xsize*0.05), high=int(xsize*0.95), size=(nbadsecA+nbadsecD)) if logger is not None: logger.info(xposit+1) @@ -350,8 +350,12 @@ def MakeTrail(imgarr, satuyxtuple, charge, fullwell=9e4, direction='up', trailcu imgarr[yi, xi] = fullwell if direction == 'up': yi -= 1 + if yi == (imgarr.shape[0]//2 - 1): + break elif direction == 'down': yi += 1 + if yi == (imgarr.shape[0]//2): + break yy += 1 else: if trail_frac < trailcutfrac: @@ -363,8 +367,12 @@ def MakeTrail(imgarr, satuyxtuple, charge, fullwell=9e4, direction='up', trailcu if direction == 'up': yi -= 1 + if yi == (imgarr.shape[0]//2 - 1): + break elif direction == 'down': yi += 1 + if yi == (imgarr.shape[0]//2): + break yy += 1 return imgarr diff --git a/observation_sim/mock_objects/CatalogBase.py b/observation_sim/mock_objects/CatalogBase.py index 106e4e7..ea94b77 100644 --- a/observation_sim/mock_objects/CatalogBase.py +++ b/observation_sim/mock_objects/CatalogBase.py @@ -12,6 +12,9 @@ class CatalogBase(metaclass=ABCMeta): def __init__(self): pass + def free_mem(self, **kward): + pass + @abstractmethod def load_sed(self, obj, **kward): pass diff --git a/observation_sim/sim_steps/add_objects.py b/observation_sim/sim_steps/add_objects.py index 81cb589..b35325b 100644 --- a/observation_sim/sim_steps/add_objects.py +++ b/observation_sim/sim_steps/add_objects.py @@ -102,6 +102,7 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param): # # [DEBUG] [TODO] # if j >= 10: # break + obj = cat.objs[j] if not self._is_obj_valid(obj): @@ -133,7 +134,6 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param): continue # [TODO] Testing - # print(obj.param["mag_%s" % filt.filter_type.lower()], obj.param["mag_%s" % cut_filter.filter_type.lower()]) # self.chip_output.Log_info("mag_%s = %.3f"%(filt.filter_type.lower(), obj.param["mag_%s"%filt.filter_type.lower()])) # Exclude very bright/dim objects (for now) @@ -242,8 +242,8 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param): obj.unload_SED() del obj # gc.collect() - cat.starDDL.freeGlobeData() - del cat.starDDL + cat.free_mem + del cat if chip.survey_type == "spectroscopic" and not self.overall_config["run_option"]["out_cat_only"] and chip.slsPSFOptim: # from observation_sim.instruments.chip import chip_utils as chip_utils -- GitLab