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
221f50ea
Commit
221f50ea
authored
Apr 08, 2024
by
Fang Yuedong
Browse files
move catalog initialization into add_objects.py
parent
98579c7c
Changes
8
Show whitespace changes
Inline
Side-by-side
Catalog/C6_50sqdeg.py
View file @
221f50ea
...
...
@@ -71,7 +71,7 @@ class Catalog(CatalogBase):
def
__init__
(
self
,
config
,
chip
,
pointing
,
chip_output
,
filt
,
**
kwargs
):
super
().
__init__
()
self
.
cat_dir
=
os
.
path
.
join
(
config
[
"data_dir"
],
config
[
"catalog_options"
][
"input_path"
][
"cat_dir"
])
self
.
seed_Av
=
config
[
"catalog_options"
][
"seed_Av"
]
#
self.seed_Av = config["catalog_options"]["seed_Av"]
self
.
cosmo
=
FlatLambdaCDM
(
H0
=
67.66
,
Om0
=
0.3111
)
...
...
ObservationSim/ObservationSim.py
View file @
221f50ea
...
...
@@ -93,7 +93,7 @@ class Observation(object):
chip
=
self
.
prepare_chip_for_exposure
(
chip
,
ra_cen
,
dec_cen
,
pointing
)
# Load catalogues
self
.
cat
=
self
.
Catalog
(
config
=
self
.
config
,
chip
=
chip
,
pointing
=
pointing
,
cat_dir
=
cat_dir
,
sed_dir
=
sed_dir
,
chip_output
=
chip_output
,
filt
=
filt
)
#
self.cat = self.Catalog(config=self.config, chip=chip, pointing=pointing, cat_dir=cat_dir, sed_dir=sed_dir, chip_output=chip_output, filt=filt)
# Initialize SimSteps
sim_steps
=
SimSteps
(
overall_config
=
self
.
config
,
chip_output
=
chip_output
,
all_filters
=
self
.
all_filters
)
...
...
@@ -112,7 +112,7 @@ class Observation(object):
filt
=
filt
,
tel
=
self
.
tel
,
pointing
=
pointing
,
catalog
=
self
.
c
at
,
catalog
=
self
.
C
at
alog
,
obs_param
=
obs_param
)
chip_output
.
Log_info
(
"Finished simulation step: %s"
%
(
step
))
except
Exception
as
e
:
...
...
ObservationSim/_util.py
View file @
221f50ea
...
...
@@ -13,7 +13,7 @@ def parse_args():
'''
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--config_file'
,
type
=
str
,
required
=
True
,
help
=
'.yaml config file for simulation settings.'
)
parser
.
add_argument
(
'--catalog'
,
type
=
str
,
required
=
True
,
help
=
'name of the catalog interface class to be loaded.'
)
parser
.
add_argument
(
'--catalog'
,
type
=
str
,
help
=
'name of the catalog interface class to be loaded.'
)
parser
.
add_argument
(
'-c'
,
'--config_dir'
,
type
=
str
,
help
=
'Directory that houses the .yaml config file.'
)
parser
.
add_argument
(
'-d'
,
'--data_dir'
,
type
=
str
,
help
=
'Directory that houses the input data.'
)
parser
.
add_argument
(
'-w'
,
'--work_dir'
,
type
=
str
,
help
=
'The path for output.'
)
...
...
ObservationSim/sim_steps/add_objects.py
View file @
221f50ea
...
...
@@ -12,6 +12,12 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
# Prepare output file(s) for this chip
self
.
chip_output
.
create_output_file
()
# Load catalogues
if
catalog
is
None
:
self
.
chip_output
.
Log_error
(
"Catalog interface class must be specified for SCIE-OBS"
)
raise
ValueError
(
"Catalog interface class must be specified for SCIE-OBS"
)
cat
=
catalog
(
config
=
self
.
overall_config
,
chip
=
chip
,
pointing
=
pointing
,
chip_output
=
self
.
chip_output
,
filt
=
filt
)
# Prepare the PSF model
if
self
.
overall_config
[
"psf_setting"
][
"psf_model"
]
==
"Gauss"
:
psf_model
=
PSFGauss
(
chip
=
chip
,
psfRa
=
self
.
overall_config
[
"psf_setting"
][
"psf_rcont"
])
...
...
@@ -48,7 +54,7 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
chip_wcs
=
galsim
.
FitsWCS
(
header
=
self
.
h_ext
)
# Loop over objects
nobj
=
len
(
cat
alog
.
objs
)
nobj
=
len
(
cat
.
objs
)
missed_obj
=
0
bright_obj
=
0
dim_obj
=
0
...
...
@@ -56,19 +62,19 @@ def add_objects(self, chip, filt, tel, pointing, catalog, obs_param):
# # [DEBUG] [TODO]
# if j >= 10:
# break
obj
=
cat
alog
.
objs
[
j
]
obj
=
cat
.
objs
[
j
]
# load and convert SED; also caculate object's magnitude in all CSST bands
try
:
sed_data
=
cat
alog
.
load_sed
(
obj
)
norm_filt
=
cat
alog
.
load_norm_filt
(
obj
)
obj
.
sed
,
obj
.
param
[
"mag_%s"
%
filt
.
filter_type
.
lower
()],
obj
.
param
[
"flux_%s"
%
filt
.
filter_type
.
lower
()]
=
cat
alog
.
convert_sed
(
sed_data
=
cat
.
load_sed
(
obj
)
norm_filt
=
cat
.
load_norm_filt
(
obj
)
obj
.
sed
,
obj
.
param
[
"mag_%s"
%
filt
.
filter_type
.
lower
()],
obj
.
param
[
"flux_%s"
%
filt
.
filter_type
.
lower
()]
=
cat
.
convert_sed
(
mag
=
obj
.
param
[
"mag_use_normal"
],
sed
=
sed_data
,
target_filt
=
filt
,
norm_filt
=
norm_filt
,
)
_
,
obj
.
param
[
"mag_%s"
%
cut_filter
.
filter_type
.
lower
()],
obj
.
param
[
"flux_%s"
%
cut_filter
.
filter_type
.
lower
()]
=
cat
alog
.
convert_sed
(
_
,
obj
.
param
[
"mag_%s"
%
cut_filter
.
filter_type
.
lower
()],
obj
.
param
[
"flux_%s"
%
cut_filter
.
filter_type
.
lower
()]
=
cat
.
convert_sed
(
mag
=
obj
.
param
[
"mag_use_normal"
],
sed
=
sed_data
,
target_filt
=
cut_filter
,
...
...
ObservationSim/sim_steps/add_pattern_noise.py
View file @
221f50ea
...
...
@@ -4,6 +4,8 @@ from ObservationSim.Instrument.Chip import Effects
def
apply_PRNU
(
self
,
chip
,
filt
,
tel
,
pointing
,
catalog
,
obs_param
):
chip
.
img
*=
chip
.
prnu_img
if
self
.
overall_config
[
"output_setting"
][
"prnu_output"
]
==
True
:
chip
.
prnu_img
.
write
(
"%s/FlatImg_PRNU_%s.fits"
%
(
self
.
chip_output
.
subdir
,
chip
.
chipID
))
return
chip
,
filt
,
tel
,
pointing
def
add_poisson_and_dark
(
self
,
chip
,
filt
,
tel
,
pointing
,
catalog
,
obs_param
):
...
...
ObservationSim/sim_steps/add_sky_background.py
View file @
221f50ea
...
...
@@ -60,6 +60,9 @@ def add_sky_flat_calibration(self, chip, filt, tel, pointing, catalog, obs_param
if
obs_param
[
"shutter_effect"
]
==
True
:
flat_normal
=
flat_normal
*
chip
.
shutter_img
flat_normal
=
np
.
array
(
flat_normal
,
dtype
=
'float32'
)
if
self
.
overall_config
[
"output_setting"
][
"shutter_output"
]
==
True
:
# output 16-bit shutter effect image with pixel value <=65535
shutt_gsimg
=
galsim
.
ImageUS
(
chip
.
shutter_img
*
6E4
)
shutt_gsimg
.
write
(
"%s/ShutterEffect_%s_1.fits"
%
(
self
.
chip_output
.
subdir
,
chip
.
chipID
))
if
chip
.
survey_type
==
"photometric"
:
...
...
config/config_overall.yaml
View file @
221f50ea
...
...
@@ -21,14 +21,11 @@ run_counter: 1
# Run options
run_option
:
use_mpi
:
NO
# NOTE: "n_threads" paramters is currently not used in the backend
# simulation codes. It should be implemented later in the web frontend
# in order to config the number of threads to request from NAOC cluster
n_threads
:
80
# Output catalog only?
# If yes, no imaging simulation will run
out_cat_only
:
YES
# If yes, no imaging simulation will be run. Only the catalogs
# of corresponding footprints will be generated.
out_cat_only
:
NO
###############################################
# Catalog setting
...
...
@@ -55,10 +52,10 @@ catalog_options:
# Only simulate galaxies?
galaxy_only
:
YES
# rotate galaxy ellipticity
rotateEll
:
0.
# [degree]
#
#
rotate galaxy ellipticity
#
rotateEll: 0. # [degree]
seed_Av
:
121212
# Seed for generating random intrinsic extinction
#
seed_Av: 121212 # Seed for generating random intrinsic extinction
###############################################
# Observation setting
...
...
@@ -133,8 +130,8 @@ shear_setting:
###############################################
output_setting
:
output_format
:
"
channels"
# Whether to export as 16 channels (subimages) with pre- and over-scan ("image"/"channels")
shutter_output
:
O
FF
# Whether to export shutter effect 16-bit image
prnu_output
:
O
FF
# Whether to export the PRNU (pixel-to-pixel flat-fielding) files
shutter_output
:
N
O
# Whether to export shutter effect 16-bit image
prnu_output
:
N
O
# Whether to export the PRNU (pixel-to-pixel flat-fielding) files
###############################################
# Random seeds
...
...
run_sim.py
View file @
221f50ea
...
...
@@ -83,7 +83,10 @@ def run_sim():
config_out
.
write
(
"###############################################
\n
"
)
# Initialize the simulation
if
args
.
catalog
is
not
None
:
catalog_module
=
importlib
.
import_module
(
'Catalog.'
+
args
.
catalog
)
else
:
catalog_module
=
None
obs
=
Observation
(
config
=
config
,
Catalog
=
catalog_module
.
Catalog
,
work_dir
=
config
[
'work_dir'
],
data_dir
=
config
[
'data_dir'
])
# Run simulation
...
...
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