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
Liu Dezi
csst_msc_sim
Commits
75547899
Commit
75547899
authored
Nov 24, 2022
by
Zhang Xin
Browse files
debug & optimize disperse
parent
93a4abf7
Changes
2
Show whitespace changes
Inline
Side-by-side
ObservationSim/MockObject/SkybackgroundMap.py
View file @
75547899
...
@@ -10,6 +10,8 @@ import galsim
...
@@ -10,6 +10,8 @@ import galsim
import
os
import
os
import
time
try
:
try
:
import
importlib.resources
as
pkg_resources
import
importlib.resources
as
pkg_resources
except
ImportError
:
except
ImportError
:
...
@@ -95,7 +97,7 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -95,7 +97,7 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
tar_spec
=
spec
,
tar_spec
=
spec
,
band_start
=
tbstart
,
band_end
=
tbend
,
band_start
=
tbstart
,
band_end
=
tbend
,
conf
=
conf2
,
conf
=
conf2
,
flat_cube
=
flat_cub
e
,
ignoreBeam
=
[
'D'
,
'E'
])
flat_cube
=
Non
e
,
ignoreBeam
=
[
'D'
,
'E'
])
spec_orders
=
sdp
.
compute_spec_orders
()
spec_orders
=
sdp
.
compute_spec_orders
()
...
@@ -147,12 +149,13 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -147,12 +149,13 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
y_len
=
skyMap
.
shape
[
0
]
y_len
=
skyMap
.
shape
[
0
]
x_len
=
skyMap
.
shape
[
1
]
x_len
=
skyMap
.
shape
[
1
]
delt_x
=
500
delt_x
=
500
delt_y
=
500
delt_y
=
y_len
sub_y_start_arr
=
np
.
arange
(
0
,
y_len
,
delt_y
)
sub_y_start_arr
=
np
.
arange
(
0
,
y_len
,
delt_y
)
sub_y_end_arr
=
sub_y_start_arr
+
delt_y
sub_y_end_arr
=
sub_y_start_arr
+
delt_y
sub_y_end_arr
[
-
1
]
=
min
(
sub_y_end_arr
[
-
1
],
y_len
)
sub_y_end_arr
[
-
1
]
=
min
(
sub_y_end_arr
[
-
1
],
y_len
)
delt_x
=
split_pos
-
0
sub_x_start_arr
=
np
.
arange
(
0
,
split_pos
,
delt_x
)
sub_x_start_arr
=
np
.
arange
(
0
,
split_pos
,
delt_x
)
sub_x_end_arr
=
sub_x_start_arr
+
delt_x
sub_x_end_arr
=
sub_x_start_arr
+
delt_x
sub_x_end_arr
[
-
1
]
=
min
(
sub_x_end_arr
[
-
1
],
split_pos
)
sub_x_end_arr
[
-
1
]
=
min
(
sub_x_end_arr
[
-
1
],
split_pos
)
...
@@ -166,7 +169,8 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -166,7 +169,8 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
for
j
,
k2
in
enumerate
(
sub_x_start_arr
):
for
j
,
k2
in
enumerate
(
sub_x_start_arr
):
sub_x_s
=
k2
sub_x_s
=
k2
sub_x_e
=
sub_x_end_arr
[
j
]
sub_x_e
=
sub_x_end_arr
[
j
]
print
(
i
,
j
,
sub_y_s
,
sub_y_e
,
sub_x_s
,
sub_x_e
)
T1
=
time
.
time
()
skyImg_sub
=
galsim
.
Image
(
skyImg
.
array
[
sub_y_s
:
sub_y_e
,
sub_x_s
:
sub_x_e
])
skyImg_sub
=
galsim
.
Image
(
skyImg
.
array
[
sub_y_s
:
sub_y_e
,
sub_x_s
:
sub_x_e
])
origin_sub
=
[
sub_y_s
,
sub_x_s
]
origin_sub
=
[
sub_y_s
,
sub_x_s
]
sub_x_center
=
(
sub_x_s
+
sub_x_e
)
/
2.
sub_x_center
=
(
sub_x_s
+
sub_x_e
)
/
2.
...
@@ -175,7 +179,7 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -175,7 +179,7 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
tar_spec
=
spec
,
tar_spec
=
spec
,
band_start
=
tbstart
,
band_end
=
tbend
,
band_start
=
tbstart
,
band_end
=
tbend
,
conf
=
conf1
,
conf
=
conf1
,
flat_cube
=
flat_cub
e
,
ignoreBeam
=
[
'D'
,
'E'
])
flat_cube
=
Non
e
,
ignoreBeam
=
[
'
B'
,
'C'
,
'
D'
,
'E'
])
spec_orders
=
sdp
.
compute_spec_orders
()
spec_orders
=
sdp
.
compute_spec_orders
()
...
@@ -190,6 +194,11 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -190,6 +194,11 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
continue
continue
fImg
[
bounds
]
=
fImg
[
bounds
]
+
ssImg
[
bounds
]
fImg
[
bounds
]
=
fImg
[
bounds
]
+
ssImg
[
bounds
]
T2
=
time
.
time
()
print
(
'time: %s ms'
%
((
T2
-
T1
)
*
1000
))
delt_x
=
x_len
-
split_pos
sub_x_start_arr
=
np
.
arange
(
split_pos
,
x_len
,
delt_x
)
sub_x_start_arr
=
np
.
arange
(
split_pos
,
x_len
,
delt_x
)
sub_x_end_arr
=
sub_x_start_arr
+
delt_x
sub_x_end_arr
=
sub_x_start_arr
+
delt_x
sub_x_end_arr
[
-
1
]
=
min
(
sub_x_end_arr
[
-
1
],
x_len
)
sub_x_end_arr
[
-
1
]
=
min
(
sub_x_end_arr
[
-
1
],
x_len
)
...
@@ -203,6 +212,9 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -203,6 +212,9 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
for
j
,
k2
in
enumerate
(
sub_x_start_arr
):
for
j
,
k2
in
enumerate
(
sub_x_start_arr
):
sub_x_s
=
k2
sub_x_s
=
k2
sub_x_e
=
sub_x_end_arr
[
j
]
sub_x_e
=
sub_x_end_arr
[
j
]
print
(
i
,
j
,
sub_y_s
,
sub_y_e
,
sub_x_s
,
sub_x_e
)
T1
=
time
.
time
()
skyImg_sub
=
galsim
.
Image
(
skyImg
.
array
[
sub_y_s
:
sub_y_e
,
sub_x_s
:
sub_x_e
])
skyImg_sub
=
galsim
.
Image
(
skyImg
.
array
[
sub_y_s
:
sub_y_e
,
sub_x_s
:
sub_x_e
])
origin_sub
=
[
sub_y_s
,
sub_x_s
]
origin_sub
=
[
sub_y_s
,
sub_x_s
]
...
@@ -212,7 +224,7 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -212,7 +224,7 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
tar_spec
=
spec
,
tar_spec
=
spec
,
band_start
=
tbstart
,
band_end
=
tbend
,
band_start
=
tbstart
,
band_end
=
tbend
,
conf
=
conf2
,
conf
=
conf2
,
flat_cube
=
flat_cub
e
,
ignoreBeam
=
[
'D'
,
'E'
])
flat_cube
=
Non
e
,
ignoreBeam
=
[
'
B'
,
'C'
,
'
D'
,
'E'
])
spec_orders
=
sdp
.
compute_spec_orders
()
spec_orders
=
sdp
.
compute_spec_orders
()
...
@@ -226,6 +238,9 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
...
@@ -226,6 +238,9 @@ def calculateSkyMap_split_g(skyMap=None, blueLimit=4200, redLimit=6500, skyfn='s
if
bounds
.
area
()
==
0
:
if
bounds
.
area
()
==
0
:
continue
continue
fImg
[
bounds
]
=
fImg
[
bounds
]
+
ssImg
[
bounds
]
fImg
[
bounds
]
=
fImg
[
bounds
]
+
ssImg
[
bounds
]
T2
=
time
.
time
()
print
(
'time: %s ms'
%
((
T2
-
T1
)
*
1000
))
if
isAlongY
==
1
:
if
isAlongY
==
1
:
fimg
,
tmx
,
tmy
=
rotate90
(
array_orig
=
fImg
.
array
,
xc
=
0
,
yc
=
0
,
isClockwise
=
0
)
fimg
,
tmx
,
tmy
=
rotate90
(
array_orig
=
fImg
.
array
,
xc
=
0
,
yc
=
0
,
isClockwise
=
0
)
...
...
ObservationSim/MockObject/SpecDisperser/disperse_c/disperse.pyx
View file @
75547899
...
@@ -54,18 +54,16 @@ def disperse_grism_object(np.ndarray[FTYPE_t, ndim=2] flam,
...
@@ -54,18 +54,16 @@ def disperse_grism_object(np.ndarray[FTYPE_t, ndim=2] flam,
nk
=
len
(
idxl
)
nk
=
len
(
idxl
)
nl
=
len
(
full
)
nl
=
len
(
full
)
if
(
flat
is
not
None
):
nlamb
=
len
(
wlambda
)
nlamb
=
len
(
wlambda
)
flat_lamb_min
=
2500
flat_lamb_max
=
10000
flat_eff_all
=
np
.
ones
([
nl
,
nlamb
])
*
ysens
flat_eff_all
=
np
.
ones
([
nl
,
nlamb
])
*
ysens
lambda_co
=
np
.
zeros
([
len
(
flat
[
0
]),
nlamb
])
if
(
flat
is
not
None
):
nflat
=
len
(
flat
)
if
(
nflat
==
nl
):
if
(
len
(
flat
[
0
])
==
4
):
lambda_co
=
np
.
zeros
([
4
,
nlamb
])
lambda_co
[
0
]
=
lambda_co
[
0
]
+
1
lambda_co
[
0
]
=
lambda_co
[
0
]
+
1
lambda_co
[
1
]
=
wlambda
*
1
lambda_co
[
1
]
=
(
wlambda
-
flat_lamb_min
)
/
(
flat_lamb_max
-
flat_lamb_min
)
lambda_co
[
2
]
=
w
lambda
*
lambda_co
[
1
]
lambda_co
[
2
]
=
lambda
_co
[
1
]
*
lambda_co
[
1
]
lambda_co
[
3
]
=
w
lambda
*
lambda_co
[
2
]
lambda_co
[
3
]
=
lambda
_co
[
1
]
*
lambda_co
[
2
]
flat_eff_all
=
np
.
dot
(
flat
,
lambda_co
)
*
ysens
flat_eff_all
=
np
.
dot
(
flat
,
lambda_co
)
*
ysens
for
i
in
range
(
0
-
x0
[
1
],
x0
[
1
]):
for
i
in
range
(
0
-
x0
[
1
],
x0
[
1
]):
...
@@ -83,13 +81,33 @@ def disperse_grism_object(np.ndarray[FTYPE_t, ndim=2] flam,
...
@@ -83,13 +81,33 @@ def disperse_grism_object(np.ndarray[FTYPE_t, ndim=2] flam,
for
k
in
range
(
nk
):
for
k
in
range
(
nk
):
k1
=
idxl
[
k
]
+
j
*
shg
[
1
]
+
i
k1
=
idxl
[
k
]
+
j
*
shg
[
1
]
+
i
if
(
k1
>=
0
)
&
(
k1
<
nl
):
if
(
k1
>=
0
)
&
(
k1
<
nl
):
flux_factor
=
flat_eff_all
[
k1
,
k
]
full
[
k1
]
+=
fl_ij
*
yfrac
[
k
]
*
flat_eff_all
[
k1
,
k
]
full
[
k1
]
+=
fl_ij
*
yfrac
[
k
]
*
flux_factor
k2
=
idxl
[
k
]
+
(
j
-
1
)
*
shg
[
1
]
+
i
if
(
k2
>=
0
)
&
(
k2
<
nl
):
full
[
k2
]
+=
fl_ij
*
(
1
-
yfrac
[
k
])
*
flat_eff_all
[
k2
,
k
]
else
:
for
i
in
range
(
0
-
x0
[
1
],
x0
[
1
]):
if
(
x0
[
1
]
+
i
<
0
)
|
(
x0
[
1
]
+
i
>=
shd
[
1
]):
continue
for
j
in
range
(
0
-
x0
[
0
],
x0
[
0
]):
if
(
x0
[
0
]
+
j
<
0
)
|
(
x0
[
0
]
+
j
>=
shd
[
0
]):
continue
fl_ij
=
flam
[
x0
[
0
]
+
j
,
x0
[
1
]
+
i
]
#/1.e-17
if
(
fl_ij
==
0
):
continue
for
k
in
range
(
nk
):
k1
=
idxl
[
k
]
+
j
*
shg
[
1
]
+
i
if
(
k1
>=
0
)
&
(
k1
<
nl
):
full
[
k1
]
+=
fl_ij
*
yfrac
[
k
]
*
ysens
[
k
]
k2
=
idxl
[
k
]
+
(
j
-
1
)
*
shg
[
1
]
+
i
k2
=
idxl
[
k
]
+
(
j
-
1
)
*
shg
[
1
]
+
i
if
(
k2
>=
0
)
&
(
k2
<
nl
):
if
(
k2
>=
0
)
&
(
k2
<
nl
):
flux_factor
=
flat_eff_all
[
k2
,
k
]
full
[
k2
]
+=
fl_ij
*
(
1
-
yfrac
[
k
])
*
ysens
[
k
]
full
[
k2
]
+=
fl_ij
*
(
1
-
yfrac
[
k
])
*
flux_factor
return
True
return
True
...
...
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