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
Zhang Xin
Sls 1d Spec
Commits
43f01711
Commit
43f01711
authored
Apr 03, 2023
by
xin
Browse files
adjust spec sampling density and random seed
parent
12488ec1
Changes
2
Hide whitespace changes
Inline
Side-by-side
SpecDisperser/SpecDisperser.py
View file @
43f01711
...
@@ -60,7 +60,7 @@ def rotate90(array_orig=None, xc=0, yc=0, isClockwise=0):
...
@@ -60,7 +60,7 @@ def rotate90(array_orig=None, xc=0, yc=0, isClockwise=0):
class
SpecDisperser
(
object
):
class
SpecDisperser
(
object
):
def
__init__
(
self
,
orig_img
=
None
,
xcenter
=
0
,
ycenter
=
0
,
origin
=
[
100
,
100
],
tar_spec
=
None
,
band_start
=
2550
,
def
__init__
(
self
,
orig_img
=
None
,
xcenter
=
0
,
ycenter
=
0
,
origin
=
[
100
,
100
],
tar_spec
=
None
,
band_start
=
2550
,
band_end
=
10000
,
isAlongY
=
0
,
conf
=
'../param/CONF/csst.conf'
,
gid
=
0
):
band_end
=
10000
,
isAlongY
=
0
,
conf
=
'../param/CONF/csst.conf'
,
gid
=
0
,
deltLamb
=
0.01
):
"""
"""
orig_img: normal image,galsim image
orig_img: normal image,galsim image
xcenter, ycenter: the center of galaxy in orig_img
xcenter, ycenter: the center of galaxy in orig_img
...
@@ -97,6 +97,7 @@ class SpecDisperser(object):
...
@@ -97,6 +97,7 @@ class SpecDisperser(object):
self
.
band_start
=
band_start
self
.
band_start
=
band_start
self
.
band_end
=
band_end
self
.
band_end
=
band_end
self
.
spec
=
tar_spec
self
.
spec
=
tar_spec
self
.
deltLamb
=
deltLamb
self
.
beam_flux
=
OrderedDict
()
self
.
beam_flux
=
OrderedDict
()
...
@@ -132,7 +133,7 @@ class SpecDisperser(object):
...
@@ -132,7 +133,7 @@ class SpecDisperser(object):
lam_index
=
argsort
(
lam_beam
)
lam_index
=
argsort
(
lam_beam
)
conf_sens
=
self
.
grating_conf
.
sens
[
beam
]
conf_sens
=
self
.
grating_conf
.
sens
[
beam
]
lam_intep
=
np
.
linspace
(
self
.
band_start
,
self
.
band_end
,
int
((
self
.
band_end
-
self
.
band_start
)
/
0.5
))
lam_intep
=
np
.
linspace
(
self
.
band_start
,
self
.
band_end
,
int
((
self
.
band_end
-
self
.
band_start
)
/
self
.
deltLamb
))
thri
=
interpolate
.
interp1d
(
conf_sens
[
'WAVELENGTH'
],
conf_sens
[
'SENSITIVITY'
])
thri
=
interpolate
.
interp1d
(
conf_sens
[
'WAVELENGTH'
],
conf_sens
[
'SENSITIVITY'
])
spci
=
interpolate
.
interp1d
(
self
.
spec
[
'WAVELENGTH'
],
self
.
spec
[
'FLUX'
])
spci
=
interpolate
.
interp1d
(
self
.
spec
[
'WAVELENGTH'
],
self
.
spec
[
'FLUX'
])
...
...
SpecGen/SpecGenerator.py
View file @
43f01711
...
@@ -21,6 +21,7 @@ import random
...
@@ -21,6 +21,7 @@ import random
from
astropy.table
import
Table
from
astropy.table
import
Table
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
time
import
mpi4py.MPI
as
MPI
import
mpi4py.MPI
as
MPI
...
@@ -76,13 +77,13 @@ class SpecGenerator(object):
...
@@ -76,13 +77,13 @@ class SpecGenerator(object):
return
SED
return
SED
def
generateSpec1dforGal
(
self
,
s_n
=
1.0
,
re
=
1
,
pa
=
90
,
q_ell
=
0.6
,
limitfluxratio
=
0.9
):
def
generateSpec1dforGal
(
self
,
s_n
=
1.0
,
re
=
1
,
pa
=
90
,
q_ell
=
0.6
,
limitfluxratio
=
0.9
,
deltLamb
=
0.01
):
specConfile
=
self
.
config
.
conFiles
[
self
.
grating
]
specConfile
=
self
.
config
.
conFiles
[
self
.
grating
]
throughput_f
=
self
.
config
.
senFisle
[
self
.
grating
]
+
self
.
config
.
orderIDs
[
self
.
beam
]
+
'.fits'
throughput_f
=
self
.
config
.
senFisle
[
self
.
grating
]
+
self
.
config
.
orderIDs
[
self
.
beam
]
+
'.fits'
sed
=
self
.
generateSEDfromFiles
(
self
.
sedFile
,
2500
,
10000
,
0.01
)
sed
=
self
.
generateSEDfromFiles
(
self
.
sedFile
,
2500
,
10000
,
deltLamb
)
x_nominal
=
int
(
np
.
floor
(
self
.
xcenter
+
0.5
))
x_nominal
=
int
(
np
.
floor
(
self
.
xcenter
+
0.5
))
y_nominal
=
int
(
np
.
floor
(
self
.
ycenter
+
0.5
))
y_nominal
=
int
(
np
.
floor
(
self
.
ycenter
+
0.5
))
...
@@ -118,7 +119,7 @@ class SpecGenerator(object):
...
@@ -118,7 +119,7 @@ class SpecGenerator(object):
ycenter
=
y_nominal
,
origin
=
origin_star
,
ycenter
=
y_nominal
,
origin
=
origin_star
,
tar_spec
=
sed
,
tar_spec
=
sed
,
conf
=
specConfile
,
conf
=
specConfile
,
isAlongY
=
0
)
isAlongY
=
0
,
deltLamb
=
deltLamb
/
2.
)
spec_orders
=
sdp
.
compute_spec_orders
()
spec_orders
=
sdp
.
compute_spec_orders
()
...
@@ -130,6 +131,7 @@ class SpecGenerator(object):
...
@@ -130,6 +131,7 @@ class SpecGenerator(object):
Aimg_
=
Aimg_
+
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
Aimg_
=
Aimg_
+
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
np
.
random
.
seed
(
int
(
time
.
time
()))
Aimg_
=
np
.
random
.
poisson
(
Aimg_
)
Aimg_
=
np
.
random
.
poisson
(
Aimg_
)
for
i
in
np
.
arange
(
self
.
expNum
):
for
i
in
np
.
arange
(
self
.
expNum
):
Aimg_
=
self
.
addReadoutNois
(
img
=
Aimg_
,
readout
=
self
.
readout
)
Aimg_
=
self
.
addReadoutNois
(
img
=
Aimg_
,
readout
=
self
.
readout
)
...
@@ -253,13 +255,13 @@ class SpecGenerator(object):
...
@@ -253,13 +255,13 @@ class SpecGenerator(object):
return
specTab
,
Aimg
,
stamp
.
array
,
saturePix
return
specTab
,
Aimg
,
stamp
.
array
,
saturePix
def
generateSpec1dforStar
(
self
,
limitfluxratio
=
0.8
):
def
generateSpec1dforStar
(
self
,
limitfluxratio
=
0.8
,
deltLamb
=
0.01
):
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
specConfile
=
self
.
config
.
conFiles
[
self
.
grating
]
specConfile
=
self
.
config
.
conFiles
[
self
.
grating
]
throughput_f
=
self
.
config
.
senFisle
[
self
.
grating
]
+
self
.
config
.
orderIDs
[
self
.
beam
]
+
'.fits'
throughput_f
=
self
.
config
.
senFisle
[
self
.
grating
]
+
self
.
config
.
orderIDs
[
self
.
beam
]
+
'.fits'
sed
=
self
.
generateSEDfromFiles
(
self
.
sedFile
,
2500
,
10000
,
0.01
)
sed
=
self
.
generateSEDfromFiles
(
self
.
sedFile
,
2500
,
10000
,
deltLamb
)
x_nominal
=
int
(
np
.
floor
(
self
.
xcenter
+
0.5
))
x_nominal
=
int
(
np
.
floor
(
self
.
xcenter
+
0.5
))
y_nominal
=
int
(
np
.
floor
(
self
.
ycenter
+
0.5
))
y_nominal
=
int
(
np
.
floor
(
self
.
ycenter
+
0.5
))
...
@@ -293,7 +295,7 @@ class SpecGenerator(object):
...
@@ -293,7 +295,7 @@ class SpecGenerator(object):
ycenter
=
y_nominal
,
origin
=
origin_star
,
ycenter
=
y_nominal
,
origin
=
origin_star
,
tar_spec
=
sed
,
tar_spec
=
sed
,
conf
=
specConfile
,
conf
=
specConfile
,
isAlongY
=
0
)
isAlongY
=
0
,
deltLamb
=
deltLamb
/
2.
)
spec_orders
=
sdp
.
compute_spec_orders
()
spec_orders
=
sdp
.
compute_spec_orders
()
...
@@ -304,7 +306,7 @@ class SpecGenerator(object):
...
@@ -304,7 +306,7 @@ class SpecGenerator(object):
Aimg_
=
Aimg_orig
Aimg_
=
Aimg_orig
Aimg_
=
Aimg_
+
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
Aimg_
=
Aimg_
+
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
np
.
random
.
seed
(
int
(
time
.
time
()))
Aimg_
=
np
.
random
.
poisson
(
Aimg_
)
Aimg_
=
np
.
random
.
poisson
(
Aimg_
)
for
i
in
np
.
arange
(
self
.
expNum
):
for
i
in
np
.
arange
(
self
.
expNum
):
Aimg_
=
self
.
addReadoutNois
(
img
=
Aimg_
,
readout
=
self
.
readout
)
Aimg_
=
self
.
addReadoutNois
(
img
=
Aimg_
,
readout
=
self
.
readout
)
...
@@ -424,6 +426,7 @@ class SpecGenerator(object):
...
@@ -424,6 +426,7 @@ class SpecGenerator(object):
return
specTab
,
Aimg
,
stamp
.
array
,
saturePix
return
specTab
,
Aimg
,
stamp
.
array
,
saturePix
def
addReadoutNois
(
self
,
img
=
None
,
readout
=
5
):
def
addReadoutNois
(
self
,
img
=
None
,
readout
=
5
):
random
.
seed
(
time
.
time
())
for
i
in
range
(
img
.
shape
[
0
]):
for
i
in
range
(
img
.
shape
[
0
]):
for
j
in
range
(
img
.
shape
[
1
]):
for
j
in
range
(
img
.
shape
[
1
]):
img
[
i
,
j
]
+=
round
(
random
.
gauss
(
mu
=
0
,
sigma
=
readout
))
img
[
i
,
j
]
+=
round
(
random
.
gauss
(
mu
=
0
,
sigma
=
readout
))
...
...
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