Commit 36189a3e authored by JX's avatar JX 😵
Browse files

Merge remote-tracking branch 'origin/develop'

parents dd26d370 27646bc4
Pipeline #4509 passed with stage
in 0 seconds
...@@ -4,9 +4,9 @@ import os ...@@ -4,9 +4,9 @@ import os
import numpy as np import numpy as np
import gc import gc
import ObservationSim.Instrument._util as _util import observation_sim.instruments._util as _util
from ObservationSim.Instrument.FilterParam import FilterParam from observation_sim.instruments.FilterParam import FilterParam
from ObservationSim.Straylight import Straylight from observation_sim.sky_background import Straylight
try: try:
import importlib.resources as pkg_resources import importlib.resources as pkg_resources
...@@ -14,6 +14,7 @@ except ImportError: ...@@ -14,6 +14,7 @@ except ImportError:
# Try backported to PY<37 'importlib_resources' # Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources import importlib_resources as pkg_resources
class Filter(object): class Filter(object):
def __init__(self, filter_id, filter_type, filter_param, ccd_bandpass=None): def __init__(self, filter_id, filter_type, filter_param, ccd_bandpass=None):
self.filter_id = filter_id self.filter_id = filter_id
...@@ -52,57 +53,67 @@ class Filter(object): ...@@ -52,57 +53,67 @@ class Filter(object):
def _get_bandpasses(self, filter_dir=None, unit='A'): def _get_bandpasses(self, filter_dir=None, unit='A'):
if self.filter_id < 7: # Photometric if self.filter_id < 7: # Photometric
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + '.txt') as filter_file: with pkg_resources.files('observation_sim.instruments.data.filters').joinpath(self.filter_type.lower() + '.txt') as filter_file:
self.filter_bandpass = galsim.Bandpass(str(filter_file), wave_type=unit) self.filter_bandpass = galsim.Bandpass(
str(filter_file), wave_type=unit)
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + '.txt') as filter_file: with pkg_resources.path('observation_sim.instruments.data.filters', self.filter_type.lower() + '.txt') as filter_file:
self.filter_bandpass = galsim.Bandpass(str(filter_file), wave_type=unit) self.filter_bandpass = galsim.Bandpass(
str(filter_file), wave_type=unit)
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.throughputs').joinpath(self.filter_type.lower() + '_throughput.txt') as filter_file: with pkg_resources.files('observation_sim.instruments.data.throughputs').joinpath(self.filter_type.lower() + '_throughput.txt') as filter_file:
bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit) bandpass_full = galsim.Bandpass(
str(filter_file), wave_type=unit)
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.throughputs', self.filter_type.lower() + '_throughput.txt') as filter_file: with pkg_resources.path('observation_sim.instruments.data.throughputs', self.filter_type.lower() + '_throughput.txt') as filter_file:
bandpass_full = galsim.Bandpass(str(filter_file), wave_type=unit) bandpass_full = galsim.Bandpass(
str(filter_file), wave_type=unit)
# bandpass_full = bandpass_full * self.ccd_bandpass # bandpass_full = bandpass_full * self.ccd_bandpass
# Get sub-bandpasses # Get sub-bandpasses
bandpass_sub_list = [] bandpass_sub_list = []
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.files('observation_sim.instruments.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.path('observation_sim.instruments.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
for i in range(2, len(wave_points), 2): for i in range(2, len(wave_points), 2):
blim = max(float(wave_points[i-2])*0.1, bandpass_full.blue_limit) blim = max(float(wave_points[i-2])
* 0.1, bandpass_full.blue_limit)
rlim = min(float(wave_points[i])*0.1, bandpass_full.red_limit) rlim = min(float(wave_points[i])*0.1, bandpass_full.red_limit)
if blim >= rlim: if blim >= rlim:
continue continue
bandpass = bandpass_full.truncate(blue_limit=blim, red_limit=rlim) bandpass = bandpass_full.truncate(
blue_limit=blim, red_limit=rlim)
bandpass_sub_list.append(bandpass) bandpass_sub_list.append(bandpass)
# print("num of sub-bandpasses for filter#%d(%s) = "%(self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True) # print("num of sub-bandpasses for filter#%d(%s) = "%(self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True)
else: # Spectroscopic else: # Spectroscopic
sls_lamb = np.linspace(self.blue_limit, self.red_limit, 100) sls_lamb = np.linspace(self.blue_limit, self.red_limit, 100)
sls_flux = np.ones_like(sls_lamb) sls_flux = np.ones_like(sls_lamb)
con_spec = galsim.LookupTable(sls_lamb, sls_flux, interpolant='nearest') con_spec = galsim.LookupTable(
sls_lamb, sls_flux, interpolant='nearest')
bandpass_full = galsim.Bandpass(con_spec, wave_type=unit) bandpass_full = galsim.Bandpass(con_spec, wave_type=unit)
bandpass_sub_list = [] bandpass_sub_list = []
try: try:
with pkg_resources.files('ObservationSim.Instrument.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.files('observation_sim.instruments.data.filters').joinpath(self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
except AttributeError: except AttributeError:
with pkg_resources.path('ObservationSim.Instrument.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file: with pkg_resources.path('observation_sim.instruments.data.filters', self.filter_type.lower() + "_sub.list") as wave_bin_file:
wave_points = open(wave_bin_file).read().splitlines() wave_points = open(wave_bin_file).read().splitlines()
for i in range(2, len(wave_points), 2): for i in range(2, len(wave_points), 2):
blim = max(float(wave_points[i - 2]) * 0.1, bandpass_full.blue_limit) blim = max(float(wave_points[i - 2])
rlim = min(float(wave_points[i]) * 0.1, bandpass_full.red_limit) * 0.1, bandpass_full.blue_limit)
rlim = min(float(wave_points[i])
* 0.1, bandpass_full.red_limit)
if blim >= rlim: if blim >= rlim:
continue continue
bandpass = bandpass_full.truncate(blue_limit=blim, red_limit=rlim) bandpass = bandpass_full.truncate(
blue_limit=blim, red_limit=rlim)
bandpass_sub_list.append(bandpass) bandpass_sub_list.append(bandpass)
# print("num of sub-bandpasses for filter#%d(%s) = " % (self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True) # print("num of sub-bandpasses for filter#%d(%s) = " % (self.filter_id, self.filter_type), len(bandpass_sub_list), flush=True)
return bandpass_full, bandpass_sub_list return bandpass_full, bandpass_sub_list
def getPhotonE(self): def getPhotonE(self):
...@@ -111,17 +122,20 @@ class Filter(object): ...@@ -111,17 +122,20 @@ class Filter(object):
def getSkyNoise(self, exptime, gain=1.): def getSkyNoise(self, exptime, gain=1.):
return self.sky_background * exptime / gain return self.sky_background * exptime / gain
def setFilterStrayLightPixel(self,jtime = 2460843., sat_pos = np.array([0,0,0]), pointing_radec = np.array([0,0]), sun_pos = np.array([0,0,0])): def setFilterStrayLightPixel(self, jtime=2460843., sat_pos=np.array([0, 0, 0]), pointing_radec=np.array([0, 0]), sun_pos=np.array([0, 0, 0])):
sl = Straylight(jtime=jtime, sat_pos=sat_pos, pointing_radec=pointing_radec,sun_pos=sun_pos) sl = Straylight(jtime=jtime, sat_pos=sat_pos,
pointing_radec=pointing_radec, sun_pos=sun_pos)
if self.filter_type in _util.SPEC_FILTERS: if self.filter_type in _util.SPEC_FILTERS:
s_pix, spec = sl.calculateStrayLightGrating(grating = self.filter_type.upper()) s_pix, spec = sl.calculateStrayLightGrating(
if s_pix>0.8: grating=self.filter_type.upper())
if s_pix > 0.8:
s_pix = 0.8 s_pix = 0.8
self.sky_background = s_pix self.sky_background = s_pix
self.zodical_spec = spec self.zodical_spec = spec
elif self.filter_type.lower() in [x.lower for x in _util.PHOT_FILTERS]: elif self.filter_type.lower() in [x.lower for x in _util.PHOT_FILTERS]:
s_pix = sl.calculateStrayLightFilter(filter=self.filter_type.lower()) s_pix = sl.calculateStrayLightFilter(
if s_pix>1: filter=self.filter_type.lower())
if s_pix > 1:
s_pix = 1 s_pix = 1
self.sky_background = s_pix self.sky_background = s_pix
self.zodical_spec = None self.zodical_spec = None
...@@ -144,6 +158,8 @@ class Filter(object): ...@@ -144,6 +158,8 @@ class Filter(object):
full_well = 90000 full_well = 90000
throughput_file = self.filter_type.lower() + '_throughput.txt' throughput_file = self.filter_type.lower() + '_throughput.txt'
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) 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)
print("for filter %s: mag_limiting: %.3f, mag_saturation: %.3f"%(self.filter_type, self.mag_limiting, self.mag_saturation)) print("for filter %s: mag_limiting: %.3f, mag_saturation: %.3f" %
(self.filter_type, self.mag_limiting, self.mag_saturation))
import galsim import galsim
import numpy as np import numpy as np
class FilterParam(object): class FilterParam(object):
def __init__(self, filter_dir=None, filter_param=None): def __init__(self, filter_dir=None, filter_param=None):
self.param = self._filtParam(filter_param) self.param = self._filtParam(filter_param)
...@@ -14,7 +15,7 @@ class FilterParam(object): ...@@ -14,7 +15,7 @@ class FilterParam(object):
TODO: subject to change TODO: subject to change
Basic parameters of the CSSOS filters. Basic parameters of the CSSOS filters.
""" """
# filter parameters: name: # filter parameters: name:
# 1) effective wavelength # 1) effective wavelength
# 2) effective width # 2) effective width
# 3) blue end # 3) blue end
...@@ -26,19 +27,20 @@ class FilterParam(object): ...@@ -26,19 +27,20 @@ class FilterParam(object):
# 8) dim end magnitude # 8) dim end magnitude
if filter_param == None: if filter_param == None:
filtP = { filtP = {
"NUV": [2867.7, 705.4, 2470.0, 3270.0, 0.1404, 0.004, 15.7, 25.4], "NUV": [2867.7, 705.4, 2470.0, 3270.0, 0.1404, 0.004, 15.7, 25.4],
"u": [3601.1, 852.1, 3120.0, 4090.0, 0.2176, 0.021, 16.1, 25.4], "u": [3601.1, 852.1, 3120.0, 4090.0, 0.2176, 0.021, 16.1, 25.4],
"g": [4754.5, 1569.8, 3900.0, 5620.0, 0.4640, 0.164, 17.2, 26.3], "g": [4754.5, 1569.8, 3900.0, 5620.0, 0.4640, 0.164, 17.2, 26.3],
"r": [6199.8, 1481.2, 5370.0, 7030.0, 0.5040, 0.207, 17.0, 26.0], "r": [6199.8, 1481.2, 5370.0, 7030.0, 0.5040, 0.207, 17.0, 26.0],
"i": [7653.2, 1588.1, 6760.0, 8550.0, 0.4960, 0.212, 16.7, 25.9], "i": [7653.2, 1588.1, 6760.0, 8550.0, 0.4960, 0.212, 16.7, 25.9],
"z": [9600.6, 2490.5, 8240.0, 11000.0, 0.2000, 0.123, 15.7, 25.2], "z": [9600.6, 2490.5, 8240.0, 11000.0, 0.2000, 0.123, 15.7, 25.2],
"y": [10051.0, 1590.6, 9130.0, 11000.0, 0.0960, 0.037, 14.4, 24.4], "y": [10051.0, 1590.6, 9130.0, 11000.0, 0.0960, 0.037, 14.4, 24.4],
"FGS": [5000.0, 8000.0, 3000.0, 11000.0, 0.6500, 0.164, 0., 30.], # [TODO] # [TODO]
"FGS": [5000.0, 8000.0, 3000.0, 11000.0, 0.6500, 0.164, 0., 30.],
"GU": [0.0, 0.0, 2550.0, 4200.0, 1.0, 0.037, 14.0, 26.0],
"GV": [0.0, 0.0, 4000.0, 6500.0, 1.0, 0.037, 14.0, 26.0], "GU": [0.0, 0.0, 2550.0, 4200.0, 1.0, 0.037, 14.0, 26.0],
"GI": [0.0, 0.0, 6200.0, 10000.0, 1.0, 0.037, 14.0, 26.0], "GV": [0.0, 0.0, 4000.0, 6500.0, 1.0, 0.037, 14.0, 26.0],
} "GI": [0.0, 0.0, 6200.0, 10000.0, 1.0, 0.037, 14.0, 26.0],
}
else: else:
filtP = filter_param filtP = filter_param
...@@ -48,10 +50,10 @@ class FilterParam(object): ...@@ -48,10 +50,10 @@ class FilterParam(object):
""" """
read filters and save into Python dictionary read filters and save into Python dictionary
NOTE: the wavelength unit must be in "Angstrom" NOTE: the wavelength unit must be in "Angstrom"
Parameters: Parameters:
Same as function 'seds' Same as function 'seds'
Return: Return:
Same as function 'seds' Same as function 'seds'
""" """
...@@ -65,9 +67,10 @@ class FilterParam(object): ...@@ -65,9 +67,10 @@ class FilterParam(object):
ifiltn = filtdir+itype+".dat" ifiltn = filtdir+itype+".dat"
iblim = filtParams[itype][2] iblim = filtParams[itype][2]
irlim = filtParams[itype][3] irlim = filtParams[itype][3]
ifilt = galsim.Bandpass(ifiltn,wave_type=unit,blue_limit=iblim,red_limit=irlim) ifilt = galsim.Bandpass(
wave = ifilt.wave_list ifiltn, wave_type=unit, blue_limit=iblim, red_limit=irlim)
wave = ifilt.wave_list
ifilt = ifilt.func(wave) ifilt = ifilt.func(wave)
filts[itype] = np.transpose(np.array([wave*10.0,ifilt])) filts[itype] = np.transpose(np.array([wave*10.0, ifilt]))
return filtype, filts return filtype, filts
\ No newline at end of file
...@@ -40,18 +40,6 @@ class FocalPlane(object): ...@@ -40,18 +40,6 @@ class FocalPlane(object):
for i in range(1, 31): for i in range(1, 31):
self.ignore_chips.append(i) self.ignore_chips.append(i)
# if config is not None:
# self.nchip_x = config["nchip_x"]
# self.nchip_y = config["nchip_y"]
# self.npix_tot_x = config["npix_tot_x"]
# self.npix_tot_y = config["npix_tot_y"]
# self.npix_gap_x = config["npix_gap_x"]
# self.npix_gap_y = config["npix_gap_y"]
# if "chipLabelIDs" in config:
# self.chipLabelIDs = config["chipLabelIDs"]
# if "bad_chips" in config:
# self.bad_chips = config["bad_chips"]
# else:
self.nchip_x = 6 self.nchip_x = 6
self.nchip_y = 5 self.nchip_y = 5
self.npix_tot_x = 59516 self.npix_tot_x = 59516
...@@ -95,10 +83,6 @@ class FocalPlane(object): ...@@ -95,10 +83,6 @@ class FocalPlane(object):
if (xcen == None) or (ycen == None): if (xcen == None) or (ycen == None):
xcen = self.cen_pix_x xcen = self.cen_pix_x
ycen = self.cen_pix_y ycen = self.cen_pix_y
# dudx = -np.cos(img_rot.rad) * pix_scale
# dudy = -np.sin(img_rot.rad) * pix_scale
# dvdx = -np.sin(img_rot.rad) * pix_scale
# dvdy = +np.cos(img_rot.rad) * pix_scale
dudx = -np.cos(img_rot.rad) * pix_scale dudx = -np.cos(img_rot.rad) * pix_scale
dudy = +np.sin(img_rot.rad) * pix_scale dudy = +np.sin(img_rot.rad) * pix_scale
......
import numpy as np
try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
class Telescope(object):
def __init__(self, param=None, optEffCurve_path=None):
self.diameter = 2.0 # in unit of meter
if param is not None:
self.diameter = param["diameter"]
self.pupil_area = np.pi * (0.5 * self.diameter)**2
if optEffCurve_path is not None:
self.efficiency = self._get_efficiency(optEffCurve_path)
else:
try:
with pkg_resources.files('observation_sim.instruments.data').joinpath('mirror_ccdnote.txt') as optEffCurve_path:
self.efficiency = self._get_efficiency(optEffCurve_path)
except AttributeError:
with pkg_resources.path('observation_sim.instruments.data', 'mirror_ccdnote.txt') as optEffCurve_path:
self.efficiency = self._get_efficiency(optEffCurve_path)
def _get_efficiency(self, effCurve_path):
""" Read in the efficiency of optics
for each band
Parameters:
effCurve_path: the path for efficiency file
Returns:
opticsEff: a dictionary of efficiency (a scalar) for each band
"""
f = open(effCurve_path, 'r')
for _ in range(2):
header = f.readline()
iline = 0
opticsEff = {}
for line in f:
line = line.strip()
columns = line.split()
opticsEff[str(columns[0])] = float(columns[2])
f.close()
return opticsEff
...@@ -2,4 +2,4 @@ from .Telescope import Telescope ...@@ -2,4 +2,4 @@ from .Telescope import Telescope
from .Filter import Filter from .Filter import Filter
from .FilterParam import FilterParam from .FilterParam import FilterParam
from .FocalPlane import FocalPlane from .FocalPlane import FocalPlane
from .Chip import Chip from .chip import Chip
\ No newline at end of file
import numpy as np
import os
import math
from pylab import *
from scipy import interpolate
try:
import importlib.resources as pkg_resources
except ImportError:
# Try backported to PY<37 'importlib_resources'
import importlib_resources as pkg_resources
VC_A = 2.99792458e+18 # speed of light: A/s
VC_M = 2.99792458e+8 # speed of light: m/s
H_PLANK = 6.626196e-27 # Plank constant: erg s
ALL_FILTERS = ["NUV", "u", "g", "r", "i", "z", "y", "GU", "GV", "GI", "FGS"]
PHOT_FILTERS = ["NUV", "u", "g", 'r', 'i', 'z', 'y', 'FGS']
SPEC_FILTERS = ["GI", "GV", "GU"]
def rotate_conterclockwise(x0, y0, x, y, angle):
"""
Rotate a point counterclockwise by a given angle around a given origin.
The angle should be given in radians.
"""
angle = np.deg2rad(angle)
qx = x0 + np.cos(angle)*(x - x0) - np.sin(angle) * (y - y0)
qy = y0 + np.sin(angle)*(x - x0) + np.cos(angle) * (y - y0)
return qx, qy
def photonEnergy(lambd):
""" The energy of photon at a given wavelength
Parameter:
lambd: the wavelength in unit of Angstrom
Return:
eph: energy of photon in unit of erg
"""
nu = VC_A / lambd
eph = H_PLANK * nu
return eph
def calculateLimitMag(aperture=2.0, psf_fwhm=0.1969, pixelSize=0.074, pmRation=0.8, throughputFn='i_throughput.txt', readout=5.0, skyFn='sky_emiss_hubble_50_50_A.dat', darknoise=0.02, exTime=150, exNum=1, fw=90000):
'''
description:
param {*} aperture: unit m, default 2 m
param {*} psf_fwhm: psf fwhm, default 0.1969"
param {*} pixelSize: pixel size, default 0.074"
param {*} pmRation: the ratio of souce flux in the limit mag calculation
param {*} throughputFn: throuput file name
param {*} readout: unit, e-/pixel
param {*} skyFn: sky sed file name, average of hst, 'sky_emiss_hubble_50_50_A.dat'
param {*} darknoise: unit, e-/pixel/s
param {*} exTime: exposure time one time, default 150s
param {*} exNum: exposure number, defautl 1
param {*} fw, full well value( or saturation value),default 90000e-/pixel
return {*} limit mag and saturation mag
'''
try:
with pkg_resources.files('observation_sim.instruments.data.throughputs').joinpath(throughputFn) as data_file:
throughput_f = np.loadtxt(data_file)
except AttributeError:
with pkg_resources.path('observation_sim.instruments.data.throughputs', throughputFn) as data_file:
throughput_f = np.loadtxt(data_file)
thr_i = interpolate.interp1d(
throughput_f[:, 0]/10, throughput_f[:, 1]) # wavelength in anstrom
f_s = 200
f_e = 1100
delt_f = 0.5
data_num = int((f_e-f_s)/delt_f+1)
eff = np.zeros([data_num, 2])
eff[:, 0] = np.arange(f_s, f_e+delt_f, delt_f)
eff[:, 1] = thr_i(eff[:, 0])
wave = np.arange(f_s, f_e+delt_f, delt_f)
wavey = np.ones(wave.shape[0])
try:
with pkg_resources.files('observation_sim.instruments.data.throughputs').joinpath(skyFn) as data_file:
skydata = np.loadtxt(data_file)
except AttributeError:
with pkg_resources.path('observation_sim.instruments.data.throughputs', skyFn) as data_file:
skydata = np.loadtxt(data_file)
skydatai = interpolate.interp1d(skydata[:, 0]/10, skydata[:, 1]*10)
sky_data = np.zeros([data_num, 2])
sky_data[:, 0] = np.arange(f_s, f_e+delt_f, delt_f)
sky_data[:, 1] = skydatai(sky_data[:, 0])
flux_sky = trapz((sky_data[:, 1])*eff[:, 1], sky_data[:, 0])
skyPix = flux_sky*pixelSize*pixelSize*pi*(aperture*aperture/4)
# limit mag
r_pix = psf_fwhm*0.7618080243778568/pixelSize # radius RE80, pixel
cnum = math.pi * r_pix * r_pix
sn = 5
d = skyPix*exTime*exNum*cnum + darknoise * \
exTime*exNum*cnum+readout*readout*cnum*exNum
a = 1
b = -sn*sn
c = -sn*sn*d
flux = (-b+sqrt(b*b-4*a*c))/(2*a)/pmRation
limitMag = -2.5*log10(flux/(54799275581.04437 * trapz(wavey *
eff[:, 1]/wave, wave, 0.1)*exTime*exNum*pi*(aperture/2)*(aperture/2)))
# saturation mag
from astropy.modeling.models import Gaussian2D
m_size = int(20 * psf_fwhm/pixelSize)
if m_size % 2 == 0:
m_size + 1
m_cen = m_size//2
psf_sigma = psf_fwhm/2.355/pixelSize
gaussShape = Gaussian2D(1, m_cen, m_cen, psf_sigma, psf_sigma)
yp, xp = np.mgrid[0:m_size, 0:m_size]
psfMap = gaussShape(xp, yp)
maxRatio = np.amax(psfMap)/np.sum(psfMap)
# print(maxRatio)
flux_sat = fw/maxRatio*exNum
satMag = -2.5*log10(flux_sat/(54799275581.04437 * trapz(wavey *
eff[:, 1]/wave, wave, 0.1)*exTime*exNum*pi*(aperture/2)*(aperture/2)))
return limitMag, satMag
This diff is collapsed.
from ctypes import CDLL, POINTER, c_int, c_double,c_float,c_long,c_char_p from ctypes import CDLL, POINTER, c_int, c_double, c_float, c_long, c_char_p
from numpy.ctypeslib import ndpointer from numpy.ctypeslib import ndpointer
import numpy.ctypeslib as clb import numpy.ctypeslib as clb
import numpy as np import numpy as np
...@@ -10,12 +10,12 @@ import os ...@@ -10,12 +10,12 @@ import os
lib_path = os.path.dirname(os.path.realpath(__file__)) lib_path = os.path.dirname(os.path.realpath(__file__))
#lib_path += "/add_CTI.so" # lib_path += "/add_CTI.so"
lib_path += "/libmoduleCTI.so" lib_path += "/libmoduleCTI.so"
lib = CDLL(lib_path) lib = CDLL(lib_path)
CTI_simul = lib.__getattr__('CTI_simul') CTI_simul = lib.__getattr__('CTI_simul')
CTI_simul.argtypes = [POINTER(POINTER(c_int)),c_int,c_int,c_int,c_int,POINTER(c_float),POINTER(c_float),\ CTI_simul.argtypes = [POINTER(POINTER(c_int)), c_int, c_int, c_int, c_int, POINTER(c_float), POINTER(c_float),
c_float,c_float,c_float,c_int,POINTER(c_int),c_int,POINTER(POINTER(c_int))] c_float, c_float, c_float, c_int, POINTER(c_int), c_int, POINTER(POINTER(c_int))]
''' '''
get_trap_h = lib.__getattr__('save_trap_map') get_trap_h = lib.__getattr__('save_trap_map')
get_trap_h.argtypes = [POINTER(c_int), c_int, c_int, c_int, c_int, POINTER(c_float), c_float, c_float, c_char_p] get_trap_h.argtypes = [POINTER(c_int), c_int, c_int, c_int, c_int, POINTER(c_float), c_float, c_float, c_char_p]
...@@ -45,42 +45,50 @@ def bin2fits(bin_file,fits_dir,nsp,nx,ny,nmax): ...@@ -45,42 +45,50 @@ def bin2fits(bin_file,fits_dir,nsp,nx,ny,nmax):
datai[j+1,:,:] = h datai[j+1,:,:] = h
fits.writeto(fits_dir+"/trap_"+str(i+1)+".fits",datai,overwrite=True) fits.writeto(fits_dir+"/trap_"+str(i+1)+".fits",datai,overwrite=True)
''' '''
def numpy_matrix_to_int_pointer(arr): def numpy_matrix_to_int_pointer(arr):
int_pointer_array = (POINTER(c_int)*arr.shape[0])() int_pointer_array = (POINTER(c_int)*arr.shape[0])()
for i in range(arr.shape[0]): for i in range(arr.shape[0]):
arr1 = np.array(arr[i].copy().tolist(),dtype=np.int32) arr1 = np.array(arr[i].copy().tolist(), dtype=np.int32)
int_pointer_array[i] = np.ctypeslib.as_ctypes(arr1) int_pointer_array[i] = np.ctypeslib.as_ctypes(arr1)
return int_pointer_array return int_pointer_array
def pointer_to_numpy_matrix(arr_pointer,row,col):
arr = np.zeros((row,col))
def pointer_to_numpy_matrix(arr_pointer, row, col):
arr = np.zeros((row, col))
for i in range(row): for i in range(row):
for j in range(col): for j in range(col):
arr[i,j] = arr_pointer[i][j] arr[i, j] = arr_pointer[i][j]
return arr return arr
def CTI_sim(im,nx,ny,noverscan,nsp,nmax,beta,w,c,t,rho_trap,trap_seeds,release_seed=0):
def CTI_sim(im, nx, ny, noverscan, nsp, nmax, beta, w, c, t, rho_trap, trap_seeds, release_seed=0):
image = im.T image = im.T
nx_c,ny_c,noverscan_c,nsp_c,nmax_c = c_int(nx),c_int(ny),c_int(noverscan),c_int(nsp),c_int(nmax) nx_c, ny_c, noverscan_c, nsp_c, nmax_c = c_int(nx), c_int(
ny), c_int(noverscan), c_int(nsp), c_int(nmax)
ntotal = ny+noverscan ntotal = ny+noverscan
beta_c,w_c,c_c = c_float(beta),c_float(w),c_float(c) beta_c, w_c, c_c = c_float(beta), c_float(w), c_float(c)
t_p = np.ctypeslib.as_ctypes(t) t_p = np.ctypeslib.as_ctypes(t)
rho_trap_p = np.ctypeslib.as_ctypes(rho_trap) rho_trap_p = np.ctypeslib.as_ctypes(rho_trap)
image_p = numpy_matrix_to_int_pointer(image) image_p = numpy_matrix_to_int_pointer(image)
trap_seeds1 = trap_seeds.astype(np.int32) trap_seeds1 = trap_seeds.astype(np.int32)
trap_seeds_p = np.ctypeslib.as_ctypes(trap_seeds1) trap_seeds_p = np.ctypeslib.as_ctypes(trap_seeds1)
release_seed_c = c_int(release_seed) release_seed_c = c_int(release_seed)
image_cti = np.zeros((nx,ntotal)) image_cti = np.zeros((nx, ntotal))
image_cti = image_cti.astype(np.int32) image_cti = image_cti.astype(np.int32)
image_cti_p = numpy_matrix_to_int_pointer(image_cti) image_cti_p = numpy_matrix_to_int_pointer(image_cti)
print(datetime.now()) print(datetime.now())
CTI_simul(image_p,nx,ny,noverscan,nsp,rho_trap_p,t_p,beta,w,c,nmax,trap_seeds_p,release_seed_c,image_cti_p) CTI_simul(image_p, nx, ny, noverscan, nsp, rho_trap_p, t_p, beta,
w, c, nmax, trap_seeds_p, release_seed_c, image_cti_p)
print(datetime.now()) print(datetime.now())
image_cti_result = np.zeros((nx,ntotal)) image_cti_result = np.zeros((nx, ntotal))
for i in range(nx): for i in range(nx):
for j in range(ntotal): for j in range(ntotal):
image_cti_result[i,j] = image_cti_p[i][j] image_cti_result[i, j] = image_cti_p[i][j]
return image_cti_result.T return image_cti_result.T
""" """
if __name__ =='__main__': if __name__ =='__main__':
nx,ny,noverscan,nsp,nmax = 4608,4616,84,3,10 nx,ny,noverscan,nsp,nmax = 4608,4616,84,3,10
......
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