Commit df22b3b0 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

Merge branch 'master' into 'release_v3.0'

Release version v3.2.0

See merge request !33
parents 1b4f4012 428f2c1e
...@@ -191,7 +191,7 @@ class Chip(FocalPlane): ...@@ -191,7 +191,7 @@ class Chip(FocalPlane):
"""Return the filter index and type for a given chip #(chipID) """Return the filter index and type for a given chip #(chipID)
""" """
filter_type_list = _util.ALL_FILTERS filter_type_list = _util.ALL_FILTERS
if chipID == None: if chipID is None:
chipID = self.chipID chipID = self.chipID
# updated configurations # updated configurations
......
...@@ -173,6 +173,13 @@ def get_flat(img, seed): ...@@ -173,6 +173,13 @@ def get_flat(img, seed):
return flat_img, flat_normal return flat_img, flat_normal
def get_innerflat(chip=None, filt=None):
from observation_sim.mock_objects import FlatLED
led_obj = FlatLED(chip, filt)
flat_img = led_obj.getInnerFlat()
return flat_img
def add_cosmic_rays(img, chip, exptime=150, seed=0): def add_cosmic_rays(img, chip, exptime=150, seed=0):
cr_map, cr_event_num = effects.produceCR_Map( cr_map, cr_event_num = effects.produceCR_Map(
xLen=chip.npix_x, yLen=chip.npix_y, xLen=chip.npix_x, yLen=chip.npix_y,
...@@ -206,7 +213,7 @@ def get_poisson(seed=0, sky_level=0.): ...@@ -206,7 +213,7 @@ def get_poisson(seed=0, sky_level=0.):
def get_base_img(img, chip, read_noise, readout_time, dark_noise, exptime=150., InputDark=None): def get_base_img(img, chip, read_noise, readout_time, dark_noise, exptime=150., InputDark=None):
if InputDark == None: if InputDark is None:
# base_level = read_noise**2 + dark_noise*(exptime+0.5*readout_time) # base_level = read_noise**2 + dark_noise*(exptime+0.5*readout_time)
# base_level = dark_noise*(exptime+0.5*readout_time) # base_level = dark_noise*(exptime+0.5*readout_time)
base_level = dark_noise*(exptime) base_level = dark_noise*(exptime)
...@@ -237,7 +244,7 @@ def add_poisson(img, chip, exptime=150., seed=0, sky_level=0., poisson_noise=Non ...@@ -237,7 +244,7 @@ def add_poisson(img, chip, exptime=150., seed=0, sky_level=0., poisson_noise=Non
img.addNoise(poisson_noise) img.addNoise(poisson_noise)
# img -= read_noise**2 # img -= read_noise**2
if InputDark != None: if InputDark is not None:
# "Instrument/data/dark/dark_1000s_example_0.fits" # "Instrument/data/dark/dark_1000s_example_0.fits"
hdu = fits.open(InputDark) hdu = fits.open(InputDark)
img += hdu[0].data/hdu[0].header['exptime']*exptime img += hdu[0].data/hdu[0].header['exptime']*exptime
......
This diff is collapsed.
...@@ -37,7 +37,7 @@ void addEffects(int ngx_ima, int ngy_ima, float *arr_ima, float *arr_imc, int bi ...@@ -37,7 +37,7 @@ void addEffects(int ngx_ima, int ngy_ima, float *arr_ima, float *arr_imc, int bi
{ {
printf("Adding BF effect...\n"); printf("Adding BF effect...\n");
//setup BF correlation fliter //setup BF correlation fliter
float neX; float neX, neXtemp;
float neP1 = 50000; float neP1 = 50000;
float bfaP1[9]={0.9707182, 0.002143905, 0.004131103, 0.001149542, 0.0005501739, 0.0005469659, 0.0003726081, 0.0003795207, 0.0001633302}; float bfaP1[9]={0.9707182, 0.002143905, 0.004131103, 0.001149542, 0.0005501739, 0.0005469659, 0.0003726081, 0.0003795207, 0.0001633302};
float neP2 = 10000; float neP2 = 10000;
...@@ -56,15 +56,18 @@ void addEffects(int ngx_ima, int ngy_ima, float *arr_ima, float *arr_imc, int bi ...@@ -56,15 +56,18 @@ void addEffects(int ngx_ima, int ngy_ima, float *arr_ima, float *arr_imc, int bi
neX = arr_ima[j+i*ny]; neX = arr_ima[j+i*ny];
if(neX >= 10000) if(neX >= 10000)
{ {
neXtemp = neX;
if(neXtemp > 100000)
neXtemp = 100000;
bfa[0][0]=0; //linearInterp(neX, neP1, bfaP1[0], neP2, bfaP2[0]); //0; bfa[0][0]=0; //linearInterp(neX, neP1, bfaP1[0], neP2, bfaP2[0]); //0;
bfa[0][1]=bfa[0][-1]=linearInterp(neX, neP1, bfaP1[1], neP2, bfaP2[1]); //0.01575; bfa[0][1]=bfa[0][-1]=linearInterp(neXtemp, neP1, bfaP1[1], neP2, bfaP2[1]); //0.01575;
bfa[-1][0]=bfa[1][0]=linearInterp(neX, neP1, bfaP1[2], neP2, bfaP2[2]); //0.00652; bfa[-1][0]=bfa[1][0]=linearInterp(neXtemp, neP1, bfaP1[2], neP2, bfaP2[2]); //0.00652;
bfa[-1][-1]=bfa[1][1]=bfa[-1][1]=bfa[1][-1]=linearInterp(neX, neP1, bfaP1[3], neP2, bfaP2[3]); //0.00335; bfa[-1][-1]=bfa[1][1]=bfa[-1][1]=bfa[1][-1]=linearInterp(neXtemp, neP1, bfaP1[3], neP2, bfaP2[3]); //0.00335;
bfa[0][-2]=bfa[0][2]=linearInterp(neX, neP1, bfaP1[4], neP2, bfaP2[4]); bfa[0][-2]=bfa[0][2]=linearInterp(neXtemp, neP1, bfaP1[4], neP2, bfaP2[4]);
bfa[-2][0]=bfa[2][0]=linearInterp(neX, neP1, bfaP1[5], neP2, bfaP2[5]); //0.00118; bfa[-2][0]=bfa[2][0]=linearInterp(neXtemp, neP1, bfaP1[5], neP2, bfaP2[5]); //0.00118;
bfa[-2][-1]=bfa[-2][1]=bfa[2][1]=bfa[2][-1]=linearInterp(neX, neP1, bfaP1[6], neP2, bfaP2[6]); bfa[-2][-1]=bfa[-2][1]=bfa[2][1]=bfa[2][-1]=linearInterp(neXtemp, neP1, bfaP1[6], neP2, bfaP2[6]);
bfa[-1][-2]=bfa[1][2]=bfa[-1][2]=bfa[1][-2]=linearInterp(neX, neP1, bfaP1[7], neP2, bfaP2[7]); //0.00083; bfa[-1][-2]=bfa[1][2]=bfa[-1][2]=bfa[1][-2]=linearInterp(neXtemp, neP1, bfaP1[7], neP2, bfaP2[7]); //0.00083;
bfa[-2][-2]=bfa[-2][2]=bfa[2][-2]=bfa[2][2]=linearInterp(neX, neP1, bfaP1[8], neP2, bfaP2[8]); //0.00043; bfa[-2][-2]=bfa[-2][2]=bfa[2][-2]=bfa[2][2]=linearInterp(neXtemp, neP1, bfaP1[8], neP2, bfaP2[8]); //0.00043;
} }
else else
{ {
......
...@@ -31,7 +31,7 @@ def get_trap_map(seeds,nx,ny,nmax,rho_trap,beta,c,out_dir): ...@@ -31,7 +31,7 @@ def get_trap_map(seeds,nx,ny,nmax,rho_trap,beta,c,out_dir):
get_trap_h(seeds_p,c_int(int(nsp)),c_int(int(nx)),c_int(int(ny)),\ get_trap_h(seeds_p,c_int(int(nsp)),c_int(int(nx)),c_int(int(ny)),\
c_int(int(nmax)),rho_trap_p,c_float(beta),\ c_int(int(nmax)),rho_trap_p,c_float(beta),\
c_float(c),filename) c_float(c),filename)
def bin2fits(bin_file,fits_dir,nsp,nx,ny,nmax): def bin2fits(bin_file,fits_dir,nsp,nx,ny,nmax):
data = np.fromfile(bin_file,dtype=np.float32) data = np.fromfile(bin_file,dtype=np.float32)
data = data.reshape(nx,nsp,ny,nmax).transpose(1,3,2,0) data = data.reshape(nx,nsp,ny,nmax).transpose(1,3,2,0)
...@@ -101,6 +101,6 @@ if __name__ =='__main__': ...@@ -101,6 +101,6 @@ if __name__ =='__main__':
image = fits.getdata("inputdata/image.fits").astype(np.int32) image = fits.getdata("inputdata/image.fits").astype(np.int32)
get_trap_map(trap_seeds,nx,ny,nmax,rho_trap,beta,c,".") get_trap_map(trap_seeds,nx,ny,nmax,rho_trap,beta,c,".")
bin2fits("trap.bin",".",nsp,nx,ny,nmax) bin2fits("trap.bin",".",nsp,nx,ny,nmax)
image_cti = CTI_sim(image,nx,ny,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed) image_cti = CTI_sim(image,nx,ny,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed)
fits.writeto("output/image_CTI.fits",data=image_cti,overwrite=True) fits.writeto("output/image_CTI.fits",data=image_cti,overwrite=True)
""" """
...@@ -12,6 +12,9 @@ class CatalogBase(metaclass=ABCMeta): ...@@ -12,6 +12,9 @@ class CatalogBase(metaclass=ABCMeta):
def __init__(self): def __init__(self):
pass pass
def free_mem(self, **kward):
pass
@abstractmethod @abstractmethod
def load_sed(self, obj, **kward): def load_sed(self, obj, **kward):
pass pass
...@@ -29,8 +32,8 @@ class CatalogBase(metaclass=ABCMeta): ...@@ -29,8 +32,8 @@ class CatalogBase(metaclass=ABCMeta):
param = { param = {
"star": -1, "star": -1,
"id": -1, "id": -1,
"ra": 0, "ra": -999.,
"dec": 0., "dec": -999.,
"ra_orig": 0., "ra_orig": 0.,
"dec_orig": 0., "dec_orig": 0.,
"z": 0., "z": 0.,
...@@ -44,15 +47,15 @@ class CatalogBase(metaclass=ABCMeta): ...@@ -44,15 +47,15 @@ class CatalogBase(metaclass=ABCMeta):
"bfrac": 0., "bfrac": 0.,
"av": 0., "av": 0.,
"redden": 0., "redden": 0.,
"hlr_bulge": 0., "hlr_bulge": -999.,
"hlr_disk": 0., "hlr_disk": -999.,
"ell_bulge": 0., "ell_bulge": 0.,
"ell_disk": 0., "ell_disk": 0.,
"ell_tot": 0., "ell_tot": 0.,
"e1_disk": 0., "e1_disk": -999.,
"e2_disk": 0., "e2_disk": -999.,
"e1_bulge": 0., "e1_bulge": -999.,
"e2_bulge": 0., "e2_bulge": -999.,
"teff": 0., "teff": 0.,
"logg": 0., "logg": 0.,
"feh": 0., "feh": 0.,
...@@ -91,6 +94,8 @@ class CatalogBase(metaclass=ABCMeta): ...@@ -91,6 +94,8 @@ class CatalogBase(metaclass=ABCMeta):
bandpass = target_filt.bandpass_full bandpass = target_filt.bandpass_full
if norm_filt is not None: 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 norm_thr_rang_ids = norm_filt['SENSITIVITY'] > 0.001
else: else:
norm_filt = Table( norm_filt = Table(
......
...@@ -50,6 +50,8 @@ fluxLED = {'LED1': 15, 'LED2': 15, 'LED3': 12.5, 'LED4': 9, 'LED5': 9, ...@@ -50,6 +50,8 @@ fluxLED = {'LED1': 15, 'LED2': 15, 'LED3': 12.5, 'LED4': 9, 'LED5': 9,
# 'LED14': 10} # 'LED14': 10}
mirro_eff = {'GU': 0.61, 'GV': 0.8, 'GI': 0.8} mirro_eff = {'GU': 0.61, 'GV': 0.8, 'GI': 0.8}
bandtoLed = {'NUV': ['LED1', 'LED2'], 'u': ['LED13', 'LED14'], 'g': ['LED3', 'LED4', 'LED5'], 'r': ['LED6', 'LED7'], 'i': ['LED8'], 'z': ['LED9', 'LED10'], 'y': ['LED10'], 'GU': ['LED1', 'LED2', 'LED13', 'LED14'], 'GV': ['LED3', 'LED4', 'LED5', 'LED6'], 'GI': ['LED7', 'LED8', 'LED9', 'LED10']}
# mirro_eff = {'GU':1, 'GV':1, 'GI':1} # mirro_eff = {'GU':1, 'GV':1, 'GI':1}
...@@ -69,10 +71,18 @@ class FlatLED(MockObject): ...@@ -69,10 +71,18 @@ class FlatLED(MockObject):
with pkg_resources.path('observation_sim.mock_objects.data.led', "") as ledDir: with pkg_resources.path('observation_sim.mock_objects.data.led', "") as ledDir:
self.flatDir = ledDir.as_posix() self.flatDir = ledDir.as_posix()
def getInnerFlat(self):
ledflats = bandtoLed[self.chip.filter_type]
iFlat = np.zeros([self.chip.npix_y, self.chip.npix_x])
for nled in ledflats:
iFlat = iFlat + self.getLEDImage1(led_type=nled, LED_Img_flag=False)
iFlat = iFlat/len(ledflats)
return iFlat
### ###
# return LED flat, e/s # return LED flat, e/s
### ###
def getLEDImage(self, led_type='LED1'): def getLEDImage(self, led_type='LED1', LED_Img_flag=True):
# cwave = cwaves[led_type] # cwave = cwaves[led_type]
flat = fits.open(os.path.join(self.flatDir, 'model_' + flat = fits.open(os.path.join(self.flatDir, 'model_' +
cwaves_name[led_type] + 'nm.fits')) cwaves_name[led_type] + 'nm.fits'))
...@@ -102,7 +112,10 @@ class FlatLED(MockObject): ...@@ -102,7 +112,10 @@ class FlatLED(MockObject):
N[self.chip.npix_y * i:self.chip.npix_y * (i + 1), self.chip.npix_x * j:self.chip.npix_x * (j + 1)]), N[self.chip.npix_y * i:self.chip.npix_y * (i + 1), self.chip.npix_x * j:self.chip.npix_x * (j + 1)]),
method='linear') method='linear')
U = U/np.mean(U) U = U/np.mean(U)
flatImage = U*fluxLED[led_type]*1000
flatImage = U
if LED_Img_flag:
flatImage = flatImage*fluxLED[led_type]*1000
gc.collect() gc.collect()
return flatImage return flatImage
...@@ -110,39 +123,42 @@ class FlatLED(MockObject): ...@@ -110,39 +123,42 @@ class FlatLED(MockObject):
# return LED flat, e/s # return LED flat, e/s
### ###
def getLEDImage1(self, led_type='LED1'): def getLEDImage1(self, led_type='LED1', LED_Img_flag=True):
# cwave = cwaves[led_type] # cwave = cwaves[led_type]
flat = fits.open(os.path.join(self.flatDir, 'model_' + flat = fits.open(os.path.join(self.flatDir, 'model_' +
cwaves_name[led_type] + 'nm.fits')) cwaves_name[led_type] + 'nm.fits'))
xlen = flat[0].header['NAXIS1'] xlen = flat[0].header['NAXIS1']
ylen = 601 ylen = 601
i = self.chip.rowID - 1 i = self.chip.rowID - 1
j = self.chip.colID - 1 j = self.chip.colID - 1
x = np.linspace(0, self.chip.npix_x, int(xlen/6.)) x = np.linspace(0, self.chip.npix_x, int(xlen/6.))
y = np.linspace(0, self.chip.npix_y, int(ylen/5.)) y = np.linspace(0, self.chip.npix_y, int(ylen/5.))
xx, yy = np.meshgrid(x, y) xx, yy = np.meshgrid(x, y)
a1 = flat[0].data[int(ylen*i/5.):int(ylen*i/5.)+int(ylen/5.), a1 = flat[0].data[int(ylen*i/5.):int(ylen*i/5.)+int(ylen/5.),
int(xlen*j/6.):int(xlen*j/6.)+int(xlen/6.)] int(xlen*j/6.):int(xlen*j/6.)+int(xlen/6.)]
# z = np.sin((xx+yy+xx**2+yy**2)) # z = np.sin((xx+yy+xx**2+yy**2))
# fInterp = interp2d(xx, yy, z, kind='linear') # fInterp = interp2d(xx, yy, z, kind='linear')
X_ = np.hstack((xx.flatten()[:, None], yy.flatten()[:, None])) X_ = np.hstack((xx.flatten()[:, None], yy.flatten()[:, None]))
Z_ = a1.flatten() Z_ = a1.flatten()
n_x = np.arange(0, self.chip.npix_x, 1) n_x = np.arange(0, self.chip.npix_x, 1)
n_y = np.arange(0, self.chip.npix_y, 1) n_y = np.arange(0, self.chip.npix_y, 1)
M, N = np.meshgrid(n_x, n_y) M, N = np.meshgrid(n_x, n_y)
x_seg_len = 4
U = griddata(X_, Z_, ( y_seg_len = 8
M[0:self.chip.npix_y, 0:self.chip.npix_x], x_seg = int(self.chip.npix_x/x_seg_len)
N[0:self.chip.npix_y, 0:self.chip.npix_x]), y_seg = int(self.chip.npix_y/y_seg_len)
method='linear') U = np.zeros([self.chip.npix_y, self.chip.npix_x], dtype=np.float32)
for y_seg_i in np.arange(y_seg_len):
for x_seg_i in np.arange(x_seg_len):
U[y_seg_i*y_seg:(y_seg_i+1)*y_seg, x_seg_i*x_seg:(x_seg_i+1)*x_seg] = griddata(X_, Z_, (M[y_seg_i*y_seg:(y_seg_i+1)*y_seg, x_seg_i*x_seg:(x_seg_i+1)*x_seg], N[y_seg_i*y_seg:(y_seg_i+1)*y_seg, x_seg_i*x_seg:(x_seg_i+1)*x_seg]), method='linear')
# U = griddata(X_, Z_, (
# M[0:self.chip.npix_y, 0:self.chip.npix_x],
# N[0:self.chip.npix_y, 0:self.chip.npix_x]),
# method='nearest').astype(np.float32)
U = U/np.mean(U) U = U/np.mean(U)
flatImage = U*fluxLED[led_type]*1000 flatImage = U
if LED_Img_flag:
flatImage = U*fluxLED[led_type]*1000
gc.collect() gc.collect()
return flatImage return flatImage
......
...@@ -33,7 +33,7 @@ class Galaxy(MockObject): ...@@ -33,7 +33,7 @@ class Galaxy(MockObject):
raise ValueError( raise ValueError(
"!!!The number of PSF profiles and the number of bandpasses must be equal.") "!!!The number of PSF profiles and the number of bandpasses must be equal.")
objs = [] objs = []
if nphotons_tot == None: if nphotons_tot is None:
nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime) nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime)
# print("nphotons_tot = ", nphotons_tot) # print("nphotons_tot = ", nphotons_tot)
...@@ -92,7 +92,7 @@ class Galaxy(MockObject): ...@@ -92,7 +92,7 @@ class Galaxy(MockObject):
return final return final
def drawObj_multiband(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, exptime=150., fd_shear=None): def drawObj_multiband(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, exptime=150., fd_shear=None):
if nphotons_tot == None: if nphotons_tot is None:
nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime) nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime)
# print("nphotons_tot = ", nphotons_tot) # print("nphotons_tot = ", nphotons_tot)
...@@ -115,7 +115,7 @@ class Galaxy(MockObject): ...@@ -115,7 +115,7 @@ class Galaxy(MockObject):
# Set Galsim Parameters # Set Galsim Parameters
if self.getMagFilter(filt) <= 15 and (not big_galaxy): if self.getMagFilter(filt) <= 15 and (not big_galaxy):
folding_threshold = 5.e-4 folding_threshold = 5.e-8
else: else:
folding_threshold = 5.e-3 folding_threshold = 5.e-3
gsp = galsim.GSParams(folding_threshold=folding_threshold) gsp = galsim.GSParams(folding_threshold=folding_threshold)
...@@ -170,8 +170,11 @@ class Galaxy(MockObject): ...@@ -170,8 +170,11 @@ class Galaxy(MockObject):
# print("nphotons_sub-band_%d = %.2f"%(i, nphotons)) # print("nphotons_sub-band_%d = %.2f"%(i, nphotons))
# Get PSF model # Get PSF model
EXTRA = False
if self.getMagFilter(filt) <= filt.mag_saturation-1.:
EXTRA = True
psf, pos_shear = psf_model.get_PSF( psf, pos_shear = psf_model.get_PSF(
chip=chip, pos_img=pos_img, bandpass=bandpass, folding_threshold=folding_threshold) chip=chip, pos_img=pos_img, bandpass=bandpass, folding_threshold=folding_threshold, extrapolate=EXTRA)
if self.bfrac == 0: if self.bfrac == 0:
gal_temp = disk gal_temp = disk
...@@ -325,23 +328,28 @@ class Galaxy(MockObject): ...@@ -325,23 +328,28 @@ class Galaxy(MockObject):
galImg_List = [] galImg_List = []
try: try:
pos_img_local = [0,0] pos_img_local = [0, 0]
x_start = chip.x_cen/chip.pix_size - chip.npix_x / 2. x_start = chip.x_cen/chip.pix_size - chip.npix_x / 2.
y_start = chip.y_cen/chip.pix_size - chip.npix_y / 2. y_start = chip.y_cen/chip.pix_size - chip.npix_y / 2.
pos_img_local[0] = pos_img.x - x_start pos_img_local[0] = pos_img.x - x_start
pos_img_local[1] = pos_img.y - y_start pos_img_local[1] = pos_img.y - y_start
nnx = 0 nnx = 0
nny = 0 nny = 0
for order in ["A","B"]: for order in ["A", "B"]:
EXTRA = False
if self.getMagFilter(filt) <= filt.mag_saturation-2.:
EXTRA = True
psf, pos_shear = psf_model.get_PSF( psf, pos_shear = psf_model.get_PSF(
chip, pos_img_local=pos_img_local, bandNo=i+1, galsimGSObject=True, g_order=order, grating_split_pos=grating_split_pos) chip, pos_img_local=pos_img_local, bandNo=i+1, galsimGSObject=True, g_order=order, grating_split_pos=grating_split_pos, extrapolate=EXTRA, ngg=3072)
star_p = galsim.Convolve(psf, gal) star_p = galsim.Convolve(psf, gal)
if nnx == 0: if nnx == 0:
galImg = star_p.drawImage(wcs=chip_wcs_local, offset=offset) galImg = star_p.drawImage(
wcs=chip_wcs_local, offset=offset, method='no_pixel')
nnx = galImg.xmax - galImg.xmin + 1 nnx = galImg.xmax - galImg.xmin + 1
nny = galImg.ymax - galImg.ymin + 1 nny = galImg.ymax - galImg.ymin + 1
else: else:
galImg = star_p.drawImage(nx = nnx, ny = nny, wcs=chip_wcs_local, offset=offset) galImg = star_p.drawImage(
nx=nnx, ny=nny, wcs=chip_wcs_local, offset=offset, method='no_pixel')
galImg.setOrigin(0, 0) galImg.setOrigin(0, 0)
# n1 = np.sum(np.isinf(galImg.array)) # n1 = np.sum(np.isinf(galImg.array))
# n2 = np.sum(np.isnan(galImg.array)) # n2 = np.sum(np.isnan(galImg.array))
...@@ -351,19 +359,23 @@ class Galaxy(MockObject): ...@@ -351,19 +359,23 @@ class Galaxy(MockObject):
# ERROR happens # ERROR happens
return 2, pos_shear return 2, pos_shear
galImg_List.append(galImg) galImg_List.append(galImg)
for order in ["C","D","E"]: for order in ["C", "D", "E"]:
galImg_List.append(galImg) galImg_List.append(galImg)
except: except:
psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img) try:
star_p = galsim.Convolve(psf, gal) psf, pos_shear = psf_model.get_PSF(
galImg = star_p.drawImage(wcs=chip_wcs_local, offset=offset) chip=chip, pos_img=pos_img)
galImg.setOrigin(0, 0) star_p = galsim.Convolve(psf, gal)
if np.sum(np.isnan(galImg.array)) > 0: galImg = star_p.drawImage(
# ERROR happens wcs=chip_wcs_local, offset=offset)
return 2, pos_shear galImg.setOrigin(0, 0)
for order in ["A","B","C","D","E"]: if np.sum(np.isnan(galImg.array)) > 0:
galImg_List.append(galImg) # ERROR happens
return 2, pos_shear
for order in ["A", "B", "C", "D", "E"]:
galImg_List.append(galImg)
except Exception as e:
continue
# starImg = gal.drawImage( # starImg = gal.drawImage(
# wcs=chip_wcs_local, offset=offset, method='real_space') # wcs=chip_wcs_local, offset=offset, method='real_space')
...@@ -378,7 +390,7 @@ class Galaxy(MockObject): ...@@ -378,7 +390,7 @@ class Galaxy(MockObject):
subSlitPos = int(grating_split_pos_chip - gal_origin[1]) subSlitPos = int(grating_split_pos_chip - gal_origin[1])
# part img disperse # part img disperse
star_p1s=[] star_p1s = []
for galImg in galImg_List: for galImg in galImg_List:
subImg_p1 = galImg.array[:, 0:subSlitPos] subImg_p1 = galImg.array[:, 0:subSlitPos]
...@@ -397,17 +409,18 @@ class Galaxy(MockObject): ...@@ -397,17 +409,18 @@ class Galaxy(MockObject):
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp_p1, chip=chip, xOrderSigPlus = xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp_p1, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p1, chip=chip, pos_img_local=[xcenter_p1, ycenter_p1], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p1, chip=chip, pos_img_local=[xcenter_p1, ycenter_p1],
# psf_model=psf_model, bandNo=i + 1, # psf_model=psf_model, bandNo=i + 1,
# grating_split_pos=grating_split_pos, # grating_split_pos=grating_split_pos,
# local_wcs=chip_wcs_local, pos_img=pos_img) # local_wcs=chip_wcs_local, pos_img=pos_img)
star_p2s=[] star_p2s = []
for galImg in galImg_List: for galImg in galImg_List:
subImg_p2 = galImg.array[:, subImg_p2 = galImg.array[:,
subSlitPos:galImg.array.shape[1]] subSlitPos:galImg.array.shape[1]]
star_p2 = galsim.Image(subImg_p2) star_p2 = galsim.Image(subImg_p2)
star_p2.setOrigin(0, 0) star_p2.setOrigin(0, 0)
star_p2s.append(star_p2) star_p2s.append(star_p2)
...@@ -423,7 +436,8 @@ class Galaxy(MockObject): ...@@ -423,7 +436,8 @@ class Galaxy(MockObject):
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp_p2, chip=chip, xOrderSigPlus = xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp_p2, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p2, chip=chip, pos_img_local=[xcenter_p2, ycenter_p2], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p2, chip=chip, pos_img_local=[xcenter_p2, ycenter_p2],
# psf_model=psf_model, bandNo=i + 1, # psf_model=psf_model, bandNo=i + 1,
# grating_split_pos=grating_split_pos, # grating_split_pos=grating_split_pos,
...@@ -439,7 +453,8 @@ class Galaxy(MockObject): ...@@ -439,7 +453,8 @@ class Galaxy(MockObject):
conf=chip.sls_conf[1], conf=chip.sls_conf[1],
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus = xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal],
# psf_model=psf_model, bandNo=i + 1, # psf_model=psf_model, bandNo=i + 1,
# grating_split_pos=grating_split_pos, # grating_split_pos=grating_split_pos,
...@@ -453,7 +468,8 @@ class Galaxy(MockObject): ...@@ -453,7 +468,8 @@ class Galaxy(MockObject):
conf=chip.sls_conf[0], conf=chip.sls_conf[0],
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus = xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal],
# psf_model=psf_model, bandNo=i + 1, # psf_model=psf_model, bandNo=i + 1,
# grating_split_pos=grating_split_pos, # grating_split_pos=grating_split_pos,
...@@ -465,7 +481,7 @@ class Galaxy(MockObject): ...@@ -465,7 +481,7 @@ class Galaxy(MockObject):
return 1, pos_shear return 1, pos_shear
def getGSObj(self, psf, g1=0, g2=0, flux=None, filt=None, tel=None, exptime=150.): def getGSObj(self, psf, g1=0, g2=0, flux=None, filt=None, tel=None, exptime=150.):
if flux == None: if flux is None:
flux = self.getElectronFluxFilt(filt, tel, exptime) flux = self.getElectronFluxFilt(filt, tel, exptime)
disk = galsim.Sersic(n=self.disk_sersic_idx, disk = galsim.Sersic(n=self.disk_sersic_idx,
half_light_radius=self.hlr_disk, flux=1.0) half_light_radius=self.hlr_disk, flux=1.0)
......
...@@ -78,6 +78,8 @@ class MockObject(object): ...@@ -78,6 +78,8 @@ class MockObject(object):
(self.posImg.x, self.posImg.y), flush=True) (self.posImg.x, self.posImg.y), flush=True)
self.posImg, self.fd_shear = fdmodel.get_distorted( self.posImg, self.fd_shear = fdmodel.get_distorted(
chip=chip, pos_img=self.posImg) chip=chip, pos_img=self.posImg)
if self.posImg is None:
return None, None, None, None, None
if verbose: if verbose:
print("After field distortion:\n") print("After field distortion:\n")
print("x = %.2f, y = %.2f\n" % print("x = %.2f, y = %.2f\n" %
...@@ -108,7 +110,7 @@ class MockObject(object): ...@@ -108,7 +110,7 @@ class MockObject(object):
def drawObj_multiband(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, def drawObj_multiband(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0,
exptime=150., fd_shear=None): exptime=150., fd_shear=None):
if nphotons_tot == None: if nphotons_tot is None:
nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime) nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime)
# print("nphotons_tot = ", nphotons_tot) # print("nphotons_tot = ", nphotons_tot)
...@@ -122,7 +124,7 @@ class MockObject(object): ...@@ -122,7 +124,7 @@ class MockObject(object):
return 2, None return 2, None
# Set Galsim Parameters # Set Galsim Parameters
if self.getMagFilter(filt) <= 15: if self.getMagFilter(filt) <= 15:
folding_threshold = 5.e-4 folding_threshold = 5.e-8
else: else:
folding_threshold = 5.e-3 folding_threshold = 5.e-3
gsp = galsim.GSParams(folding_threshold=folding_threshold) gsp = galsim.GSParams(folding_threshold=folding_threshold)
...@@ -160,14 +162,17 @@ class MockObject(object): ...@@ -160,14 +162,17 @@ class MockObject(object):
# print("nphotons_sub-band_%d = %.2f"%(i, nphotons)) # print("nphotons_sub-band_%d = %.2f"%(i, nphotons))
# Get PSF model # Get PSF model
EXTRA = False
if self.getMagFilter(filt) <= filt.mag_saturation-1.:
EXTRA = True
psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img, bandpass=bandpass, psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img, bandpass=bandpass,
folding_threshold=folding_threshold) folding_threshold=folding_threshold, extrapolate=EXTRA)
# star = galsim.DeltaFunction(gsparams=gsp) # star = galsim.DeltaFunction(gsparams=gsp)
# star = star.withFlux(nphotons) # star = star.withFlux(nphotons)
# star = galsim.Convolve(psf, star) # star = galsim.Convolve(psf, star)
star = psf.withFlux(nphotons) star = psf.withFlux(nphotons)
stamp = star.drawImage(wcs=chip_wcs_local, offset=offset) stamp = star.drawImage(method='no_pixel', wcs=chip_wcs_local, offset=offset)
if np.sum(np.isnan(stamp.array)) > 0: if np.sum(np.isnan(stamp.array)) > 0:
continue continue
stamp.setCenter(x_nominal, y_nominal) stamp.setCenter(x_nominal, y_nominal)
...@@ -235,14 +240,14 @@ class MockObject(object): ...@@ -235,14 +240,14 @@ class MockObject(object):
if chip.slsPSFOptim: if chip.slsPSFOptim:
for k, v in spec_orders.items(): for k, v in spec_orders.items():
img_s = v[0] img_s = v[0]
nan_ids = np.isnan(img_s) nan_ids = np.isnan(img_s)
if img_s[nan_ids].shape[0] > 0: if img_s[nan_ids].shape[0] > 0:
img_s[nan_ids] = 0 img_s[nan_ids] = 0
print("DEBUG: specImg nan num is", img_s[nan_ids].shape[0]) print("DEBUG: specImg nan num is", img_s[nan_ids].shape[0])
######################################################### #########################################################
# img_s, orig_off = convolveImg(img_s, psf_img_m) # img_s, orig_off = convolveImg(img_s, psf_img_m)
orig_off = [0,0] orig_off = [0, 0]
origin_order_x = v[1] - orig_off[0] origin_order_x = v[1] - orig_off[0]
origin_order_y = v[2] - orig_off[1] origin_order_y = v[2] - orig_off[1]
...@@ -257,15 +262,18 @@ class MockObject(object): ...@@ -257,15 +262,18 @@ class MockObject(object):
continue continue
# orders = {'A': 'order1', 'B': 'order0', 'C': 'order2', 'D': 'order-1', 'E': 'order-2'} # orders = {'A': 'order1', 'B': 'order0', 'C': 'order2', 'D': 'order-1', 'E': 'order-2'}
orders = {'A': 'order1', 'B': 'order0', 'C': 'order0', 'D': 'order0', 'E': 'order0'} orders = {'A': 'order1', 'B': 'order0',
'C': 'order0', 'D': 'order0', 'E': 'order0'}
gratingN = chip_utils.getChipSLSGratingID(chip.chipID)[1] gratingN = chip_utils.getChipSLSGratingID(chip.chipID)[1]
if pos_img_local[0] < grating_split_pos: if pos_img_local[0] < grating_split_pos:
gratingN = chip_utils.getChipSLSGratingID(chip.chipID)[0] gratingN = chip_utils.getChipSLSGratingID(chip.chipID)[0]
chip.img_stack[gratingN][orders[k]]['w' + str(bandNo)].setOrigin(0, 0) chip.img_stack[gratingN][orders[k]
chip.img_stack[gratingN][orders[k]]['w' + str(bandNo)][bounds] = chip.img_stack[gratingN][orders[k]]['w' + str(bandNo)][bounds] + specImg[bounds] ]['w' + str(bandNo)].setOrigin(0, 0)
chip.img_stack[gratingN][orders[k]]['w' + str(bandNo)].setOrigin(chip.bound.xmin, chip.bound.ymin) chip.img_stack[gratingN][orders[k]]['w' + str(
bandNo)][bounds] = chip.img_stack[gratingN][orders[k]]['w' + str(bandNo)][bounds] + specImg[bounds]
chip.img_stack[gratingN][orders[k]]['w' +
str(bandNo)].setOrigin(chip.bound.xmin, chip.bound.ymin)
else: else:
for k, v in spec_orders.items(): for k, v in spec_orders.items():
...@@ -313,11 +321,11 @@ class MockObject(object): ...@@ -313,11 +321,11 @@ class MockObject(object):
# specImg.wcs = local_wcs # specImg.wcs = local_wcs
# specImg.setOrigin(origin_order_x, origin_order_y) # specImg.setOrigin(origin_order_x, origin_order_y)
# print('DEBUG: BEGIN -----------',bandNo,k) # print('DEBUG: BEGIN -----------',bandNo,k)
img_s = v[0] img_s = v[0]
nan_ids = np.isnan(img_s) nan_ids = np.isnan(img_s)
if img_s[nan_ids].shape[0] > 0: if img_s[nan_ids].shape[0] > 0:
img_s[nan_ids] = 0 img_s[nan_ids] = 0
...@@ -330,9 +338,11 @@ class MockObject(object): ...@@ -330,9 +338,11 @@ class MockObject(object):
specImg.wcs = local_wcs specImg.wcs = local_wcs
specImg.setOrigin(origin_order_x, origin_order_y) specImg.setOrigin(origin_order_x, origin_order_y)
try: try:
specImg = psf_model.get_PSF_AND_convolve_withsubImg(chip, cutImg=specImg, pos_img_local=pos_img_local, bandNo=bandNo, g_order=k, grating_split_pos=grating_split_pos) specImg = psf_model.get_PSF_AND_convolve_withsubImg(
chip, cutImg=specImg, pos_img_local=pos_img_local, bandNo=bandNo, g_order=k, grating_split_pos=grating_split_pos)
except: except:
psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img) psf, pos_shear = psf_model.get_PSF(
chip=chip, pos_img=pos_img)
psf_img = psf.drawImage(nx=100, ny=100, wcs=local_wcs) psf_img = psf.drawImage(nx=100, ny=100, wcs=local_wcs)
...@@ -376,7 +386,7 @@ class MockObject(object): ...@@ -376,7 +386,7 @@ class MockObject(object):
sedNormFactor = 1. sedNormFactor = 1.
if self.getMagFilter(filt) <= 15: if self.getMagFilter(filt) <= 15:
folding_threshold = 5.e-4 folding_threshold = 5.e-8
else: else:
folding_threshold = 5.e-3 folding_threshold = 5.e-3
gsp = galsim.GSParams(folding_threshold=folding_threshold) gsp = galsim.GSParams(folding_threshold=folding_threshold)
...@@ -425,45 +435,51 @@ class MockObject(object): ...@@ -425,45 +435,51 @@ class MockObject(object):
# star = galsim.DeltaFunction(gsparams=gsp) # star = galsim.DeltaFunction(gsparams=gsp)
# star = star.withFlux(tel.pupil_area * exptime) # star = star.withFlux(tel.pupil_area * exptime)
#psf list :["A","B","C","D","E"] # psf list :["A","B","C","D","E"]
starImg_List = [] starImg_List = []
try: try:
pos_img_local = [0,0] pos_img_local = [0, 0]
x_start = chip.x_cen/chip.pix_size - chip.npix_x / 2. x_start = chip.x_cen/chip.pix_size - chip.npix_x / 2.
y_start = chip.y_cen/chip.pix_size - chip.npix_y / 2. y_start = chip.y_cen/chip.pix_size - chip.npix_y / 2.
pos_img_local[0] = pos_img.x - x_start pos_img_local[0] = pos_img.x - x_start
pos_img_local[1] = pos_img.y - y_start pos_img_local[1] = pos_img.y - y_start
nnx = 0 nnx = 0
nny = 0 nny = 0
for order in ["A","B"]: for order in ["A", "B"]:
EXTRA = False
if self.getMagFilter(filt) <= filt.mag_saturation-2.:
EXTRA = True
nnx = 2048
nny = 2048
psf, pos_shear = psf_model.get_PSF( psf, pos_shear = psf_model.get_PSF(
chip, pos_img_local=pos_img_local, bandNo=i+1, galsimGSObject=True, g_order=order, grating_split_pos=grating_split_pos) chip, pos_img_local=pos_img_local, bandNo=i+1, galsimGSObject=True, g_order=order, grating_split_pos=grating_split_pos, extrapolate=EXTRA, ngg=3072)
# star_p = galsim.Convolve(psf, star) # star_p = galsim.Convolve(psf, star)
star_p = psf.withFlux(tel.pupil_area * exptime) star_p = psf.withFlux(tel.pupil_area * exptime)
if nnx == 0: if nnx == 0:
starImg = star_p.drawImage(wcs=chip_wcs_local, offset=offset) starImg = star_p.drawImage(
wcs=chip_wcs_local, offset=offset, method='no_pixel')
nnx = starImg.xmax - starImg.xmin + 1 nnx = starImg.xmax - starImg.xmin + 1
nny = starImg.ymax - starImg.ymin + 1 nny = starImg.ymax - starImg.ymin + 1
else: else:
starImg = star_p.drawImage(nx = nnx, ny = nny, wcs=chip_wcs_local, offset=offset) starImg = star_p.drawImage(
nx=nnx, ny=nny, wcs=chip_wcs_local, offset=offset, method='no_pixel')
# n1 = np.sum(np.isinf(starImg.array)) # n1 = np.sum(np.isinf(starImg.array))
# n2 = np.sum(np.isnan(starImg.array)) # n2 = np.sum(np.isnan(starImg.array))
# if n1>0 or n2 > 0: # if n1>0 or n2 > 0:
# print("DEBUG: MockObject, inf:%d, nan:%d"%(n1, n2)) # print("DEBUG: MockObject, inf:%d, nan:%d"%(n1, n2))
starImg.setOrigin(0, 0) starImg.setOrigin(0, 0)
starImg_List.append(starImg) starImg_List.append(starImg)
for order in ["C","D","E"]: for order in ["C", "D", "E"]:
starImg_List.append(starImg) starImg_List.append(starImg)
except: except:
psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img) psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img)
# star_p = galsim.Convolve(psf, star) # star_p = galsim.Convolve(psf, star)
star_p = psf.withFlux(tel.pupil_area * exptime) star_p = psf.withFlux(tel.pupil_area * exptime)
starImg = star_p.drawImage(wcs=chip_wcs_local, offset=offset) starImg = star_p.drawImage(wcs=chip_wcs_local, offset=offset, method='no_pixel')
starImg.setOrigin(0, 0) starImg.setOrigin(0, 0)
for order in ["A","B","C","D","E"]: for order in ["A", "B", "C", "D", "E"]:
starImg_List.append(starImg) starImg_List.append(starImg)
# psf_tmp = galsim.Gaussian(sigma=0.002) # psf_tmp = galsim.Gaussian(sigma=0.002)
# star = galsim.Convolve(psf_tmp, star) # star = galsim.Convolve(psf_tmp, star)
...@@ -472,14 +488,14 @@ class MockObject(object): ...@@ -472,14 +488,14 @@ class MockObject(object):
origin_star = [y_nominal - (starImg.center.y - starImg.ymin), origin_star = [y_nominal - (starImg.center.y - starImg.ymin),
x_nominal - (starImg.center.x - starImg.xmin)] x_nominal - (starImg.center.x - starImg.xmin)]
gal_origin = [origin_star[0], origin_star[1]] gal_origin = [origin_star[0], origin_star[1]]
gal_end = [origin_star[0] + starImg.array.shape[0] - gal_end = [origin_star[0] + starImg.array.shape[0] -
1, origin_star[1] + starImg.array.shape[1] - 1] 1, origin_star[1] + starImg.array.shape[1] - 1]
if gal_origin[1] < grating_split_pos_chip < gal_end[1]: if gal_origin[1] < grating_split_pos_chip < gal_end[1]:
subSlitPos = int(grating_split_pos_chip - gal_origin[1]) subSlitPos = int(grating_split_pos_chip - gal_origin[1])
# part img disperse # part img disperse
star_p1s=[] star_p1s = []
for starImg in starImg_List: for starImg in starImg_List:
subImg_p1 = starImg.array[:, 0:subSlitPos] subImg_p1 = starImg.array[:, 0:subSlitPos]
...@@ -498,17 +514,17 @@ class MockObject(object): ...@@ -498,17 +514,17 @@ class MockObject(object):
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp_p1, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp_p1, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p1, chip=chip, pos_img_local=[xcenter_p1, ycenter_p1], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p1, chip=chip, pos_img_local=[xcenter_p1, ycenter_p1],
# psf_model=psf_model, bandNo=i+1, grating_split_pos=grating_split_pos, # psf_model=psf_model, bandNo=i+1, grating_split_pos=grating_split_pos,
# local_wcs=chip_wcs_local, pos_img=pos_img) # local_wcs=chip_wcs_local, pos_img=pos_img)
star_p2s = []
star_p2s=[]
for starImg in starImg_List: for starImg in starImg_List:
subImg_p2 = starImg.array[:, subImg_p2 = starImg.array[:,
subSlitPos:starImg.array.shape[1]] subSlitPos:starImg.array.shape[1]]
star_p2 = galsim.Image(subImg_p2) star_p2 = galsim.Image(subImg_p2)
star_p2.setOrigin(0, 0) star_p2.setOrigin(0, 0)
star_p2s.append(star_p2) star_p2s.append(star_p2)
...@@ -524,7 +540,8 @@ class MockObject(object): ...@@ -524,7 +540,8 @@ class MockObject(object):
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp_p2, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp_p2, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p2, chip=chip, pos_img_local=[xcenter_p2, ycenter_p2], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp_p2, chip=chip, pos_img_local=[xcenter_p2, ycenter_p2],
# psf_model=psf_model, bandNo=i + 1, grating_split_pos=grating_split_pos, # psf_model=psf_model, bandNo=i + 1, grating_split_pos=grating_split_pos,
# local_wcs=chip_wcs_local, pos_img=pos_img) # local_wcs=chip_wcs_local, pos_img=pos_img)
...@@ -539,7 +556,8 @@ class MockObject(object): ...@@ -539,7 +556,8 @@ class MockObject(object):
conf=chip.sls_conf[1], conf=chip.sls_conf[1],
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal],
# psf_model=psf_model, bandNo=i + 1, grating_split_pos=grating_split_pos, # psf_model=psf_model, bandNo=i + 1, grating_split_pos=grating_split_pos,
# local_wcs=chip_wcs_local, pos_img=pos_img) # local_wcs=chip_wcs_local, pos_img=pos_img)
...@@ -552,7 +570,8 @@ class MockObject(object): ...@@ -552,7 +570,8 @@ class MockObject(object):
conf=chip.sls_conf[0], conf=chip.sls_conf[0],
isAlongY=0, isAlongY=0,
flat_cube=flat_cube) flat_cube=flat_cube)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local) self.addSLStoChipImage(
sdp=sdp, chip=chip, xOrderSigPlus=xOrderSigPlus, local_wcs=chip_wcs_local)
# pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal], # pos_shear = self.addSLStoChipImageWithPSF(sdp=sdp, chip=chip, pos_img_local=[x_nominal, y_nominal],
# psf_model=psf_model, bandNo=i + 1, grating_split_pos=grating_split_pos, # psf_model=psf_model, bandNo=i + 1, grating_split_pos=grating_split_pos,
# local_wcs=chip_wcs_local, pos_img=pos_img) # local_wcs=chip_wcs_local, pos_img=pos_img)
...@@ -572,7 +591,7 @@ class MockObject(object): ...@@ -572,7 +591,7 @@ class MockObject(object):
def drawObj_PSF(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, def drawObj_PSF(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0,
exptime=150., fd_shear=None, chip_output=None): exptime=150., fd_shear=None, chip_output=None):
if nphotons_tot == None: if nphotons_tot is None:
nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime) nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime)
# print("nphotons_tot = ", nphotons_tot) # print("nphotons_tot = ", nphotons_tot)
...@@ -641,7 +660,7 @@ class MockObject(object): ...@@ -641,7 +660,7 @@ class MockObject(object):
os.makedirs(fn, exist_ok=True) os.makedirs(fn, exist_ok=True)
fn = fn + "/ccd_{:}".format(chip.chipID) + \ fn = fn + "/ccd_{:}".format(chip.chipID) + \
"_psf_"+str(self.param['id'])+".fits" "_psf_"+str(self.param['id'])+".fits"
if fn != None: if fn is not None:
if os.path.exists(fn): if os.path.exists(fn):
os.remove(fn) os.remove(fn)
hdu = fitsio.PrimaryHDU() hdu = fitsio.PrimaryHDU()
......
...@@ -98,7 +98,7 @@ class Quasar(MockObject): ...@@ -98,7 +98,7 @@ class Quasar(MockObject):
del self.sed del self.sed
def getGSObj(self, psf, g1=0, g2=0, flux=None, filt=None, tel=None, exptime=150.): def getGSObj(self, psf, g1=0, g2=0, flux=None, filt=None, tel=None, exptime=150.):
if flux == None: if flux is None:
flux = self.getElectronFluxFilt(filt, tel, exptime) flux = self.getElectronFluxFilt(filt, tel, exptime)
qso = galsim.Gaussian(sigma=1.e-8, flux=1.) qso = galsim.Gaussian(sigma=1.e-8, flux=1.)
qso = qso.withFlux(flux) qso = qso.withFlux(flux)
......
from .SpecDisperser import * from .SpecDisperser import *
from .disperse_c import disperse, interp from .disperse_c import disperse, interp
\ No newline at end of file
...@@ -8,16 +8,16 @@ import numpy ...@@ -8,16 +8,16 @@ import numpy
extensions = [ extensions = [
Extension("disperse_c.interp", ["disperse_c/interp.pyx"], Extension("disperse_c.interp", ["disperse_c/interp.pyx"],
include_dirs = [numpy.get_include()], include_dirs=[numpy.get_include()],
libraries=["m"]), libraries=["m"]),
Extension("disperse_c.disperse", ["disperse_c/disperse.pyx"], Extension("disperse_c.disperse", ["disperse_c/disperse.pyx"],
include_dirs = [numpy.get_include()], include_dirs=[numpy.get_include()],
libraries=["m"]), libraries=["m"]),
] ]
setup( setup(
name = "slssim_disperse", name="slssim_disperse",
ext_modules = cythonize(extensions), ext_modules=cythonize(extensions),
) )
...@@ -21,7 +21,7 @@ class Stamp(MockObject): ...@@ -21,7 +21,7 @@ class Stamp(MockObject):
del self.sed del self.sed
def drawObj_multiband(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, exptime=150., fd_shear=None): def drawObj_multiband(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, exptime=150., fd_shear=None):
if nphotons_tot == None: if nphotons_tot is None:
nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime) nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime)
try: try:
...@@ -92,7 +92,7 @@ class Stamp(MockObject): ...@@ -92,7 +92,7 @@ class Stamp(MockObject):
else: else:
gal = gal + gal_temp gal = gal + gal_temp
stamp = gal.drawImage(wcs=chip_wcs_local, offset=offset) stamp = gal.drawImage(method='no_pixel', wcs=chip_wcs_local, offset=offset)
if np.sum(np.isnan(stamp.array)) > 0: if np.sum(np.isnan(stamp.array)) > 0:
# ERROR happens # ERROR happens
return 2, pos_shear return 2, pos_shear
......
...@@ -22,7 +22,7 @@ class Star(MockObject): ...@@ -22,7 +22,7 @@ class Star(MockObject):
del self.sed del self.sed
def getGSObj(self, psf, g1=0, g2=0, flux=None, filt=None, tel=None, exptime=150.): def getGSObj(self, psf, g1=0, g2=0, flux=None, filt=None, tel=None, exptime=150.):
if flux == None: if flux is None:
flux = self.getElectronFluxFilt(filt, tel, exptime) flux = self.getElectronFluxFilt(filt, tel, exptime)
# star = galsim.Gaussian(sigma=1.e-8, flux=1.) # star = galsim.Gaussian(sigma=1.e-8, flux=1.)
star = galsim.DeltaFunction() star = galsim.DeltaFunction()
...@@ -35,7 +35,7 @@ class Star(MockObject): ...@@ -35,7 +35,7 @@ class Star(MockObject):
raise ValueError( raise ValueError(
"!!!The number of PSF profiles and the number of bandpasses must be equal.") "!!!The number of PSF profiles and the number of bandpasses must be equal.")
objs = [] objs = []
if nphotons_tot == None: if nphotons_tot is None:
nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime) nphotons_tot = self.getElectronFluxFilt(filt, tel, exptime)
try: try:
......
...@@ -58,7 +58,7 @@ def seds(sedlistn, seddir="./", unit="A"): ...@@ -58,7 +58,7 @@ def seds(sedlistn, seddir="./", unit="A"):
read SEDs and save into Python dictionary read SEDs and save into Python dictionary
Parameters: Parameters:
sedlistn: filename of the sed template list and corresponding intrinsic sedlistn: filename of the sed template list and corresponding intrinsic
extinction model, see tmag_dz.py for detailes extinction model, see tmag_dz.py for detailes
listdir: directory of the list listdir: directory of the list
unit: wavelength unit of the input templates unit: wavelength unit of the input templates
...@@ -420,7 +420,7 @@ def sed2mag(mag_i, sedCat, filter_list, redshift=0.0, av=0.0, redden=0): ...@@ -420,7 +420,7 @@ def sed2mag(mag_i, sedCat, filter_list, redshift=0.0, av=0.0, redden=0):
def eObs(e1, e2, g1, g2): def eObs(e1, e2, g1, g2):
""" """
Calculate the sheared (observed) ellipticity using the Calculate the sheared (observed) ellipticity using the
intrinsic ellipticity and cosmic shear components. intrinsic ellipticity and cosmic shear components.
Parameters: Parameters:
...@@ -558,7 +558,7 @@ def getNormFactorForSpecWithABMAG(ABMag=20., spectrum=None, norm_thr=None, sWave ...@@ -558,7 +558,7 @@ def getNormFactorForSpecWithABMAG(ABMag=20., spectrum=None, norm_thr=None, sWave
eWave: the end of norm_thr eWave: the end of norm_thr
Return: Return:
the normalization factor flux of AB system(fix a band and magnitude ) /the flux of inpute spectrum(fix a band) the normalization factor flux of AB system(fix a band and magnitude ) /the flux of inpute spectrum(fix a band)
""" """
spectrumi = interpolate.interp1d(spectrum['WAVELENGTH'], spectrum['FLUX']) spectrumi = interpolate.interp1d(spectrum['WAVELENGTH'], spectrum['FLUX'])
norm_thri = interpolate.interp1d( norm_thri = interpolate.interp1d(
......
...@@ -62,7 +62,8 @@ class FieldDistortion(object): ...@@ -62,7 +62,8 @@ class FieldDistortion(object):
the distored position. the distored position.
""" """
if not self.isContainObj_FD(chip=chip, pos_img=pos_img): if not self.isContainObj_FD(chip=chip, pos_img=pos_img):
return galsim.PositionD(-1, -1), None # return galsim.PositionD(-1, -1), None
return None, None
if not img_rot: if not img_rot:
img_rot = np.radians(self.img_rot) img_rot = np.radians(self.img_rot)
else: else:
......
...@@ -50,7 +50,7 @@ class PSFGauss(PSFModel): ...@@ -50,7 +50,7 @@ class PSFGauss(PSFModel):
Return: the flux ratio Return: the flux ratio
""" """
if pscale == None: if pscale is None:
pscale = self.pix_size pscale = self.pix_size
gaussx = galsim.Gaussian(flux=1.0, sigma=sig) gaussx = galsim.Gaussian(flux=1.0, sigma=sig)
gaussImg = gaussx.drawImage(scale=pscale, method='no_pixel') gaussImg = gaussx.drawImage(scale=pscale, method='no_pixel')
...@@ -68,7 +68,7 @@ class PSFGauss(PSFModel): ...@@ -68,7 +68,7 @@ class PSFGauss(PSFModel):
return the fwhm in arcsec return the fwhm in arcsec
""" """
if pscale == None: if pscale is None:
pscale = self.pix_size pscale = self.pix_size
err = 1.0e-3 err = 1.0e-3
nxx = 100 nxx = 100
...@@ -122,4 +122,4 @@ class PSFGauss(PSFModel): ...@@ -122,4 +122,4 @@ class PSFGauss(PSFModel):
# return ell, beta, qr # return ell, beta, qr
PSFshear = galsim.Shear(e=ell, beta=beta*galsim.radians) PSFshear = galsim.Shear(e=ell, beta=beta*galsim.radians)
return self.psf.shear(PSFshear), PSFshear return self.psf.shear(PSFshear), PSFshear
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment