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
0b2605c1
"csst_dag/_dfs/__init__.py" did not exist on "be6f7bc25692d8b5ee444cbe72384916efa4940f"
Commit
0b2605c1
authored
Jan 05, 2023
by
xin
Browse files
add saturation information
parent
bd690d1b
Changes
3
Show whitespace changes
Inline
Side-by-side
SpecGen/SpecGenerator.py
View file @
0b2605c1
...
@@ -30,7 +30,7 @@ from . import Config
...
@@ -30,7 +30,7 @@ from . import Config
class
SpecGenerator
(
object
):
class
SpecGenerator
(
object
):
def
__init__
(
self
,
sedFn
=
'a.txt'
,
grating
=
'GI'
,
beam
=
'A'
,
aper
=
2.0
,
xcenter
=
5000
,
ycenter
=
5000
,
p_size
=
0.074
,
psf
=
None
,
skybg
=
0.3
,
dark
=
0.02
,
readout
=
5
,
t
=
150
,
expNum
=
1
,
config
=
None
):
def
__init__
(
self
,
sedFn
=
'a.txt'
,
grating
=
'GI'
,
beam
=
'A'
,
aper
=
2.0
,
xcenter
=
5000
,
ycenter
=
5000
,
p_size
=
0.074
,
psf
=
None
,
skybg
=
0.3
,
dark
=
0.02
,
readout
=
5
,
t
=
150
,
expNum
=
1
,
config
=
None
,
saturation
=
90000
):
self
.
sedFile
=
sedFn
self
.
sedFile
=
sedFn
self
.
grating
=
grating
self
.
grating
=
grating
self
.
beam
=
beam
self
.
beam
=
beam
...
@@ -45,6 +45,7 @@ class SpecGenerator(object):
...
@@ -45,6 +45,7 @@ class SpecGenerator(object):
self
.
t
=
t
self
.
t
=
t
self
.
expNum
=
expNum
self
.
expNum
=
expNum
self
.
config
=
config
self
.
config
=
config
self
.
saturation
=
saturation
'''
'''
@description:
@description:
...
@@ -115,15 +116,15 @@ class SpecGenerator(object):
...
@@ -115,15 +116,15 @@ class SpecGenerator(object):
thp_i
=
interpolate
.
interp1d
(
thp
[
'WAVELENGTH'
],
thp
[
'SENSITIVITY'
])
thp_i
=
interpolate
.
interp1d
(
thp
[
'WAVELENGTH'
],
thp
[
'SENSITIVITY'
])
Aimg_orig
=
spec_orders
[
self
.
beam
][
0
]
Aimg_orig
=
spec_orders
[
self
.
beam
][
0
]
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
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
)
Aimg
=
Aimg
-
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
Aimg
=
Aimg
_
-
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
wave_pix
=
spec_orders
[
self
.
beam
][
5
]
wave_pix
=
spec_orders
[
self
.
beam
][
5
]
...
@@ -160,18 +161,20 @@ class SpecGenerator(object):
...
@@ -160,18 +161,20 @@ class SpecGenerator(object):
bRange
=
self
.
config
.
bandRanges
[
self
.
grating
]
bRange
=
self
.
config
.
bandRanges
[
self
.
grating
]
wave_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
wave_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
err_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
err_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
specRangeImg
=
[]
for
i
in
np
.
arange
(
1
,
wave_pix
.
shape
[
0
]
-
1
):
for
i
in
np
.
arange
(
1
,
wave_pix
.
shape
[
0
]
-
1
):
w
=
wave_pix
[
i
]
w
=
wave_pix
[
i
]
if
(
bRange
[
0
]
<=
w
<=
bRange
[
1
]):
if
(
bRange
[
0
]
<=
w
<=
bRange
[
1
]):
thp_w
=
thp_i
(
w
)
thp_w
=
thp_i
(
w
)
deltW
=
(
w
-
wave_pix
[
i
-
1
])
/
2
+
(
wave_pix
[
i
+
1
]
-
w
)
/
2
deltW
=
np
.
abs
(
w
-
wave_pix
[
i
-
1
])
/
2
+
np
.
abs
(
wave_pix
[
i
+
1
]
-
w
)
/
2
f
=
spec_pix
[
wave_pos
[
0
]
-
1
+
i
]
f
=
spec_pix
[
wave_pos
[
0
]
-
1
+
i
]
f
=
f
/
self
.
t
/
thp_w
/
deltW
/
self
.
expNum
f
=
f
/
self
.
t
/
thp_w
/
deltW
/
self
.
expNum
err
=
err2_pix
[
wave_pos
[
0
]
-
1
+
i
]
err
=
err2_pix
[
wave_pos
[
0
]
-
1
+
i
]
# err = err/ t / deltW
# err = err/ t / deltW
err
=
np
.
sqrt
(
err
)
/
self
.
t
/
deltW
/
thp_w
/
self
.
expNum
err
=
np
.
sqrt
(
err
)
/
self
.
t
/
deltW
/
thp_w
/
self
.
expNum
# err = err / thp_w
# err = err / thp_w
specRangeImg
.
append
(
wave_pos
[
0
]
-
1
+
i
)
else
:
else
:
f
=
0
f
=
0
err
=
0
err
=
0
...
@@ -179,6 +182,17 @@ class SpecGenerator(object):
...
@@ -179,6 +182,17 @@ class SpecGenerator(object):
wave_flux
[
i
]
=
f
wave_flux
[
i
]
=
f
err_flux
[
i
]
=
err
err_flux
[
i
]
=
err
Aimg_cal
=
Aimg_
[
y_cent_pos
-
y_range
:
y_cent_pos
+
y_range
+
1
,
specRangeImg
]
ids
=
Aimg_cal
>
self
.
saturation
#1. saturation pixel number, 2. total pixel number, 3 saturation ratio, 4.flux ratio in photo aperture
saturePix
=
[
0
,
0
,
0
,
0
]
saturePix
[
0
]
=
Aimg_cal
[
ids
].
shape
[
0
]
saturePix
[
1
]
=
Aimg_cal
.
shape
[
0
]
*
Aimg_cal
.
shape
[
1
]
saturePix
[
2
]
=
saturePix
[
0
]
/
saturePix
[
1
]
saturePix
[
3
]
=
fluxRatio
idx
=
(
wave_pix
>=
bRange
[
0
]
-
100
)
idx
=
(
wave_pix
>=
bRange
[
0
]
-
100
)
idx1
=
(
wave_pix
[
idx
]
<=
bRange
[
1
]
+
100
)
idx1
=
(
wave_pix
[
idx
]
<=
bRange
[
1
]
+
100
)
...
@@ -194,7 +208,7 @@ class SpecGenerator(object):
...
@@ -194,7 +208,7 @@ class SpecGenerator(object):
# plt.legend([self.sedFile])
# plt.legend([self.sedFile])
# # plt.plot(wave_pix[idx][idx1], wave_flux[idx][idx1])
# # plt.plot(wave_pix[idx][idx1], wave_flux[idx][idx1])
# plt.show()
# plt.show()
return
specTab
,
Aimg
,
stamp
.
array
,
fluxRatio
return
specTab
,
Aimg
,
stamp
.
array
,
saturePix
def
generateSpec1dforStar
(
self
,
limitfluxratio
=
0.8
):
def
generateSpec1dforStar
(
self
,
limitfluxratio
=
0.8
):
...
@@ -223,15 +237,15 @@ class SpecGenerator(object):
...
@@ -223,15 +237,15 @@ class SpecGenerator(object):
thp_i
=
interpolate
.
interp1d
(
thp
[
'WAVELENGTH'
],
thp
[
'SENSITIVITY'
])
thp_i
=
interpolate
.
interp1d
(
thp
[
'WAVELENGTH'
],
thp
[
'SENSITIVITY'
])
Aimg_orig
=
spec_orders
[
self
.
beam
][
0
]
Aimg_orig
=
spec_orders
[
self
.
beam
][
0
]
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
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
)
Aimg
=
Aimg
-
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
Aimg
=
Aimg
_
-
(
self
.
skybg
+
self
.
dark
)
*
self
.
t
*
self
.
expNum
wave_pix
=
spec_orders
[
self
.
beam
][
5
]
wave_pix
=
spec_orders
[
self
.
beam
][
5
]
...
@@ -268,17 +282,21 @@ class SpecGenerator(object):
...
@@ -268,17 +282,21 @@ class SpecGenerator(object):
bRange
=
self
.
config
.
bandRanges
[
self
.
grating
]
bRange
=
self
.
config
.
bandRanges
[
self
.
grating
]
wave_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
wave_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
err_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
err_flux
=
np
.
zeros
(
wave_pix
.
shape
[
0
])
specRangeImg
=
[]
for
i
in
np
.
arange
(
1
,
wave_pix
.
shape
[
0
]
-
1
):
for
i
in
np
.
arange
(
1
,
wave_pix
.
shape
[
0
]
-
1
):
w
=
wave_pix
[
i
]
w
=
wave_pix
[
i
]
if
(
bRange
[
0
]
<=
w
<=
bRange
[
1
]):
if
(
bRange
[
0
]
<=
w
<=
bRange
[
1
]):
thp_w
=
thp_i
(
w
)
thp_w
=
thp_i
(
w
)
deltW
=
(
w
-
wave_pix
[
i
-
1
])
/
2
+
(
wave_pix
[
i
+
1
]
-
w
)
/
2
deltW
=
np
.
abs
(
w
-
wave_pix
[
i
-
1
])
/
2
+
np
.
abs
(
wave_pix
[
i
+
1
]
-
w
)
/
2
f
=
spec_pix
[
wave_pos
[
0
]
-
1
+
i
]
f
=
spec_pix
[
wave_pos
[
0
]
-
1
+
i
]
f
=
f
/
self
.
t
/
thp_w
/
deltW
/
self
.
expNum
f
=
f
/
self
.
t
/
thp_w
/
deltW
/
self
.
expNum
err
=
err2_pix
[
wave_pos
[
0
]
-
1
+
i
]
err
=
err2_pix
[
wave_pos
[
0
]
-
1
+
i
]
# err = err/ t / deltW
# err = err/ t / deltW
err
=
np
.
sqrt
(
err
)
/
self
.
t
/
deltW
/
thp_w
/
self
.
expNum
err
=
np
.
sqrt
(
err
)
/
self
.
t
/
deltW
/
thp_w
/
self
.
expNum
specRangeImg
.
append
(
wave_pos
[
0
]
-
1
+
i
)
# err = err / thp_w
# err = err / thp_w
else
:
else
:
f
=
0
f
=
0
...
@@ -287,6 +305,17 @@ class SpecGenerator(object):
...
@@ -287,6 +305,17 @@ class SpecGenerator(object):
wave_flux
[
i
]
=
f
wave_flux
[
i
]
=
f
err_flux
[
i
]
=
err
err_flux
[
i
]
=
err
Aimg_cal
=
Aimg_
[
y_cent_pos
-
y_range
:
y_cent_pos
+
y_range
+
1
,
specRangeImg
]
ids
=
Aimg_cal
>
self
.
saturation
#1. saturation pixel number, 2. total pixel number, 3 saturation ratio, 4.flux ratio in photo aperture
saturePix
=
[
0
,
0
,
0
,
0
]
saturePix
[
0
]
=
Aimg_cal
[
ids
].
shape
[
0
]
saturePix
[
1
]
=
Aimg_cal
.
shape
[
0
]
*
Aimg_cal
.
shape
[
1
]
saturePix
[
2
]
=
saturePix
[
0
]
/
saturePix
[
1
]
saturePix
[
3
]
=
fluxRatio
idx
=
(
wave_pix
>=
bRange
[
0
]
-
100
)
idx
=
(
wave_pix
>=
bRange
[
0
]
-
100
)
idx1
=
(
wave_pix
[
idx
]
<=
bRange
[
1
]
+
100
)
idx1
=
(
wave_pix
[
idx
]
<=
bRange
[
1
]
+
100
)
...
@@ -302,7 +331,7 @@ class SpecGenerator(object):
...
@@ -302,7 +331,7 @@ class SpecGenerator(object):
# plt.legend([self.sedFile])
# plt.legend([self.sedFile])
# # plt.plot(wave_pix[idx][idx1], wave_flux[idx][idx1])
# # plt.plot(wave_pix[idx][idx1], wave_flux[idx][idx1])
# plt.show()
# plt.show()
return
specTab
,
Aimg
,
stamp
.
array
,
fluxRatio
return
specTab
,
Aimg
,
stamp
.
array
,
saturePix
def
addReadoutNois
(
self
,
img
=
None
,
readout
=
5
):
def
addReadoutNois
(
self
,
img
=
None
,
readout
=
5
):
for
i
in
range
(
img
.
shape
[
0
]):
for
i
in
range
(
img
.
shape
[
0
]):
...
...
SpecWindow/specWin.py
View file @
0b2605c1
...
@@ -305,11 +305,11 @@ class Example(QMainWindow):
...
@@ -305,11 +305,11 @@ class Example(QMainWindow):
self
.
lbl11
=
QLabel
(
self
)
self
.
lbl11
=
QLabel
(
self
)
self
.
lbl11
.
move
(
20
,
55
0
)
self
.
lbl11
.
move
(
20
,
5
4
5
)
self
.
lbl11
.
setText
(
'output directory'
)
self
.
lbl11
.
setText
(
'output directory'
)
self
.
btn
=
QPushButton
(
"Output"
,
self
)
self
.
btn
=
QPushButton
(
"Output"
,
self
)
self
.
btn
.
move
(
120
,
55
0
)
self
.
btn
.
move
(
120
,
5
4
5
)
self
.
btn
.
clicked
.
connect
(
self
.
showDialog2
)
self
.
btn
.
clicked
.
connect
(
self
.
showDialog2
)
# self.lbl12 = QLabel(self)
# self.lbl12 = QLabel(self)
...
@@ -317,12 +317,24 @@ class Example(QMainWindow):
...
@@ -317,12 +317,24 @@ class Example(QMainWindow):
self
.
lbl_line1
=
QLabel
(
self
)
self
.
lbl_line1
=
QLabel
(
self
)
self
.
lbl_line1
.
move
(
20
,
580
)
self
.
lbl_line1
.
move
(
20
,
580
)
self
.
lbl_line1
.
setText
(
'----------------------------------------------'
)
self
.
lbl_line1
.
setText
(
'----------Calculation Information------------'
)
self
.
lbl_line1
.
adjustSize
()
self
.
outinfo
=
QLineEdit
(
self
)
# self.gsnText.setPlaceholderText('Sersic n')
self
.
outinfo
.
move
(
20
,
600
)
self
.
outinfo
.
setText
(
' '
)
self
.
outinfo
.
resize
(
300
,
40
)
self
.
outinfo
.
setReadOnly
(
True
)
self
.
lbl_line1
=
QLabel
(
self
)
self
.
lbl_line1
.
move
(
20
,
640
)
self
.
lbl_line1
.
setText
(
'---------------------------------------------'
)
self
.
lbl_line1
.
adjustSize
()
self
.
lbl_line1
.
adjustSize
()
self
.
simBt
=
QPushButton
(
'Begin Sim'
,
self
)
self
.
simBt
=
QPushButton
(
'Begin Sim'
,
self
)
self
.
simBt
.
setCheckable
(
True
)
self
.
simBt
.
setCheckable
(
True
)
self
.
simBt
.
move
(
20
,
6
1
0
)
self
.
simBt
.
move
(
20
,
6
5
0
)
self
.
simBt
.
clicked
.
connect
(
self
.
runDialog
)
self
.
simBt
.
clicked
.
connect
(
self
.
runDialog
)
...
@@ -403,18 +415,19 @@ class Example(QMainWindow):
...
@@ -403,18 +415,19 @@ class Example(QMainWindow):
psf
=
galsim
.
Gaussian
(
fwhm
=
fwhm
)
psf
=
galsim
.
Gaussian
(
fwhm
=
fwhm
)
specG
=
SpecGenerator
(
sedFn
=
sedFn
,
grating
=
grating
,
beam
=
beam
,
aper
=
2.0
,
xcenter
=
2000
,
ycenter
=
5000
,
p_size
=
p_size
,
psf
=
psf
,
skybg
=
skybg
,
dark
=
dark
,
readout
=
readout
,
t
=
t
,
expNum
=
expNum
,
config
=
config
)
specG
=
SpecGenerator
(
sedFn
=
sedFn
,
grating
=
grating
,
beam
=
beam
,
aper
=
2.0
,
xcenter
=
2000
,
ycenter
=
5000
,
p_size
=
p_size
,
psf
=
psf
,
skybg
=
skybg
,
dark
=
dark
,
readout
=
readout
,
t
=
t
,
expNum
=
expNum
,
config
=
config
)
if
self
.
cb1
.
isChecked
()
==
True
:
if
self
.
cb1
.
isChecked
()
==
True
:
specTab
,
specImg
,
img
,
fluxRa
=
specG
.
generateSpec1dforStar
()
specTab
,
specImg
,
img
,
sutPix
=
specG
.
generateSpec1dforStar
(
limitfluxratio
=
0.8
)
else
:
else
:
g_sn
=
float
(
self
.
gsnText
.
text
())
g_sn
=
float
(
self
.
gsnText
.
text
())
g_re
=
float
(
self
.
greText
.
text
())
g_re
=
float
(
self
.
greText
.
text
())
g_pa
=
float
(
self
.
gpaText
.
text
())
g_pa
=
float
(
self
.
gpaText
.
text
())
g_q
=
float
(
self
.
gqText
.
text
())
g_q
=
float
(
self
.
gqText
.
text
())
specTab
,
specImg
,
img
,
fluxRa
=
specG
.
generateSpec1dforGal
(
s_n
=
g_sn
,
re
=
g_re
,
pa
=
g_pa
,
q_ell
=
g_q
,
limitfluxratio
=
0.9
)
specTab
,
specImg
,
img
,
sutPix
=
specG
.
generateSpec1dforGal
(
s_n
=
g_sn
,
re
=
g_re
,
pa
=
g_pa
,
q_ell
=
g_q
,
limitfluxratio
=
0.8
)
self
.
outinfo
.
setText
(
'saturation: 90000 e- , saturation pixel number: %d, total pixel number: %d, saturation ratio: %f'
%
(
sutPix
[
0
],
sutPix
[
1
],
sutPix
[
2
]))
# self.outinfo.adjustSize()
spec_orig
=
np
.
loadtxt
(
sedFn
)
spec_orig
=
np
.
loadtxt
(
sedFn
)
self
.
fig
.
add_line
(
specTab
[
'WAVELENGTH'
],
specTab
[
'FLUX'
]
/
fluxRa
,
spec_orig
[:,
0
],
spec_orig
[:,
1
],
specImg
,
grating
)
self
.
fig
.
add_line
(
specTab
[
'WAVELENGTH'
],
specTab
[
'FLUX'
]
/
sutPix
[
3
]
,
spec_orig
[:,
0
],
spec_orig
[:,
1
],
specImg
,
grating
)
self
.
fig
.
draw
()
self
.
fig
.
draw
()
...
...
example/sim_demo1.py
View file @
0b2605c1
...
@@ -16,7 +16,7 @@ if __name__ == '__main__':
...
@@ -16,7 +16,7 @@ if __name__ == '__main__':
sedFn
=
dataDir
+
'sed/sed_44575.txt'
sedFn
=
dataDir
+
'sed/sed_44575.txt'
psf
=
galsim
.
Gaussian
(
fwhm
=
0.39
)
psf
=
galsim
.
Gaussian
(
fwhm
=
0.39
)
specG
=
SpecGenerator
(
sedFn
=
sedFn
,
grating
=
'GI'
,
beam
=
'A'
,
aper
=
2.0
,
xcenter
=
2000
,
ycenter
=
5000
,
p_size
=
0.074
,
psf
=
psf
,
skybg
=
0.3
,
dark
=
0.02
,
readout
=
5
,
t
=
150
,
expNum
=
1
,
config
=
config
)
specG
=
SpecGenerator
(
sedFn
=
sedFn
,
grating
=
'GI'
,
beam
=
'A'
,
aper
=
2.0
,
xcenter
=
2000
,
ycenter
=
5000
,
p_size
=
0.074
,
psf
=
psf
,
skybg
=
0.3
,
dark
=
0.02
,
readout
=
5
,
t
=
150
,
expNum
=
1
,
config
=
config
)
specTab
,
specImg
,
img
,
fluxRa
=
specG
.
generateSpec1dforStar
()
specTab
,
specImg
,
img
,
satPix
=
specG
.
generateSpec1dforStar
()
fits
.
writeto
(
"specImg.fits"
,
specImg
,
overwrite
=
True
)
fits
.
writeto
(
"specImg.fits"
,
specImg
,
overwrite
=
True
)
fits
.
writeto
(
"DImg.fits"
,
img
,
overwrite
=
True
)
fits
.
writeto
(
"DImg.fits"
,
img
,
overwrite
=
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