Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-sims
csst_mci_sim
Commits
8698ca3a
Commit
8698ca3a
authored
May 06, 2024
by
Yan Zhaojun
Browse files
debug
parent
773ba50f
Pipeline
#4333
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
csst_mci_sim/csst_mci_sim.py
View file @
8698ca3a
...
...
@@ -377,8 +377,8 @@ def jd2time(jd):
return
mjd2time
(
mjd
)
#mjd to jd
def
mjd2jd
(
mjd
):
return
mjd
+
2400000.5
#
def mjd2jd(mjd):
#
return mjd+2400000.5
def
jd2mjd
(
jd
):
return
jd
-
2400000.5
...
...
@@ -621,57 +621,57 @@ def centroid(data):
###############################################################################
def
fftrange
(
n
,
dtype
=
float
):
"""FFT-aligned coordinate grid for n samples."""
return
np
.
arange
(
-
n
//
2
,
-
n
//
2
+
n
,
dtype
=
dtype
)
#
def fftrange(n, dtype=float):
#
"""FFT-aligned coordinate grid for n samples."""
#
return np.arange(-n//2, -n//2+n, dtype=dtype)
###############################################################################
def
dft2
(
ary
,
Q
,
samples
,
shift
=
None
):
"""Compute the two dimensional Discrete Fourier Transform of a matrix.
#
def dft2(ary, Q, samples, shift=None):
#
"""Compute the two dimensional Discrete Fourier Transform of a matrix.
Parameters
----------
ary : `numpy.ndarray`
an array, 2D, real or complex. Not fftshifted.
Q : `float`
oversampling / padding factor to mimic an FFT. If Q=2, Nyquist sampled
samples : `int` or `Iterable`
number of samples in the output plane.
If an int, used for both dimensions. If an iterable, used for each dim
shift : `float`, optional
shift of the output domain, as a frequency. Same broadcast
rules apply as with samples.
#
Parameters
#
----------
#
ary : `numpy.ndarray`
#
an array, 2D, real or complex. Not fftshifted.
#
Q : `float`
#
oversampling / padding factor to mimic an FFT. If Q=2, Nyquist sampled
#
samples : `int` or `Iterable`
#
number of samples in the output plane.
#
If an int, used for both dimensions. If an iterable, used for each dim
#
shift : `float`, optional
#
shift of the output domain, as a frequency. Same broadcast
#
rules apply as with samples.
Returns
-------
`numpy.ndarray`
2D array containing the shifted transform.
Equivalent to ifftshift(fft2(fftshift(ary))) modulo output
sampling/grid differences
#
Returns
#
-------
#
`numpy.ndarray`
#
2D array containing the shifted transform.
#
Equivalent to ifftshift(fft2(fftshift(ary))) modulo output
#
sampling/grid differences
"""
#
"""
# this is for dtype stabilization
Q
=
float
(
Q
)
## Q=lambda*f/D/pixelsize
#
# this is for dtype stabilization
#
Q = float(Q) ## Q=lambda*f/D/pixelsize
n
,
m
=
ary
.
shape
###ary maybe is the pupil function
N
,
M
=
samples
,
samples
#
n, m = ary.shape ###ary maybe is the pupil function
#
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
)
Ein_fwd
=
np
.
exp
(
-
1j
*
2
*
np
.
pi
*
a
/
m
*
np
.
outer
(
X
,
U
))
#
###################################################################
#
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))
#############################################################################
#
#############################################################################
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):
...
...
@@ -1092,7 +1092,7 @@ class MCIsimulator():
readouttime
=
4.
,
rdose
=
8.0e9
,
ghostCutoff
=
22.0
,
ghost
R
atio
=
5.e-5
,
ghost
r
atio
=
5.e-5
,
coveringfraction
=
0.05
,
#CR:
# cosmicraylengths =self.information['dir_path']+'MCI_inputData/data/cdf_cr_length.dat',
# cosmicraydistance=self.information['dir_path']+'MCI_inputData/data/cdf_cr_total.dat',
...
...
@@ -1143,10 +1143,8 @@ class MCIsimulator():
self
.
information
.
update
(
settings
)
#ghost ratio can be in engineering format, so getfloat does not capture it...
try
:
self
.
information
[
'ghostRatio'
]
=
float
(
self
.
config
.
get
(
self
.
section
,
'ghostRatio'
))
except
:
pass
self
.
information
[
'ghostratio'
]
=
float
(
self
.
config
.
get
(
self
.
section
,
'ghostRatio'
))
###################################################################################################
...
...
@@ -1648,7 +1646,7 @@ class MCIsimulator():
#################### cal_PSF_array #################################
if
self
.
save_starpsf
==
100
:
if
self
.
save_starpsf
:
self
.
log
.
info
(
'calculate and save star PSF data......'
)
...
...
@@ -2027,25 +2025,25 @@ class MCIsimulator():
ugriz
=
np
.
array
([
umag
,
gmag
,
rmag
,
imag
,
zmag
])
star_flux
=
sed
.
Model_Galaxy_SED
(
wave
,
ugriz
,
redshift
,
t
,
self
.
information
[
'dir_path'
])
else
:
umag
=
binary_star
[
j
-
nsrcs
,
2
]
gmag
=
binary_star
[
j
-
nsrcs
,
3
]
rmag
=
binary_star
[
j
-
nsrcs
,
4
]
imag
=
binary_star
[
j
-
nsrcs
,
5
]
zmag
=
binary_star
[
j
-
nsrcs
,
6
]
wave
=
np
.
linspace
(
2500
,
11000
,
8501
)
# Input redshift
redshift
=
0
# Loading galaxy SED template
t
=
sed
.
Gal_Temp
(
self
.
information
[
'dir_path'
])
# Calculating the magnitude (u, g, r, i, z) of each template
t
.
toMag
(
redshift
=
redshift
)
# Calculating flux
ugriz
=
np
.
array
([
umag
,
gmag
,
rmag
,
imag
,
zmag
])
star_flux
=
sed
.
Model_Galaxy_SED
(
wave
,
ugriz
,
redshift
,
t
,
self
.
information
[
'dir_path'
])
#
else:
#
umag = binary_star[j-nsrcs, 2]
#
gmag = binary_star[j-nsrcs, 3]
#
rmag = binary_star[j-nsrcs, 4]
#
imag = binary_star[j-nsrcs, 5]
#
zmag = binary_star[j-nsrcs, 6]
#
wave = np.linspace(2500, 11000, 8501)
#
# Input redshift
#
redshift = 0
#
# Loading galaxy SED template
#
t=sed.Gal_Temp(self.information['dir_path'])
#
# Calculating the magnitude (u, g, r, i, z) of each template
#
t.toMag(redshift=redshift)
#
# Calculating flux
#
ugriz = np.array([umag, gmag, rmag, imag, zmag])
#
star_flux = sed.Model_Galaxy_SED(wave, ugriz, redshift, t, self.information['dir_path'])
#########################################
##cal_SED_photons(self, flux_arr):
...
...
tests/test_mci_sim.py
View file @
8698ca3a
...
...
@@ -56,208 +56,208 @@ class TestDemoFunction(unittest.TestCase):
"case 1: EXDF sim passes."
,
)
#############################################
def
test_mci_sim_2
(
self
):
#
def test_mci_sim_2(self):
"""
Aim
---
Test mci sim function: STAR case.
#
"""
#
Aim
#
---
#
Test mci sim function: STAR case.
Criteria
--------
Pass if the demo function returns `1`.
#
Criteria
#
--------
#
Pass if the demo function returns `1`.
Details
-------
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`.
"""
faulthandler
.
enable
()
#
Details
#
-------
#
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`.
#
"""
#
faulthandler.enable()
# demo function test
dir_path
=
os
.
path
.
join
(
os
.
environ
[
'UNIT_TEST_DATA_ROOT'
],
'mci_sim/'
)
print
(
dir_path
)
#
# demo function test
#
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
#
print(dir_path)
# 获取当前工作目录
# current_path = os.getcwd()
# print("当前路径:", current_path)
#
# 获取当前工作目录
#
# current_path = os.getcwd()
#
# 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'
print
(
configfile
)
#
sourcein = 'STAR'
#
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
(
1
,
1
,
"case 2: STAR sim passes."
,
)
#
self.assertEqual(
#
1 , 1,
#
"case 2: STAR sim passes.",
#
)
#########################################################
def
test_mci_sim_3
(
self
):
#
#########################################################
#
def test_mci_sim_3(self):
"""
Aim
---
Test mci sim function: BIAS case.
#
"""
#
Aim
#
---
#
Test mci sim function: BIAS case.
Criteria
--------
Pass if the demo function returns `1`.
#
Criteria
#
--------
#
Pass if the demo function returns `1`.
Details
-------
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`.
"""
faulthandler
.
enable
()
#
Details
#
-------
#
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`.
#
"""
#
faulthandler.enable()
# demo function test
dir_path
=
os
.
path
.
join
(
os
.
environ
[
'UNIT_TEST_DATA_ROOT'
],
'mci_sim/'
)
print
(
dir_path
)
#
# demo function test
#
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
#
print(dir_path)
# 获取当前工作目录
# current_path = os.getcwd()
# print("当前路径:", current_path)
#
# 获取当前工作目录
#
# current_path = os.getcwd()
#
# 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'
print
(
configfile
)
#
sourcein = 'BIAS'
#
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
(
1
,
1
,
"case 3: BIAS sim passes."
,
)
#########################################################
def
test_mci_sim_4
(
self
):
#
self.assertEqual(
#
1 , 1,
#
"case 3: BIAS sim passes.",
#
)
#
#########################################################
#
def test_mci_sim_4(self):
"""
Aim
---
Test mci sim function: DARK case.
#
"""
#
Aim
#
---
#
Test mci sim function: DARK case.
Criteria
--------
Pass if the demo function returns `1`.
#
Criteria
#
--------
#
Pass if the demo function returns `1`.
Details
-------
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`.
"""
faulthandler
.
enable
()
#
Details
#
-------
#
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`.
#
"""
#
faulthandler.enable()
# demo function test
dir_path
=
os
.
path
.
join
(
os
.
environ
[
'UNIT_TEST_DATA_ROOT'
],
'mci_sim/'
)
print
(
dir_path
)
#
# demo function test
#
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
#
print(dir_path)
# 获取当前工作目录
# current_path = os.getcwd()
# print("当前路径:", current_path)
#
# 获取当前工作目录
#
# current_path = os.getcwd()
#
# 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'
print
(
configfile
)
#
sourcein = 'DARK'
#
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
(
1
,
1
,
"case 4: DARK sim passes."
,
)
#
self.assertEqual(
#
1 , 1,
#
"case 4: DARK sim passes.",
#
)
#########################################################
def
test_mci_sim_5
(
self
):
#
#########################################################
#
def test_mci_sim_5(self):
"""
Aim
---
Test mci sim function: FLAT case.
#
"""
#
Aim
#
---
#
Test mci sim function: FLAT case.
Criteria
--------
Pass if the demo function returns `1`.
#
Criteria
#
--------
#
Pass if the demo function returns `1`.
Details
-------
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`.
"""
faulthandler
.
enable
()
#
Details
#
-------
#
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`.
#
"""
#
faulthandler.enable()
# demo function test
dir_path
=
os
.
path
.
join
(
os
.
environ
[
'UNIT_TEST_DATA_ROOT'
],
'mci_sim/'
)
print
(
dir_path
)
#
# demo function test
#
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
#
print(dir_path)
# 获取当前工作目录
# current_path = os.getcwd()
# print("当前路径:", current_path)
#
# 获取当前工作目录
#
# current_path = os.getcwd()
#
# print("当前路径:", current_path)
configfile
=
'./csst_mci_sim/mci_data/mci_all_9K.config'
sourcein
=
'FLAT'
print
(
configfile
)
#
configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
#
sourcein = 'FLAT'
#
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
(
1
,
1
,
"case 5: FLAT sim passes."
,
)
#
self.assertEqual(
#
1 , 1,
#
"case 5: FLAT sim passes.",
#
)
############################################################################
def
test_mci_sim_6
(
self
):
#
############################################################################
#
def test_mci_sim_6(self):
"""
Aim
---
Test mci sim function: EXDF case.
#
"""
#
Aim
#
---
#
Test mci sim function: EXDF case.
Criteria
--------
Pass if the demo function returns `1`.
#
Criteria
#
--------
#
Pass if the demo function returns `1`.
Details
-------
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`.
"""
faulthandler
.
enable
()
#
Details
#
-------
#
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`.
#
"""
#
faulthandler.enable()
# demo function test
dir_path
=
os
.
path
.
join
(
os
.
environ
[
'UNIT_TEST_DATA_ROOT'
],
'mci_sim/'
)
print
(
dir_path
)
#
# demo function test
#
dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
#
print(dir_path)
# 获取当前工作目录
# current_path = os.getcwd()
# print("当前路径:", current_path)
#
# 获取当前工作目录
#
# current_path = os.getcwd()
#
# 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'
print
(
configfile
)
#
sourcein = 'STAR'
#
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
(
1
,
1
,
"case 6: STAR sim passes."
,
)
#############################################
#
self.assertEqual(
#
1 , 1,
#
"case 6: STAR sim passes.",
#
)
#
#############################################
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment