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
12c472cf
Commit
12c472cf
authored
Apr 05, 2024
by
Wei Chengliang
Browse files
init tools/getPSF.py
parent
fbbd7902
Changes
1
Show whitespace changes
Inline
Side-by-side
tools/getPSF.py
0 → 100644
View file @
12c472cf
import
os
import
numpy
as
np
import
ObservationSim.PSF.PSFInterp
as
PSFInterp
from
ObservationSim.Instrument
import
Chip
,
Filter
,
FilterParam
import
yaml
import
galsim
import
astropy.io.fits
as
fitsio
# Setup PATH
SIMPATH
=
"/share/simudata/CSSOSDataProductsSims/data/CSSTSimImage_C8/testRun_FGS"
config_filename
=
SIMPATH
+
"/config_C6_fits.yaml"
cat_filename
=
SIMPATH
+
"/MSC_00000000/MSC_10106100000000_chip_40_filt_FGS.cat"
# Read cat file
catFn
=
open
(
cat_filename
,
"r"
)
line
=
catFn
.
readline
()
print
(
cat_filename
,
'
\n
'
,
line
)
imgPos
=
[]
chipID
=
-
1
for
line
in
catFn
:
line
=
line
.
strip
()
columns
=
line
.
split
()
if
chipID
==
-
1
:
chipID
=
int
(
columns
[
1
])
else
:
assert
chipID
==
int
(
columns
[
1
])
ximg
=
float
(
columns
[
3
])
yimg
=
float
(
columns
[
4
])
imgPos
.
append
([
ximg
,
yimg
])
imgPos
=
np
.
array
(
imgPos
)
nobj
=
imgPos
.
shape
[
0
]
print
(
'chipID, nobj::'
,
chipID
,
nobj
)
# Read config file
with
open
(
config_filename
,
"r"
)
as
stream
:
try
:
config
=
yaml
.
safe_load
(
stream
)
for
key
,
value
in
config
.
items
():
print
(
key
+
" : "
+
str
(
value
))
except
yaml
.
YAMLError
as
exc
:
print
(
exc
)
# Setup Chip
chip
=
Chip
(
chipID
=
chipID
,
config
=
config
)
print
(
'chip.bound::'
,
chip
.
bound
.
xmin
,
chip
.
bound
.
xmax
,
chip
.
bound
.
ymin
,
chip
.
bound
.
ymax
)
for
iobj
in
range
(
nobj
):
print
(
"
\n
get psf for iobj-"
,
iobj
,
'
\t
'
,
'bandpass:'
,
end
=
" "
,
flush
=
True
)
# Setup Position on focalplane
x
,
y
=
imgPos
[
iobj
,
:]
# try get the PSF at some location (1234, 1234) on the chip
x
=
x
+
chip
.
bound
.
xmin
y
=
y
+
chip
.
bound
.
ymin
pos_img
=
galsim
.
PositionD
(
x
,
y
)
# Setup sub-bandpass
# (There are 4 sub-bandpasses for each PSF sample)
filter_param
=
FilterParam
()
filter_id
,
filter_type
=
chip
.
getChipFilter
()
filt
=
Filter
(
filter_id
=
filter_id
,
filter_type
=
filter_type
,
filter_param
=
filter_param
,
ccd_bandpass
=
chip
.
effCurve
)
bandpass_list
=
filt
.
bandpass_sub_list
for
i
in
range
(
len
(
bandpass_list
)):
print
(
i
,
end
=
" "
,
flush
=
True
)
bandpass
=
bandpass_list
[
i
]
# say you want to access the PSF for the sub-bandpass at the blue end for that chip
# Get corresponding PSF model
psf_model
=
PSFInterp
(
chip
=
chip
,
npsf
=
100
,
PSF_data_file
=
config
[
"psf_setting"
][
"psf_dir"
])
psf
=
psf_model
.
get_PSF
(
chip
=
chip
,
pos_img
=
pos_img
,
bandpass
=
bandpass
,
galsimGSObject
=
False
)
if
True
:
fn
=
"psf_{:}.{:}.{:}.fits"
.
format
(
chipID
,
iobj
,
i
)
if
fn
!=
None
:
if
os
.
path
.
exists
(
fn
):
os
.
remove
(
fn
)
hdu
=
fitsio
.
PrimaryHDU
()
hdu
.
data
=
psf
hdu
.
header
.
set
(
'pixScale'
,
5
)
hdu
.
writeto
(
fn
)
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