Commit 1908e835 authored by Xin Zhang's avatar Xin Zhang
Browse files

sls sim double direct dispersion

parent 0d59783b
...@@ -257,7 +257,7 @@ class Galaxy(MockObject): ...@@ -257,7 +257,7 @@ class Galaxy(MockObject):
return True, pos_shear return True, pos_shear
def drawObj_slitless(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, def drawObj_slitless(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0,
exptime=150., normFilter=None): exptime=150., normFilter=None, grating_split_pos=3685):
norm_thr_rang_ids = normFilter['SENSITIVITY'] > 0.001 norm_thr_rang_ids = normFilter['SENSITIVITY'] > 0.001
sedNormFactor = getNormFactorForSpecWithABMAG(ABMag=self.param['mag_use_normal'], spectrum=self.sed, sedNormFactor = getNormFactorForSpecWithABMAG(ABMag=self.param['mag_use_normal'], spectrum=self.sed,
...@@ -280,6 +280,7 @@ class Galaxy(MockObject): ...@@ -280,6 +280,7 @@ class Galaxy(MockObject):
gsp = galsim.GSParams(folding_threshold=folding_threshold) gsp = galsim.GSParams(folding_threshold=folding_threshold)
# nphotons_sum = 0 # nphotons_sum = 0
xOrderSigPlus = {'A':1.3909419820029296,'B':1.4760376591236062,'C':4.035447379743442,'D':5.5684364343742825,'E':16.260021029735388} xOrderSigPlus = {'A':1.3909419820029296,'B':1.4760376591236062,'C':4.035447379743442,'D':5.5684364343742825,'E':16.260021029735388}
grating_split_pos_chip = chip.bound.xmin + grating_split_pos
for i in range(len(bandpass_list)): for i in range(len(bandpass_list)):
bandpass = bandpass_list[i] bandpass = bandpass_list[i]
...@@ -302,47 +303,65 @@ class Galaxy(MockObject): ...@@ -302,47 +303,65 @@ class Galaxy(MockObject):
origin_star = [self.y_nominal - (starImg.center.y - starImg.ymin), origin_star = [self.y_nominal - (starImg.center.y - starImg.ymin),
self.x_nominal - (starImg.center.x - starImg.xmin)] self.x_nominal - (starImg.center.x - starImg.xmin)]
# print(self.y_nominal, starImg.center.y, starImg.ymin) gal_origin = [origin_star[0], origin_star[1]]
gal_end = [origin_star[0] + starImg.array.shape[0] - 1, origin_star[1] + starImg.array.shape[1] - 1]
if gal_origin[1] < grating_split_pos_chip < gal_end[1]:
subSlitPos = int(grating_split_pos_chip - gal_origin[1] + 1)
## part img disperse
sdp = SpecDisperser(orig_img=starImg, xcenter=self.x_nominal-chip.bound.xmin, subImg_p1 = starImg.array[:, 0:subSlitPos]
ycenter=self.y_nominal-chip.bound.ymin, origin=origin_star, star_p1 = galsim.Image(subImg_p1)
origin_p1 = origin_star
xcenter_p1 = min(self.x_nominal,grating_split_pos_chip-1) - chip.bound.xmin
ycenter_p1 = self.y_nominal-chip.bound.ymin
sdp_p1 = SpecDisperser(orig_img=star_p1, xcenter=xcenter_p1,
ycenter=ycenter_p1, origin=origin_p1,
tar_spec=normalSED, tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10, band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[1], conf=chip.sls_conf[0],
isAlongY=0) isAlongY=0)
spec_orders = sdp.compute_spec_orders() self.addSLStoChipImage(sdp=sdp_p1, chip=chip, xOrderSigPlus = xOrderSigPlus)
for k, v in spec_orders.items():
img_s = v[0]
img_s,orig_off = convolveGaussXorders(img_s,xOrderSigPlus[k])
origin_order_x = v[1]-orig_off
origin_order_y = v[2]-orig_off
specImg = galsim.ImageF(img_s)
photons = galsim.PhotonArray.makeFromImage(specImg)
photons.x += origin_order_x
photons.y += origin_order_y
xlen_imf = int(specImg.xmax - specImg.xmin + 1)
ylen_imf = int(specImg.ymax - specImg.ymin + 1)
stamp = galsim.ImageF(xlen_imf, ylen_imf)
stamp.wcs = self.localWCS
stamp.setOrigin(origin_order_x, origin_order_y)
bounds = stamp.bounds & chip.img.bounds
if bounds.area() == 0:
continue
stamp[bounds] = chip.img[bounds]
if not big_galaxy: subImg_p2 = starImg.array[:, subSlitPos+1:starImg.array.shape[1]]
chip.sensor.accumulate(photons, stamp) star_p2 = galsim.Image(subImg_p2)
else: origin_p2 = [origin_star[0], grating_split_pos_chip]
sensor = galsim.Sensor() xcenter_p2 = max(self.x_nominal, grating_split_pos_chip - 1) - chip.bound.xmin
sensor.accumulate(photons, stamp) ycenter_p2 = self.y_nominal - chip.bound.ymin
# chip.sensor.accumulate(photons, stamp) sdp_p2 = SpecDisperser(orig_img=star_p2, xcenter=xcenter_p2,
chip.img[bounds] = stamp[bounds] ycenter=ycenter_p2, origin=origin_p2,
del stamp tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[1],
isAlongY=0)
self.addSLStoChipImage(sdp=sdp_p2, chip=chip, xOrderSigPlus = xOrderSigPlus)
del sdp_p1
del sdp_p2
elif grating_split_pos_chip<=gal_origin[1]:
sdp = SpecDisperser(orig_img=starImg, xcenter=self.x_nominal - chip.bound.xmin,
ycenter=self.y_nominal - chip.bound.ymin, origin=origin_star,
tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[1],
isAlongY=0)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus = xOrderSigPlus)
del sdp del sdp
del spec_orders elif grating_split_pos_chip>=gal_end[1]:
sdp = SpecDisperser(orig_img=starImg, xcenter=self.x_nominal - chip.bound.xmin,
ycenter=self.y_nominal - chip.bound.ymin, origin=origin_star,
tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[0],
isAlongY=0)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus = xOrderSigPlus)
del sdp
# print(self.y_nominal, starImg.center.y, starImg.ymin)
del psf del psf
return True, pos_shear return True, pos_shear
......
...@@ -168,8 +168,36 @@ class MockObject(object): ...@@ -168,8 +168,36 @@ class MockObject(object):
del stamp del stamp
return True, pos_shear return True, pos_shear
def addSLStoChipImage(self, sdp = None, chip = None, xOrderSigPlus = None):
spec_orders = sdp.compute_spec_orders()
for k, v in spec_orders.items():
img_s = v[0]
img_s, orig_off = convolveGaussXorders(img_s, xOrderSigPlus[k])
origin_order_x = v[1] - orig_off
origin_order_y = v[2] - orig_off
specImg = galsim.ImageF(img_s)
photons = galsim.PhotonArray.makeFromImage(specImg)
photons.x += origin_order_x
photons.y += origin_order_y
xlen_imf = int(specImg.xmax - specImg.xmin + 1)
ylen_imf = int(specImg.ymax - specImg.ymin + 1)
stamp = galsim.ImageF(xlen_imf, ylen_imf)
stamp.wcs = self.localWCS
stamp.setOrigin(origin_order_x, origin_order_y)
bounds = stamp.bounds & chip.img.bounds
if bounds.area() == 0:
continue
stamp[bounds] = chip.img[bounds]
chip.sensor.accumulate(photons, stamp)
chip.img[bounds] = stamp[bounds]
del stamp
del spec_orders
def drawObj_slitless(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0, def drawObj_slitless(self, tel, pos_img, psf_model, bandpass_list, filt, chip, nphotons_tot=None, g1=0, g2=0,
exptime=150., normFilter=None): exptime=150., normFilter=None, grating_split_pos=3685):
norm_thr_rang_ids = normFilter['SENSITIVITY'] > 0.001 norm_thr_rang_ids = normFilter['SENSITIVITY'] > 0.001
sedNormFactor = getNormFactorForSpecWithABMAG(ABMag=self.param['mag_use_normal'], spectrum=self.sed, sedNormFactor = getNormFactorForSpecWithABMAG(ABMag=self.param['mag_use_normal'], spectrum=self.sed,
...@@ -192,6 +220,7 @@ class MockObject(object): ...@@ -192,6 +220,7 @@ class MockObject(object):
xOrderSigPlus = {'A':1.3909419820029296,'B':1.4760376591236062,'C':4.035447379743442,'D':5.5684364343742825,'E':16.260021029735388} xOrderSigPlus = {'A':1.3909419820029296,'B':1.4760376591236062,'C':4.035447379743442,'D':5.5684364343742825,'E':16.260021029735388}
grating_split_pos_chip = chip.bound.xmin + grating_split_pos
for i in range(len(bandpass_list)): for i in range(len(bandpass_list)):
bandpass = bandpass_list[i] bandpass = bandpass_list[i]
psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img, bandpass=bandpass, folding_threshold=folding_threshold) psf, pos_shear = psf_model.get_PSF(chip=chip, pos_img=pos_img, bandpass=bandpass, folding_threshold=folding_threshold)
...@@ -203,39 +232,63 @@ class MockObject(object): ...@@ -203,39 +232,63 @@ class MockObject(object):
origin_star = [self.y_nominal - (starImg.center.y - starImg.ymin), origin_star = [self.y_nominal - (starImg.center.y - starImg.ymin),
self.x_nominal - (starImg.center.x - starImg.xmin)] self.x_nominal - (starImg.center.x - starImg.xmin)]
sdp = SpecDisperser(orig_img=starImg, xcenter=self.x_nominal-chip.bound.xmin, gal_origin = [origin_star[0], origin_star[1]]
ycenter=self.y_nominal-chip.bound.ymin, origin=origin_star, gal_end = [origin_star[0] + starImg.array.shape[0] - 1, origin_star[1] + starImg.array.shape[1] - 1]
if gal_origin[1] < grating_split_pos_chip < gal_end[1]:
subSlitPos = int(grating_split_pos_chip - gal_origin[1] + 1)
## part img disperse
subImg_p1 = starImg.array[:, 0:subSlitPos]
star_p1 = galsim.Image(subImg_p1)
origin_p1 = origin_star
xcenter_p1 = min(self.x_nominal,grating_split_pos_chip-1) - chip.bound.xmin
ycenter_p1 = self.y_nominal-chip.bound.ymin
sdp_p1 = SpecDisperser(orig_img=star_p1, xcenter=xcenter_p1,
ycenter=ycenter_p1, origin=origin_p1,
tar_spec=normalSED, tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10, band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[1], conf=chip.sls_conf[0],
isAlongY=0) isAlongY=0)
spec_orders = sdp.compute_spec_orders() self.addSLStoChipImage(sdp=sdp_p1, chip=chip, xOrderSigPlus = xOrderSigPlus)
for k, v in spec_orders.items():
img_s = v[0]
img_s,orig_off = convolveGaussXorders(img_s,xOrderSigPlus[k])
origin_order_x = v[1]-orig_off
origin_order_y = v[2]-orig_off
specImg = galsim.ImageF(img_s)
photons = galsim.PhotonArray.makeFromImage(specImg)
photons.x += origin_order_x
photons.y += origin_order_y
xlen_imf = int(specImg.xmax - specImg.xmin + 1) subImg_p2 = starImg.array[:, subSlitPos+1:starImg.array.shape[1]]
ylen_imf = int(specImg.ymax - specImg.ymin + 1) star_p2 = galsim.Image(subImg_p2)
stamp = galsim.ImageF(xlen_imf, ylen_imf) origin_p2 = [origin_star[0], grating_split_pos_chip]
stamp.wcs = self.localWCS xcenter_p2 = max(self.x_nominal, grating_split_pos_chip - 1) - chip.bound.xmin
stamp.setOrigin(origin_order_x, origin_order_y) ycenter_p2 = self.y_nominal - chip.bound.ymin
bounds = stamp.bounds & chip.img.bounds sdp_p2 = SpecDisperser(orig_img=star_p2, xcenter=xcenter_p2,
if bounds.area() == 0: ycenter=ycenter_p2, origin=origin_p2,
continue tar_spec=normalSED,
stamp[bounds] = chip.img[bounds] band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
chip.sensor.accumulate(photons, stamp) conf=chip.sls_conf[1],
chip.img[bounds] = stamp[bounds] isAlongY=0)
del stamp
self.addSLStoChipImage(sdp=sdp_p2, chip=chip,xOrderSigPlus = xOrderSigPlus)
del sdp_p1
del sdp_p2
elif grating_split_pos_chip<=gal_origin[1]:
sdp = SpecDisperser(orig_img=starImg, xcenter=self.x_nominal - chip.bound.xmin,
ycenter=self.y_nominal - chip.bound.ymin, origin=origin_star,
tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[1],
isAlongY=0)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus = xOrderSigPlus)
del sdp
elif grating_split_pos_chip>=gal_end[1]:
sdp = SpecDisperser(orig_img=starImg, xcenter=self.x_nominal - chip.bound.xmin,
ycenter=self.y_nominal - chip.bound.ymin, origin=origin_star,
tar_spec=normalSED,
band_start=bandpass.blue_limit * 10, band_end=bandpass.red_limit * 10,
conf=chip.sls_conf[0],
isAlongY=0)
self.addSLStoChipImage(sdp=sdp, chip=chip, xOrderSigPlus = xOrderSigPlus)
del sdp del sdp
del spec_orders
del psf del psf
return True, pos_shear return True, pos_shear
......
...@@ -15,7 +15,7 @@ import os ...@@ -15,7 +15,7 @@ import os
###calculate sky map by sky SED ###calculate sky map by sky SED
def calculateSkyMap_split_g(xLen=9232, yLen=9126, blueLimit=4200, redLimit=6500, skyfn='param/skybackground/sky_emiss_hubble_50_50_A.dat', conf=[''], pixelSize=0.074, isAlongY=0, def calculateSkyMap_split_g(xLen=9232, yLen=9126, blueLimit=4200, redLimit=6500, skyfn='param/skybackground/sky_emiss_hubble_50_50_A.dat', conf=[''], pixelSize=0.074, isAlongY=0,
split_pos=100000): split_pos=3685):
skyMap = np.ones([yLen, xLen], dtype='float32') skyMap = np.ones([yLen, xLen], dtype='float32')
# for i in range(len(conf)): # for i in range(len(conf)):
......
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