Commit 8698ca3a authored by Yan Zhaojun's avatar Yan Zhaojun
Browse files

debug

parent 773ba50f
Pipeline #4333 failed with stage
in 0 seconds
...@@ -377,8 +377,8 @@ def jd2time(jd): ...@@ -377,8 +377,8 @@ def jd2time(jd):
return mjd2time(mjd) return mjd2time(mjd)
#mjd to jd #mjd to jd
def mjd2jd(mjd): # def mjd2jd(mjd):
return mjd+2400000.5 # return mjd+2400000.5
def jd2mjd(jd): def jd2mjd(jd):
return jd-2400000.5 return jd-2400000.5
...@@ -621,57 +621,57 @@ def centroid(data): ...@@ -621,57 +621,57 @@ def centroid(data):
############################################################################### ###############################################################################
def fftrange(n, dtype=float): # def fftrange(n, dtype=float):
"""FFT-aligned coordinate grid for n samples.""" # """FFT-aligned coordinate grid for n samples."""
return np.arange(-n//2, -n//2+n, dtype=dtype) # return np.arange(-n//2, -n//2+n, dtype=dtype)
############################################################################### ###############################################################################
def dft2(ary, Q, samples, shift=None): # def dft2(ary, Q, samples, shift=None):
"""Compute the two dimensional Discrete Fourier Transform of a matrix. # """Compute the two dimensional Discrete Fourier Transform of a matrix.
Parameters # Parameters
---------- # ----------
ary : `numpy.ndarray` # ary : `numpy.ndarray`
an array, 2D, real or complex. Not fftshifted. # an array, 2D, real or complex. Not fftshifted.
Q : `float` # Q : `float`
oversampling / padding factor to mimic an FFT. If Q=2, Nyquist sampled # oversampling / padding factor to mimic an FFT. If Q=2, Nyquist sampled
samples : `int` or `Iterable` # samples : `int` or `Iterable`
number of samples in the output plane. # number of samples in the output plane.
If an int, used for both dimensions. If an iterable, used for each dim # If an int, used for both dimensions. If an iterable, used for each dim
shift : `float`, optional # shift : `float`, optional
shift of the output domain, as a frequency. Same broadcast # shift of the output domain, as a frequency. Same broadcast
rules apply as with samples. # rules apply as with samples.
Returns # Returns
------- # -------
`numpy.ndarray` # `numpy.ndarray`
2D array containing the shifted transform. # 2D array containing the shifted transform.
Equivalent to ifftshift(fft2(fftshift(ary))) modulo output # Equivalent to ifftshift(fft2(fftshift(ary))) modulo output
sampling/grid differences # sampling/grid differences
""" # """
# this is for dtype stabilization # # this is for dtype stabilization
Q = float(Q) ## Q=lambda*f/D/pixelsize # Q = float(Q) ## Q=lambda*f/D/pixelsize
n, m = ary.shape ###ary maybe is the pupil function # n, m = ary.shape ###ary maybe is the pupil function
N, M = samples,samples # N, M = samples,samples
X, Y, U, V = (fftrange(n) for n in (m, n, M, N)) # X, Y, U, V = (fftrange(n) for n in (m, n, M, N))
a = 1 / Q # a = 1 / Q
################################################################### # ###################################################################
Eout_fwd = np.exp(-1j * 2 * np.pi * a / n * np.outer(Y, V).T) # Eout_fwd = np.exp(-1j * 2 * np.pi * a / n * np.outer(Y, V).T)
Ein_fwd = np.exp(-1j * 2 * np.pi * a / m * np.outer(X, U)) # Ein_fwd = np.exp(-1j * 2 * np.pi * a / m * np.outer(X, U))
############################################################################# # #############################################################################
out = Eout_fwd @ ary @ Ein_fwd #### ary is the input pupil function # out = Eout_fwd @ ary @ Ein_fwd #### ary is the input pupil function
return out # return out
############################################################################## ##############################################################################
# def idft2(ary, Q, samples, shift=None): # def idft2(ary, Q, samples, shift=None):
...@@ -1092,7 +1092,7 @@ class MCIsimulator(): ...@@ -1092,7 +1092,7 @@ class MCIsimulator():
readouttime=4., readouttime=4.,
rdose=8.0e9, rdose=8.0e9,
ghostCutoff=22.0, ghostCutoff=22.0,
ghostRatio=5.e-5, ghostratio=5.e-5,
coveringfraction=0.05, #CR: coveringfraction=0.05, #CR:
# cosmicraylengths =self.information['dir_path']+'MCI_inputData/data/cdf_cr_length.dat', # cosmicraylengths =self.information['dir_path']+'MCI_inputData/data/cdf_cr_length.dat',
# cosmicraydistance=self.information['dir_path']+'MCI_inputData/data/cdf_cr_total.dat', # cosmicraydistance=self.information['dir_path']+'MCI_inputData/data/cdf_cr_total.dat',
...@@ -1143,10 +1143,8 @@ class MCIsimulator(): ...@@ -1143,10 +1143,8 @@ class MCIsimulator():
self.information.update(settings) self.information.update(settings)
#ghost ratio can be in engineering format, so getfloat does not capture it... #ghost ratio can be in engineering format, so getfloat does not capture it...
try: self.information['ghostratio'] = float(self.config.get(self.section, 'ghostRatio'))
self.information['ghostRatio'] = float(self.config.get(self.section, 'ghostRatio'))
except:
pass
################################################################################################### ###################################################################################################
...@@ -1648,7 +1646,7 @@ class MCIsimulator(): ...@@ -1648,7 +1646,7 @@ class MCIsimulator():
#################### cal_PSF_array ################################# #################### cal_PSF_array #################################
if self.save_starpsf==100: if self.save_starpsf:
self.log.info('calculate and save star PSF data......') self.log.info('calculate and save star PSF data......')
...@@ -2027,25 +2025,25 @@ class MCIsimulator(): ...@@ -2027,25 +2025,25 @@ class MCIsimulator():
ugriz = np.array([umag, gmag, rmag, imag, zmag]) ugriz = np.array([umag, gmag, rmag, imag, zmag])
star_flux = sed.Model_Galaxy_SED(wave, ugriz, redshift, t, self.information['dir_path']) star_flux = sed.Model_Galaxy_SED(wave, ugriz, redshift, t, self.information['dir_path'])
else: # else:
umag = binary_star[j-nsrcs, 2] # umag = binary_star[j-nsrcs, 2]
gmag = binary_star[j-nsrcs, 3] # gmag = binary_star[j-nsrcs, 3]
rmag = binary_star[j-nsrcs, 4] # rmag = binary_star[j-nsrcs, 4]
imag = binary_star[j-nsrcs, 5] # imag = binary_star[j-nsrcs, 5]
zmag = binary_star[j-nsrcs, 6] # zmag = binary_star[j-nsrcs, 6]
wave = np.linspace(2500, 11000, 8501) # wave = np.linspace(2500, 11000, 8501)
# Input redshift # # Input redshift
redshift = 0 # redshift = 0
# Loading galaxy SED template # # Loading galaxy SED template
t=sed.Gal_Temp(self.information['dir_path']) # t=sed.Gal_Temp(self.information['dir_path'])
# Calculating the magnitude (u, g, r, i, z) of each template # # Calculating the magnitude (u, g, r, i, z) of each template
t.toMag(redshift=redshift) # t.toMag(redshift=redshift)
# Calculating flux # # Calculating flux
ugriz = np.array([umag, gmag, rmag, imag, zmag]) # ugriz = np.array([umag, gmag, rmag, imag, zmag])
star_flux = sed.Model_Galaxy_SED(wave, ugriz, redshift, t, self.information['dir_path']) # star_flux = sed.Model_Galaxy_SED(wave, ugriz, redshift, t, self.information['dir_path'])
######################################### #########################################
##cal_SED_photons(self, flux_arr): ##cal_SED_photons(self, flux_arr):
......
...@@ -56,208 +56,208 @@ class TestDemoFunction(unittest.TestCase): ...@@ -56,208 +56,208 @@ class TestDemoFunction(unittest.TestCase):
"case 1: EXDF sim passes.", "case 1: EXDF sim passes.",
) )
############################################# #############################################
def test_mci_sim_2(self): # def test_mci_sim_2(self):
""" # """
Aim # Aim
--- # ---
Test mci sim function: STAR case. # Test mci sim function: STAR case.
Criteria # Criteria
-------- # --------
Pass if the demo function returns `1`. # Pass if the demo function returns `1`.
Details # Details
------- # -------
The demo function returns the length of the input argument list. # The demo function returns the length of the input argument list.
This case aims to test whether the demo function returns `1` if input is `None`. # This case aims to test whether the demo function returns `1` if input is `None`.
""" # """
faulthandler.enable() # faulthandler.enable()
# demo function test # # demo function test
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/') # dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
print(dir_path) # print(dir_path)
# 获取当前工作目录 # # 获取当前工作目录
# current_path = os.getcwd() # # current_path = os.getcwd()
# print("当前路径:", current_path) # # print("当前路径:", current_path)
configfile = './csst_mci_sim/mci_data/mci_all_9K.config' # configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
sourcein = 'STAR' # sourcein = 'STAR'
print(configfile) # print(configfile)
debug=True # debug=True
csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1) # csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1)
self.assertEqual( # self.assertEqual(
1 , 1, # 1 , 1,
"case 2: STAR sim passes.", # "case 2: STAR sim passes.",
) # )
######################################################### # #########################################################
def test_mci_sim_3(self): # def test_mci_sim_3(self):
""" # """
Aim # Aim
--- # ---
Test mci sim function: BIAS case. # Test mci sim function: BIAS case.
Criteria # Criteria
-------- # --------
Pass if the demo function returns `1`. # Pass if the demo function returns `1`.
Details # Details
------- # -------
The demo function returns the length of the input argument list. # The demo function returns the length of the input argument list.
This case aims to test whether the demo function returns `1` if input is `None`. # This case aims to test whether the demo function returns `1` if input is `None`.
""" # """
faulthandler.enable() # faulthandler.enable()
# demo function test # # demo function test
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/') # dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
print(dir_path) # print(dir_path)
# 获取当前工作目录 # # 获取当前工作目录
# current_path = os.getcwd() # # current_path = os.getcwd()
# print("当前路径:", current_path) # # print("当前路径:", current_path)
configfile = './csst_mci_sim/mci_data/mci_all_9K.config' # configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
sourcein = 'BIAS' # sourcein = 'BIAS'
print(configfile) # print(configfile)
debug=True # debug=True
csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1) # csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1)
self.assertEqual( # self.assertEqual(
1 , 1, # 1 , 1,
"case 3: BIAS sim passes.", # "case 3: BIAS sim passes.",
) # )
######################################################### # #########################################################
def test_mci_sim_4(self): # def test_mci_sim_4(self):
""" # """
Aim # Aim
--- # ---
Test mci sim function: DARK case. # Test mci sim function: DARK case.
Criteria # Criteria
-------- # --------
Pass if the demo function returns `1`. # Pass if the demo function returns `1`.
Details # Details
------- # -------
The demo function returns the length of the input argument list. # The demo function returns the length of the input argument list.
This case aims to test whether the demo function returns `1` if input is `None`. # This case aims to test whether the demo function returns `1` if input is `None`.
""" # """
faulthandler.enable() # faulthandler.enable()
# demo function test # # demo function test
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/') # dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
print(dir_path) # print(dir_path)
# 获取当前工作目录 # # 获取当前工作目录
# current_path = os.getcwd() # # current_path = os.getcwd()
# print("当前路径:", current_path) # # print("当前路径:", current_path)
configfile = './csst_mci_sim/mci_data/mci_all_9K.config' # configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
sourcein = 'DARK' # sourcein = 'DARK'
print(configfile) # print(configfile)
debug=True # debug=True
csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1) # csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1)
self.assertEqual( # self.assertEqual(
1 , 1, # 1 , 1,
"case 4: DARK sim passes.", # "case 4: DARK sim passes.",
) # )
######################################################### # #########################################################
def test_mci_sim_5(self): # def test_mci_sim_5(self):
""" # """
Aim # Aim
--- # ---
Test mci sim function: FLAT case. # Test mci sim function: FLAT case.
Criteria # Criteria
-------- # --------
Pass if the demo function returns `1`. # Pass if the demo function returns `1`.
Details # Details
------- # -------
The demo function returns the length of the input argument list. # The demo function returns the length of the input argument list.
This case aims to test whether the demo function returns `1` if input is `None`. # This case aims to test whether the demo function returns `1` if input is `None`.
""" # """
faulthandler.enable() # faulthandler.enable()
# demo function test # # demo function test
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/') # dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
print(dir_path) # print(dir_path)
# 获取当前工作目录 # # 获取当前工作目录
# current_path = os.getcwd() # # current_path = os.getcwd()
# print("当前路径:", current_path) # # print("当前路径:", current_path)
configfile = './csst_mci_sim/mci_data/mci_all_9K.config' # configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
sourcein = 'FLAT' # sourcein = 'FLAT'
print(configfile) # print(configfile)
debug=True # debug=True
csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1) # csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1)
self.assertEqual( # self.assertEqual(
1 , 1, # 1 , 1,
"case 5: FLAT sim passes.", # "case 5: FLAT sim passes.",
) # )
############################################################################ # ############################################################################
def test_mci_sim_6(self): # def test_mci_sim_6(self):
""" # """
Aim # Aim
--- # ---
Test mci sim function: EXDF case. # Test mci sim function: EXDF case.
Criteria # Criteria
-------- # --------
Pass if the demo function returns `1`. # Pass if the demo function returns `1`.
Details # Details
------- # -------
The demo function returns the length of the input argument list. # The demo function returns the length of the input argument list.
This case aims to test whether the demo function returns `1` if input is `None`. # This case aims to test whether the demo function returns `1` if input is `None`.
""" # """
faulthandler.enable() # faulthandler.enable()
# demo function test # # demo function test
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/') # dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
print(dir_path) # print(dir_path)
# 获取当前工作目录 # # 获取当前工作目录
# current_path = os.getcwd() # # current_path = os.getcwd()
# print("当前路径:", current_path) # # print("当前路径:", current_path)
configfile = './csst_mci_sim/mci_data/mci_all_9K.config' # configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
sourcein = 'STAR' # sourcein = 'STAR'
print(configfile) # print(configfile)
debug=True # debug=True
csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1) # csst_mci_sim.runMCIsim(sourcein, configfile, dir_path, debug, 1)
self.assertEqual( # self.assertEqual(
1 , 1, # 1 , 1,
"case 6: STAR sim passes.", # "case 6: STAR sim passes.",
) # )
############################################# # #############################################
\ 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