Skip to content
GitLab
Explore
Projects
Groups
Snippets
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
81e2570f
Commit
81e2570f
authored
1 year ago
by
Zhang Xin
Browse files
Options
Download
Email Patches
Plain Diff
fix unittest for ccd Effect model
parent
042e5887
release_v3.0
current_stable_for_tests
develop
master
milky_way_extinction
revert-914004c1
sim_scheduler
sls_psf_pca_convolve
v3.1.0
v3.0.0
1 merge request
!22
add field distortion test
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/det_effect_unit_test.py
+35
-25
tests/det_effect_unit_test.py
tests/testData/csst_fz_gc0/wfc-cr-attachpixel.dat
+42
-0
tests/testData/csst_fz_gc0/wfc-cr-attachpixel.dat
with
77 additions
and
25 deletions
+77
-25
tests/det_effect_unit_test.py
+
35
-
25
View file @
81e2570f
...
...
@@ -6,18 +6,28 @@ import matplotlib.pyplot as plt
import
os
,
sys
,
math
,
copy
from
numpy.random
import
Generator
,
PCG64
import
warnings
from
astropy.io
import
fits
warnings
.
filterwarnings
(
"ignore"
,
'.*Numba.*'
,)
width
=
9216
height
=
9232
if
os
.
path
.
isdir
(
'./output/'
):
pass
else
:
os
.
mkdir
(
'./output/'
)
class
DetTest
(
unittest
.
TestCase
):
def
__init__
(
self
,
methodName
=
'runTest'
):
super
(
DetTest
,
self
).
__init__
(
methodName
)
self
.
filePath
(
'csst_fz_gc0'
)
def
filePath
(
self
,
file_name
):
self
.
datafn
=
os
.
path
.
join
(
os
.
getenv
(
'UNIT_TEST_DATA_ROOT'
),
file_name
)
self
.
outDataFn
=
os
.
path
.
join
(
self
.
datafn
,
'output'
)
if
os
.
path
.
isdir
(
self
.
outDataFn
):
pass
else
:
os
.
mkdir
(
self
.
outDataFn
)
def
test_prnu
(
self
):
'''
Unit test for PRNU. Expected result: a randomized GS image contains PRNU with sigma=0.01, mean=1.
...
...
@@ -64,12 +74,12 @@ class DetTest(unittest.TestCase):
img
.
addNoise
(
galsim
.
GaussianNoise
(
sigma
=
7
))
# plt.imshow(img.array)
# plt.show()
filename1
=
os
.
path
.
join
(
'output'
,
'test_satu_initimg.fits'
)
filename1
=
os
.
path
.
join
(
self
.
outDataFn
,
'test_satu_initimg.fits'
)
img
.
write
(
filename1
)
newimg
=
Effects
.
SaturBloom
(
img
,
fullwell
=
9e4
)
# plt.imshow(newimg.array)
# plt.show()
filename2
=
os
.
path
.
join
(
'output'
,
'test_satu_bleedimg.fits'
)
filename2
=
os
.
path
.
join
(
self
.
outDataFn
,
'test_satu_bleedimg.fits'
)
newimg
.
write
(
filename2
)
del
img
,
newimg
,
star
...
...
@@ -79,16 +89,16 @@ class DetTest(unittest.TestCase):
'''
imgarr
=
np
.
arange
(
1
,
9e4
,
4
).
reshape
((
150
,
150
))
img
=
galsim
.
Image
(
copy
.
deepcopy
(
imgarr
))
filename1
=
os
.
path
.
join
(
'output'
,
'test_nonlinear_initimg.fits'
)
filename1
=
os
.
path
.
join
(
self
.
outDataFn
,
'test_nonlinear_initimg.fits'
)
img
.
write
(
filename1
)
newimg
=
Effects
.
NonLinearity
(
img
,
beta1
=
5E-7
,
beta2
=
0
)
filename2
=
os
.
path
.
join
(
'output'
,
'test_nonlinear_finalimg.fits'
)
filename2
=
os
.
path
.
join
(
self
.
outDataFn
,
'test_nonlinear_finalimg.fits'
)
newimg
.
write
(
filename2
)
plt
.
scatter
(
imgarr
.
flatten
(),
newimg
.
array
.
flatten
(),
s
=
2
,
alpha
=
0.5
)
plt
.
plot
([
-
1e3
,
9e4
],[
-
1e3
,
9e4
],
color
=
'black'
,
lw
=
1
,
ls
=
'--'
)
plt
.
xlabel
(
'input (e-)'
)
plt
.
ylabel
(
'output (e-)'
)
plt
.
savefig
(
'./output/
test_nonlinearity.png'
,
dpi
=
200
)
plt
.
savefig
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_nonlinearity.png'
)
,
dpi
=
200
)
plt
.
show
()
del
img
,
newimg
,
imgarr
...
...
@@ -97,35 +107,35 @@ class DetTest(unittest.TestCase):
rgbadpix
=
Generator
(
PCG64
(
20210911
))
badfraction
=
5E-5
*
(
rgbadpix
.
random
()
*
0.5
+
0.7
)
img
=
Effects
.
DefectivePixels
(
img
,
IfHotPix
=
True
,
IfDeadPix
=
True
,
fraction
=
badfraction
,
seed
=
20210911
,
biaslevel
=
0
)
img
.
write
(
'./output/
test_badpixel_HtrDtr.fits'
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_badpixel_HtrDtr.fits'
)
)
del
img
def
test_badpixel_HfsDtr
(
self
):
img
=
galsim
.
Image
(
500
,
500
,
init_value
=
1000
)
rgbadpix
=
Generator
(
PCG64
(
20210911
))
badfraction
=
5E-5
*
(
rgbadpix
.
random
()
*
0.5
+
0.7
)
img
=
Effects
.
DefectivePixels
(
img
,
IfHotPix
=
False
,
IfDeadPix
=
True
,
fraction
=
badfraction
,
seed
=
20210911
,
biaslevel
=
0
)
img
.
write
(
'./output/
test_badpixel_HfsDtr.fits'
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_badpixel_HfsDtr.fits'
)
)
del
img
def
test_badpixel_HtrDfs
(
self
):
img
=
galsim
.
Image
(
500
,
500
,
init_value
=
1000
)
rgbadpix
=
Generator
(
PCG64
(
20210911
))
badfraction
=
5E-5
*
(
rgbadpix
.
random
()
*
0.5
+
0.7
)
img
=
Effects
.
DefectivePixels
(
img
,
IfHotPix
=
True
,
IfDeadPix
=
False
,
fraction
=
badfraction
,
seed
=
20210911
,
biaslevel
=
0
)
img
.
write
(
'./output/
test_badpixel_HtrDfs.fits'
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_badpixel_HtrDfs.fits'
)
)
del
img
def
test_badpixel_HfsDfs
(
self
):
img
=
galsim
.
Image
(
500
,
500
,
init_value
=
1000
)
rgbadpix
=
Generator
(
PCG64
(
20210911
))
badfraction
=
5E-5
*
(
rgbadpix
.
random
()
*
0.5
+
0.7
)
img
=
Effects
.
DefectivePixels
(
img
,
IfHotPix
=
False
,
IfDeadPix
=
False
,
fraction
=
badfraction
,
seed
=
20210911
,
biaslevel
=
0
)
img
.
write
(
'./output/
test_badpixel_HfsDfs.fits'
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_badpixel_HfsDfs.fits'
)
)
del
img
def
test_badlines
(
self
):
img
=
galsim
.
Image
(
500
,
500
,
init_value
=-
1000
)
img
.
addNoise
(
galsim
.
GaussianNoise
(
sigma
=
7
))
newimg
=
Effects
.
BadColumns
(
copy
.
deepcopy
(
img
),
seed
=
20210911
)
newimg
.
write
(
'./output/
test_badlines.fits'
)
newimg
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_badlines.fits'
)
)
del
newimg
,
img
def
test_cte
(
self
):
...
...
@@ -134,8 +144,8 @@ class DetTest(unittest.TestCase):
img
.
array
[
150
,
150
]
=
3e4
newimgcol
=
Effects
.
CTE_Effect
(
copy
.
deepcopy
(
img
),
direction
=
'column'
)
newimgrow
=
Effects
.
CTE_Effect
(
copy
.
deepcopy
(
img
),
direction
=
'row'
)
newimgcol
.
write
(
'./output/
test_ctecol.fits'
)
newimgrow
.
write
(
'./output/
test_cterow.fits'
)
newimgcol
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_ctecol.fits'
)
)
newimgrow
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_cterow.fits'
)
)
del
img
,
newimgcol
,
newimgrow
def
test_readnoise
(
self
):
...
...
@@ -144,7 +154,7 @@ class DetTest(unittest.TestCase):
rng_readout
=
galsim
.
BaseDeviate
(
seed
)
readout_noise
=
galsim
.
GaussianNoise
(
rng
=
rng_readout
,
sigma
=
5
)
img
.
addNoise
(
readout_noise
)
img
.
write
(
'./output/
test_readnoise.fits'
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_readnoise.fits'
)
)
stdval
=
np
.
std
(
img
.
array
)
self
.
assertTrue
(
np
.
abs
(
stdval
-
5
)
<
0.01
*
5
)
print
(
'
\n
Unit test for readout noise has been passed.'
)
...
...
@@ -158,8 +168,8 @@ class DetTest(unittest.TestCase):
def
test_apply16gains
(
self
):
img
=
galsim
.
Image
(
500
,
500
,
init_value
=
100
)
img
=
Effects
.
ApplyGainNonUniform16
(
img
,
gain
=
1.5
,
nsecy
=
2
,
nsecx
=
8
,
seed
=
202102
)
img
.
write
(
"./output/
test_apply16gains.fits
"
)
img
,
_
=
Effects
.
ApplyGainNonUniform16
(
img
,
gain
=
1.5
,
nsecy
=
2
,
nsecx
=
8
,
seed
=
202102
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_apply16gains.fits
'
)
)
rightedge
=
int
(
500
/
8
)
*
8
print
(
'gain=%6.2f'
%
1.5
)
meanimg
=
np
.
mean
(
img
.
array
[:,:
rightedge
])
...
...
@@ -172,20 +182,20 @@ class DetTest(unittest.TestCase):
def
test_cosmicray
(
self
):
attachedSizes
=
np
.
loadtxt
(
'../ObservationSim/Instrument/Chip/
wfc-cr-attachpixel.dat'
)
cr_map
=
Effects
.
produceCR_Map
(
attachedSizes
=
np
.
loadtxt
(
os
.
path
.
join
(
self
.
datafn
,
'
wfc-cr-attachpixel.dat'
)
)
cr_map
,
_
=
Effects
.
produceCR_Map
(
xLen
=
500
,
yLen
=
500
,
exTime
=
150
+
0.5
*
40
,
cr_pixelRatio
=
0.003
*
(
1
+
0.5
*
40
/
150
),
gain
=
1
,
attachedSizes
=
attachedSizes
,
seed
=
20210911
)
crimg
=
galsim
.
Image
(
cr_map
)
crimg
.
write
(
'./output/
test_cosmicray.fits'
)
crimg
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_cosmicray.fits'
)
)
del
cr_map
,
crimg
def
test_shutter
(
self
):
img
=
galsim
.
Image
(
5000
,
5000
,
init_value
=
1000
)
shuttimg
=
Effects
.
ShutterEffectArr
(
img
,
t_exp
=
150
,
t_shutter
=
1.3
,
dist_bearing
=
735
,
dt
=
1E-3
)
# shutter effect normalized image for this chip
img
*=
shuttimg
img
.
write
(
'./output/
test_shutter.fits'
)
img
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_shutter.fits'
)
)
del
img
def
test_vignette
(
self
):
...
...
@@ -195,7 +205,7 @@ class DetTest(unittest.TestCase):
img
.
setOrigin
(
10000
,
10000
)
flat_img
=
Effects
.
MakeFlatSmooth
(
img
.
bounds
,
20210911
)
flat_normal
=
flat_img
/
np
.
mean
(
flat_img
.
array
)
flat_normal
.
write
(
'./output/
test_vignette.fits'
)
flat_normal
.
write
(
os
.
path
.
join
(
self
.
outDataFn
,
'
test_vignette.fits'
)
)
del
flat_img
,
img
,
flat_normal
...
...
This diff is collapsed.
Click to expand it.
tests/testData/csst_fz_gc0/wfc-cr-attachpixel.dat
0 → 100755
+
42
-
0
View file @
81e2570f
# Graph from wfc-cr-attach, page 1
0.00000 0.004684
0.5031 0.004684
0.5283 0.01873
1.509 0.01873
1.534 0.09327
2.490 0.09327
2.515 0.1034
3.496 0.1034
3.522 0.2440
4.503 0.2440
4.528 0.1107
5.509 0.1107
5.534 0.1013
6.490 0.1013
6.515 0.06090
7.496 0.06090
7.522 0.05834
8.503 0.05834
8.528 0.03875
9.509 0.03875
9.534 0.03066
10.49 0.03066
10.51 0.01788
11.47 0.01788
11.49 0.01831
13.50 0.01831
13.53 0.01235
13.53 0.01235
14.49 0.01235
14.51 0.01064
15.49 0.01064
15.52 0.008091
16.50 0.008091
16.52 0.004684
17.48 0.004684
17.53 0.003833
18.49 0.003833
18.51 0.005536
19.47 0.005536
19.52 0.004684
20.00 0.004684
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets