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_msc_sim
Commits
96e13f5a
Commit
96e13f5a
authored
Apr 11, 2024
by
Wei Chengliang
Browse files
update darknoise module
parent
02bd3aae
Changes
3
Show whitespace changes
Inline
Side-by-side
ObservationSim/Instrument/Chip/ChipUtils.py
View file @
96e13f5a
...
...
@@ -171,22 +171,40 @@ def get_poisson(seed=0, sky_level=0.):
poisson_noise
=
galsim
.
PoissonNoise
(
rng_poisson
,
sky_level
=
sky_level
)
return
rng_poisson
,
poisson_noise
def
get_base_img
(
img
,
read_noise
,
readout_time
,
dark_noise
,
exptime
=
150.
):
def
get_base_img
(
img
,
chip
,
read_noise
,
readout_time
,
dark_noise
,
exptime
=
150.
,
InputDark
=
None
):
if
InputDark
==
None
:
# base_level = read_noise**2 + dark_noise*(exptime+0.5*readout_time)
base_level
=
dark_noise
*
(
exptime
+
0.5
*
readout_time
)
base_img
=
base_level
*
np
.
ones_like
(
img
.
array
)
return
base_img
def
add_poisson
(
img
,
chip
,
exptime
=
150.
,
seed
=
0
,
sky_level
=
0.
,
poisson_noise
=
None
,
dark_noise
=
None
):
## base_level = dark_noise*(exptime+0.5*readout_time)
base_level
=
dark_noise
*
(
exptime
)
base_img1
=
base_level
*
np
.
ones_like
(
img
.
array
)
else
:
base_img1
=
np
.
zeros_like
(
img
.
array
)
ny
=
int
(
chip
.
npix_y
/
2
)
nx
=
chip
.
npix_x
arr
=
np
.
arange
(
ny
).
reshape
(
ny
,
1
)
arr
=
np
.
broadcast_to
(
arr
,
(
ny
,
nx
))
base_img2
=
np
.
zeros_like
(
img
.
array
)
base_img2
[:
ny
,
:]
=
arr
base_img2
[
ny
:,
:]
=
arr
[::
-
1
,:]
base_img2
[:,:]
=
base_img2
[:,:]
*
(
readout_time
/
ny
)
*
dark_noise
return
base_img1
+
base_img2
def
add_poisson
(
img
,
chip
,
exptime
=
150.
,
seed
=
0
,
sky_level
=
0.
,
poisson_noise
=
None
,
dark_noise
=
None
,
InputDark
=
None
):
if
poisson_noise
is
None
:
_
,
poisson_noise
=
get_poisson
(
seed
=
seed
,
sky_level
=
sky_level
)
read_noise
=
chip
.
read_noise
if
dark_noise
is
None
:
dark_noise
=
chip
.
dark_noise
base_img
=
get_base_img
(
img
=
img
,
read_noise
=
read_noise
,
readout_time
=
chip
.
readout_time
,
dark_noise
=
dark_noise
,
exptime
=
exptime
)
base_img
=
get_base_img
(
img
=
img
,
chip
,
read_noise
=
read_noise
,
readout_time
=
chip
.
readout_time
,
dark_noise
=
dark_noise
,
exptime
=
exptime
,
InputDark
=
None
)
img
+=
base_img
img
.
addNoise
(
poisson_noise
)
# img -= read_noise**2
if
InputDark
!=
None
:
hdu
=
fits
.
open
(
InputDark
)
##"Instrument/data/dark/dark_1000s_example_0.fits"
img
+=
hdu
[
0
].
data
/
hdu
[
0
].
header
[
'exptime'
]
*
exptime
hdu
.
close
()
return
img
,
base_img
def
add_brighter_fatter
(
img
):
...
...
@@ -215,7 +233,7 @@ def add_brighter_fatter(img):
img
.
array
[:,
:]
=
np
.
reshape
(
arr_imc
,
[
nx
,
ny
])
del
arr_ima
,
arr_imc
return
img
"""
def add_inputdark(img, chip, exptime):
fname = "/share/home/weichengliang/CSST_git/test_new_sim/csst-simulation/ObservationSim/Instrument/data/dark/dark_1000s_example_0.fits"
hdu = fits.open(fname)
...
...
@@ -225,7 +243,7 @@ def add_inputdark(img, chip, exptime):
hdu.close()
del inputdark
return img
"""
def
AddPreScan
(
GSImage
,
pre1
=
27
,
pre2
=
4
,
over1
=
71
,
over2
=
80
,
nsecy
=
2
,
nsecx
=
8
):
img
=
GSImage
.
array
ny
,
nx
=
img
.
shape
...
...
ObservationSim/sim_steps/add_pattern_noise.py
View file @
96e13f5a
...
...
@@ -10,8 +10,6 @@ def apply_PRNU(self, chip, filt, tel, pointing, catalog, obs_param):
def
add_poisson_and_dark
(
self
,
chip
,
filt
,
tel
,
pointing
,
catalog
,
obs_param
):
# Add dark current & Poisson noise
InputDark
=
False
# Get exposure time
if
(
obs_param
)
and
(
"exptime"
in
obs_param
)
and
(
obs_param
[
"exptime"
]
is
not
None
):
exptime
=
obs_param
[
"exptime"
]
...
...
@@ -19,15 +17,11 @@ def add_poisson_and_dark(self, chip, filt, tel, pointing, catalog, obs_param):
exptime
=
pointing
.
exp_time
if
obs_param
[
"add_dark"
]
==
True
:
if
InputDark
:
chip
.
img
=
chip_utils
.
add_inputdark
(
img
=
chip
.
img
,
chip
=
chip
,
exptime
=
exptime
)
else
:
chip
.
img
,
_
=
chip_utils
.
add_poisson
(
img
=
chip
.
img
,
chip
=
chip
,
exptime
=
exptime
,
poisson_noise
=
chip
.
poisson_noise
)
exptime
=
pointing
.
exp_time
,
poisson_noise
=
chip
.
poisson_noise
,
InputDark
=
None
)
else
:
chip
.
img
,
_
=
chip_utils
.
add_poisson
(
img
=
chip
.
img
,
chip
=
self
,
...
...
ObservationSim/sim_steps/readout_output.py
View file @
96e13f5a
...
...
@@ -12,6 +12,11 @@ def add_prescan_overscan(self, chip, filt, tel, pointing, catalog, obs_param):
pre2
=
chip
.
prescan_y
,
over1
=
chip
.
overscan_x
,
over2
=
chip
.
overscan_y
)
if
obs_param
[
"add_dark"
]
==
True
:
ny
=
int
(
chip
.
npix_y
/
2
)
base_dark
=
(
ny
-
1
)
*
(
chip
.
readout_time
/
ny
)
*
chip
.
dark_noise
chip
.
img
.
array
[(
chip
.
prescan_y
+
ny
):
-
(
chip
.
prescan_y
+
ny
),:]
=
bese_dark
return
chip
,
filt
,
tel
,
pointing
def
add_readout_noise
(
self
,
chip
,
filt
,
tel
,
pointing
,
catalog
,
obs_param
):
...
...
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