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_cpic_sim
Commits
b7f8c4fa
Commit
b7f8c4fa
authored
Apr 20, 2024
by
GZhao
Browse files
V2.0 developing initial
parent
6a5baa03
Pipeline
#4230
failed with stage
in 0 seconds
Changes
42
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tests/test_optics.py
View file @
b7f8c4fa
import
unittest
from
csst_cpic_sim.target
import
star_photlam
from
csst_cpic_sim.optics
import
make_focus_image
,
focal_mask
,
filter_throughput
from
csst_cpic_sim.config
import
which_focalplane
,
S
import
time
from
CpicImgSim.target
import
star_photlam
from
CpicImgSim.optics
import
make_focus_image
,
focal_mask
,
filter_throughput
,
ideal_focus_image
from
CpicImgSim.config
import
which_focalplane
,
S
import
numpy
as
np
from
astropy.io
import
fits
def
gaussian_psf
(
band
,
spectrum
,
shape
,
error
=
0.1
):
psf_shape
=
[
shape
,
shape
]
xx
,
yy
=
np
.
mgrid
[
0
:
psf_shape
[
0
],
0
:
psf_shape
[
1
]]
center
=
np
.
array
([(
psf_shape
[
0
]
-
1
)
/
2
,
(
psf_shape
[
1
]
-
1
)
/
2
])
sigma
=
10
psf
=
np
.
exp
(
-
((
xx
-
center
[
0
])
**
2
+
(
yy
-
center
[
1
])
**
2
)
/
(
2
*
sigma
**
2
))
psf
=
psf
/
psf
.
sum
()
filter
=
filter_throughput
(
band
)
return
psf
*
(
spectrum
*
filter
).
integrate
()
class
TestOptics
(
unittest
.
TestCase
):
...
...
@@ -33,18 +50,6 @@ class TestOptics(unittest.TestCase):
def
test_make_focus_image
(
self
):
# test fuction to generate psf
def
gaussian_psf
(
band
,
spectrum
,
shape
,
error
=
0.1
):
psf_shape
=
[
shape
,
shape
]
xx
,
yy
=
np
.
mgrid
[
0
:
psf_shape
[
0
],
0
:
psf_shape
[
1
]]
center
=
np
.
array
([(
psf_shape
[
0
]
-
1
)
/
2
,
(
psf_shape
[
1
]
-
1
)
/
2
])
sigma
=
10
psf
=
np
.
exp
(
-
((
xx
-
center
[
0
])
**
2
+
(
yy
-
center
[
1
])
**
2
)
/
(
2
*
sigma
**
2
))
psf
=
psf
/
psf
.
sum
()
filter
=
filter_throughput
(
band
)
return
psf
*
(
spectrum
*
filter
).
integrate
()
# test targets
cstar
=
star_photlam
(
0
,
'F2V'
,
is_blackbody
=
True
)
...
...
@@ -85,4 +90,89 @@ class TestOptics(unittest.TestCase):
if
__name__
==
'__main__'
:
unittest
.
main
()
# unittest.main()
import
time
from
CpicImgSim.target
import
star_photlam
def
make_test_sub_image
(
size
,
shape
):
shape
=
np
.
array
([
shape
,
shape
])
sub_image
=
np
.
zeros
(
shape
)
center
=
(
shape
-
1
)
/
2
xx
,
yy
=
np
.
meshgrid
(
np
.
arange
(
shape
[
0
]),
np
.
arange
(
shape
[
1
]))
xx
=
xx
-
center
[
1
]
yy
=
yy
-
center
[
0
]
sub_image
[
np
.
abs
(
xx
)
<
0.6
]
=
1
sub_image
[
np
.
abs
(
yy
)
<
0.6
]
=
1
sub_image
[(
np
.
abs
(
xx
)
<
0.6
)
&
(
np
.
abs
(
yy
)
<
0.6
)]
=
0
sub_image
[
yy
>
7
]
=
0
sub_image
[
yy
<
-
3
]
=
0
sub_image
[
np
.
abs
(
xx
)
>
3
]
=
0
sub_image2
=
(
np
.
sqrt
(
xx
**
2
*
2
+
yy
**
2
)
<
size
).
astype
(
int
)
sub_image
=
sub_image2
*
(
1
-
sub_image
)
return
sub_image
def
test_ideal_focus_image
():
targets
=
[
[
0
,
0
,
star_photlam
(
2
,
'G2'
),
None
],
[
5
,
3
,
star_photlam
(
0
,
'G2'
),
make_test_sub_image
(
4
,
20
)],
[
8
,
0
,
star_photlam
(
-
5
,
'G2'
),
make_test_sub_image
(
10
,
100
)],
]
bandpass
=
S
.
Box
(
6000
,
500
)
start_time
=
time
.
time
()
foc
=
ideal_focus_image
(
bandpass
,
targets
,
0.0165
,
[
1024
,
1024
],
)
end_time
=
time
.
time
()
execution_time
=
end_time
-
start_time
fits
.
writeto
(
'foc.fits'
,
foc
,
overwrite
=
True
)
start_time
=
time
.
time
()
foc
=
ideal_focus_image
(
bandpass
,
targets
,
0.0165
,
[
1024
,
1024
],
rotation
=
30
,
)
end_time
=
time
.
time
()
execution_time
=
end_time
-
start_time
fits
.
writeto
(
'foc_rot30.fits'
,
foc
,
overwrite
=
True
)
def
test_convolve_psf
():
targets
=
[
[
0
,
0
,
star_photlam
(
2
,
'G2'
),
None
],
[
5
,
3
,
star_photlam
(
0
,
'G2'
),
make_test_sub_image
(
4
,
20
)],
[
8
,
0
,
star_photlam
(
-
5
,
'G2'
),
make_test_sub_image
(
10
,
100
)],
]
def
cov_psf_func
(
wave
,
error
=
0.1
):
psf_shape
=
[
1024
,
1024
]
xx
,
yy
=
np
.
mgrid
[
0
:
psf_shape
[
0
],
0
:
psf_shape
[
1
]]
center
=
np
.
array
([(
psf_shape
[
0
]
-
1
)
/
2
,
(
psf_shape
[
1
]
-
1
)
/
2
])
sigma
=
10
psf
=
np
.
exp
(
-
((
xx
-
center
[
0
])
**
2
+
(
yy
-
center
[
1
])
**
2
)
/
(
2
*
sigma
**
2
))
psf
=
psf
/
psf
.
sum
()
return
psf
from
CpicImgSim.optics
import
convolve_psf
img_final
=
convolve_psf
(
'f661'
,
targets
,
cov_psf_func
)
fits
.
writeto
(
'cov.fits'
,
img_final
,
overwrite
=
True
)
test_convolve_psf
()
# import matplotlib.pyplot as plt
# plt.imshow(make_test_sub_image(5, 6))
# plt.show()
tests/test_target.py
View file @
b7f8c4fa
import
os
import
unittest
from
csst_cpic_sim.target
import
_sptype2num
,
hybrid_albedo_spectrum
,
star_photlam
,
spectrum_generator
,
planet_contrast
,
extract_target_x_y
from
csst_cpic_sim.config
import
S
from
CpicImgSim.target
import
_sptype2num
,
hybrid_albedo_spectrum
,
star_photlam
,
spectrum_generator
from
CpicImgSim.target
import
AlbedoCat
,
bcc_spectrum
,
planet_contrast
,
extract_target_x_y
,
TargetOjbect
from
CpicImgSim.config
import
S
from
math
import
pi
tests_folder
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
class
TestTarget
(
unittest
.
TestCase
):
def
test_target_object
(
self
):
d_cstar
=
{
'magnitude'
:
5
,
'ra'
:
'120d'
,
'dec'
:
'40d'
,
'distance'
:
10
,
'sptype'
:
'F0III'
,
}
cstar
=
TargetOjbect
(
d_cstar
)
self
.
assertEqual
(
cstar
.
sp_model
==
'star'
)
d_cstar
[
'is_blackbody'
]
=
True
cstar
=
TargetOjbect
(
d_cstar
)
self
.
assertEqual
(
cstar
.
sp_model
==
'blackbody'
)
d_planet
=
{
'radius'
:
2
,
'pangle'
:
60
,
'coe_b'
:
0.3
,
'coe_r'
:
0.7
,
'separation'
:
0.5
,
'phase_angle'
:
90
,
}
old_planet
=
TargetOjbect
(
d_planet
,
cstar
=
cstar
,
sp_model
=
'planet'
)
self
.
assertEqual
(
old_planet
.
sp_model
==
'hybrid_planet'
)
d_planet
[
'sp_model'
]
=
'bcc_planet'
d_planet
[
'coe_cloud'
]
=
1
d_planet
[
'coe_metal'
]
=
0
old_planet
=
TargetOjbect
(
d_planet
,
cstar
=
cstar
,
sp_model
=
'planet'
)
self
.
assertEqual
(
old_planet
.
sp_model
==
'bcc_planet'
)
self
.
assertRaises
(
Warning
,
TargetOjbect
,
d_cstar
,
cstar
=
cstar
,
sp_model
=
'planet'
)
def
test_image_input
(
self
):
def
test_bcc_class
(
self
):
spectrum
=
AlbedoCat
(
90
,
1
,
0
)
self
.
assertIsInstance
(
spectrum
,
S
.
spectrum
.
SpectralElement
)
# import matplotlib.pyplot as plt
# plt.plot(spectrum.wave, spectrum.throughput)
# plt.show()
def
test_bcc_func
(
self
):
spectrum
=
bcc_spectrum
(
0.5
,
0.5
)
self
.
assertIsInstance
(
spectrum
,
S
.
spectrum
.
SpectralElement
)
self
.
assertEqual
(
spectrum
.
waveunits
.
name
,
'angstrom'
)
# import matplotlib.pyplot as plt
# plt.plot(spectrum.wave, spectrum.throughput)
# plt.xlabel(spectrum.waveunits)
# plt.show()
def
test_hybrid_albedo_spectrum
(
self
):
planet
=
hybrid_albedo_spectrum
(
0.5
,
1
)
self
.
assertIsInstance
(
planet
,
S
.
spectrum
.
SpectralElement
)
...
...
@@ -111,6 +171,15 @@ class TestTarget(unittest.TestCase):
'pangle'
:
60
,
'separation'
:
0.5
,
'phase_angle'
:
90
,
},
{
'radius'
:
2
,
'pangle'
:
60
,
'separation'
:
0.5
,
'phase_angle'
:
90
,
'model'
:
'bcc_planet'
,
'coe_c'
:
1
,
'coe_m'
:
0
,
}
]
}
...
...
Prev
1
2
3
Next
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