Commits (3)
......@@ -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 = []
......
......@@ -45,7 +45,6 @@ class Filter(object):
def is_too_bright(self, mag, margin=-2.5):
return mag <= self.mag_saturation + margin
# return mag <= 14.0
def is_too_dim(self, mag, margin=1.0):
return mag >= self.mag_limiting + margin
......@@ -143,7 +142,7 @@ class Filter(object):
del sl
gc.collect()
def update_limit_saturation_mags(self, exptime=150., psf_fwhm=0.1969, skyFn='sky_emiss_hubble_50_50_A.dat', chip=None):
def update_limit_saturation_mags(self, exptime=150., psf_fwhm=0.1969, skyFn='sky_emiss_hubble_50_50_A.dat', chip=None, full_depth_exptime=None):
if self.filter_type in _util.SPEC_FILTERS:
return
if chip is not None:
......@@ -160,6 +159,10 @@ class Filter(object):
self.mag_limiting, self.mag_saturation = _util.calculateLimitMag(
psf_fwhm=psf_fwhm, pixelSize=pix_scale, throughputFn=throughput_file, readout=5.0, skyFn=skyFn, darknoise=dark_noise, exTime=exptime, fw=full_well)
if full_depth_exptime is not None:
self.mag_limiting, _ = _util.calculateLimitMag(
psf_fwhm=psf_fwhm, pixelSize=pix_scale, throughputFn=throughput_file, readout=5.0, skyFn=skyFn, darknoise=dark_noise, exTime=full_depth_exptime, fw=full_well)
print("for filter %s: mag_limiting: %.3f, mag_saturation: %.3f" %
(self.filter_type, self.mag_limiting, self.mag_saturation))
......@@ -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)
......@@ -308,15 +308,21 @@ def MakeTrail(imgarr, satuyxtuple, charge, fullwell=9e4, direction='up', trailcu
if yi == 0 or yi == imgarr.shape[0]-1:
imgarr[yi, xi] = fullwell
break
if direction == 'up':
if imgarr[yi-1, xi] >= fullwell:
imgarr[yi, xi] = fullwell
yi -= 1
# [TEST] charge in the middle
if yi == (imgarr.shape[0] // 2 - 1):
break
continue
elif direction == 'down':
if imgarr[yi+1, xi] >= fullwell:
imgarr[yi, xi] = fullwell
yi += 1
if yi == (imgarr.shape[0] // 2):
break
continue
if aa <= 1:
while imgarr[yi, xi] >= fullwell:
......@@ -325,13 +331,15 @@ def MakeTrail(imgarr, satuyxtuple, charge, fullwell=9e4, direction='up', trailcu
imgarr[yi-1, xi] += charge
charge = imgarr[yi-1, xi]-fullwell
yi -= 1
if yi < 0:
# if yi < 0:
if yi < 0 or yi == (imgarr.shape[0]//2 - 1):
break
elif direction == 'down':
imgarr[yi+1, xi] += charge
charge = imgarr[yi+1, xi]-fullwell
yi += 1
if yi > imgarr.shape[0]:
# if yi > imgarr.shape[0]:
if yi > imgarr.shape[0] or yi == (imgarr.shape[0]//2):
break
else:
# calculate bleeding trail:
......@@ -342,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:
......@@ -355,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
......
......@@ -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
......@@ -91,6 +94,10 @@ class CatalogBase(metaclass=ABCMeta):
bandpass = target_filt.bandpass_full
if norm_filt is not None:
if hasattr(norm_filt, 'bandpass_full'):
norm_filt = Table(
np.array(np.array([norm_filt.bandpass_full.wave_list*10.0, norm_filt.bandpass_full.func(
norm_filt.bandpass_full.wave_list)])).T, names=(['WAVELENGTH', 'SENSITIVITY']))
norm_thr_rang_ids = norm_filt['SENSITIVITY'] > 0.001
else:
norm_filt = Table(
......
......@@ -75,7 +75,9 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
for ifilt in range(len(self.all_filters)):
temp_filter = self.all_filters[ifilt]
temp_filter.update_limit_saturation_mags(
exptime=pointing.get_full_depth_exptime(temp_filter.filter_type), chip=chip)
exptime=pointing.exp_time,
full_depth_exptime=pointing.get_full_depth_exptime(temp_filter.filter_type),
chip=chip)
if temp_filter.filter_type.lower() == self.overall_config["obs_setting"]["cut_in_band"].lower():
cut_filter = temp_filter
......@@ -100,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):
......@@ -109,6 +112,7 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
try:
sed_data = cat.load_sed(obj)
norm_filt = cat.load_norm_filt(obj)
obj.sed, obj.param["mag_%s" % filt.filter_type.lower()], obj.param["flux_%s" % filt.filter_type.lower()] = cat.convert_sed(
mag=obj.param["mag_use_normal"],
sed=sed_data,
......@@ -116,11 +120,12 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
norm_filt=norm_filt,
mu=obj.mu
)
_, obj.param["mag_%s" % cut_filter.filter_type.lower()], obj.param["flux_%s" % cut_filter.filter_type.lower()] = cat.convert_sed(
mag=obj.param["mag_use_normal"],
sed=sed_data,
target_filt=cut_filter,
norm_filt=norm_filt,
norm_filt=(norm_filt if norm_filt else filt),
mu=obj.mu
)
except Exception as e:
......@@ -136,7 +141,7 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
mag=obj.param["mag_%s" %
self.overall_config["obs_setting"]["cut_in_band"].lower()],
margin=self.overall_config["obs_setting"]["mag_sat_margin"]):
self.chip_output.Log_info("obj %s too birght!! mag_%s = %.3f" % (
self.chip_output.Log_info("obj %s too bright!! mag_%s = %.3f" % (
obj.id, cut_filter.filter_type, obj.param["mag_%s" % self.overall_config["obs_setting"]["cut_in_band"].lower()]))
bright_obj += 1
obj.unload_SED()
......@@ -237,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
......