Commit df22b3b0 authored by Fang Yuedong's avatar Fang Yuedong
Browse files

Merge branch 'master' into 'release_v3.0'

Release version v3.2.0

See merge request !33
parents 1b4f4012 428f2c1e
...@@ -79,7 +79,7 @@ for iobj in range(nobj): ...@@ -79,7 +79,7 @@ for iobj in range(nobj):
if True: if True:
fn = "psf_{:}.{:}.{:}.fits".format(chipID, iobj, i) fn = "psf_{:}.{:}.{:}.fits".format(chipID, iobj, i)
if fn != None: if fn is not None:
if os.path.exists(fn): if os.path.exists(fn):
os.remove(fn) os.remove(fn)
hdu = fitsio.PrimaryHDU() hdu = fitsio.PrimaryHDU()
......
...@@ -25,6 +25,7 @@ import galsim ...@@ -25,6 +25,7 @@ import galsim
import math import math
# from numba import jit # from numba import jit
class Chip(object): class Chip(object):
def __init__(self, chipID): def __init__(self, chipID):
self.chipID = chipID self.chipID = chipID
...@@ -43,7 +44,7 @@ class Chip(object): ...@@ -43,7 +44,7 @@ class Chip(object):
self.npix_y = 9232 self.npix_y = 9232
self.pix_scale = 0.074 self.pix_scale = 0.074
def getTanWCS(self, ra, dec, img_rot, pix_scale = None, xcen=None, ycen=None, logger=None): def getTanWCS(self, ra, dec, img_rot, pix_scale=None, xcen=None, ycen=None, logger=None):
""" Get the WCS of the image mosaic using Gnomonic/TAN projection """ Get the WCS of the image mosaic using Gnomonic/TAN projection
Parameter: Parameter:
...@@ -57,11 +58,12 @@ class Chip(object): ...@@ -57,11 +58,12 @@ class Chip(object):
WCS of the focal plane WCS of the focal plane
""" """
if logger is not None: if logger is not None:
logger.info(" Construct the wcs of the entire image mosaic using Gnomonic/TAN projection") logger.info(
if (xcen == None) or (ycen == None): " Construct the wcs of the entire image mosaic using Gnomonic/TAN projection")
if (xcen is None) or (ycen is None):
xcen = self.cen_pix_x xcen = self.cen_pix_x
ycen = self.cen_pix_y ycen = self.cen_pix_y
if pix_scale == None: if pix_scale is None:
pix_scale = self.pix_scale pix_scale = self.pix_scale
# dudx = -np.cos(img_rot.rad) * pix_scale # dudx = -np.cos(img_rot.rad) * pix_scale
# dudy = -np.sin(img_rot.rad) * pix_scale # dudy = -np.sin(img_rot.rad) * pix_scale
...@@ -78,7 +80,8 @@ class Chip(object): ...@@ -78,7 +80,8 @@ class Chip(object):
# dvdx = -np.cos(img_rot.rad) * pix_scale # dvdx = -np.cos(img_rot.rad) * pix_scale
# dvdy = +np.sin(img_rot.rad) * pix_scale # dvdy = +np.sin(img_rot.rad) * pix_scale
moscen = galsim.PositionD(x=xcen, y=ycen) moscen = galsim.PositionD(x=xcen, y=ycen)
sky_center = galsim.CelestialCoord(ra=ra*galsim.degrees, dec=dec*galsim.degrees) sky_center = galsim.CelestialCoord(
ra=ra*galsim.degrees, dec=dec*galsim.degrees)
affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen) affine = galsim.AffineTransform(dudx, dudy, dvdx, dvdy, origin=moscen)
WCS = galsim.TanWCS(affine, sky_center, units=galsim.arcsec) WCS = galsim.TanWCS(affine, sky_center, units=galsim.arcsec)
...@@ -99,8 +102,6 @@ class Chip(object): ...@@ -99,8 +102,6 @@ class Chip(object):
A galsim BoundsD object A galsim BoundsD object
""" """
chipID = self.chipID chipID = self.chipID
rowID, colID = self.getChipRowCol(chipID) rowID, colID = self.getChipRowCol(chipID)
...@@ -125,36 +126,41 @@ class Chip(object): ...@@ -125,36 +126,41 @@ class Chip(object):
return galsim.PositionD(xcen, ycen) return galsim.PositionD(xcen, ycen)
def transRaDec2D(ra, dec): def transRaDec2D(ra, dec):
x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795); x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795)
y1 = np.cos(dec / 57.2957795) * np.sin(ra / 57.2957795); y1 = np.cos(dec / 57.2957795) * np.sin(ra / 57.2957795)
z1 = np.sin(dec / 57.2957795); z1 = np.sin(dec / 57.2957795)
return np.array([x1, y1, z1]) return np.array([x1, y1, z1])
def getobsPA(ra, dec): def getobsPA(ra, dec):
l1 = np.array([0,0,1]) l1 = np.array([0, 0, 1])
l2 = transRaDec2D(ra, dec) l2 = transRaDec2D(ra, dec)
polar_ec = coord.SkyCoord(0*u.degree, 90*u.degree,frame='barycentrictrueecliptic') polar_ec = coord.SkyCoord(0*u.degree, 90*u.degree,
frame='barycentrictrueecliptic')
polar_eq = polar_ec.transform_to('icrs') polar_eq = polar_ec.transform_to('icrs')
# print(polar_eq.ra.value,polar_eq.dec.value) # print(polar_eq.ra.value,polar_eq.dec.value)
polar_d = transRaDec2D(polar_eq.ra.value, polar_eq.dec.value) polar_d = transRaDec2D(polar_eq.ra.value, polar_eq.dec.value)
l1l2cross = np.cross(l2,l1) l1l2cross = np.cross(l2, l1)
pdl2cross = np.cross(l2,polar_d) pdl2cross = np.cross(l2, polar_d)
angle = math.acos(np.dot(l1l2cross,pdl2cross)/(np.linalg.norm(l1l2cross)*np.linalg.norm(pdl2cross))) angle = math.acos(np.dot(l1l2cross, pdl2cross) /
(np.linalg.norm(l1l2cross)*np.linalg.norm(pdl2cross)))
angle = (angle)/math.pi*180 angle = (angle)/math.pi*180
angle = angle + 90 angle = angle + 90
if (ra<90 or ra> 270): if (ra < 90 or ra > 270):
angle=-angle angle = -angle
return angle return angle
# @jit() # @jit()
def getSelectPointingList(center = [60,-40], radius = 2):
points = np.loadtxt('sky.dat')
center = center#ra dec def getSelectPointingList(center=[60, -40], radius=2):
points = np.loadtxt('sky.dat')
center = center # ra dec
radius = radius # degree radius = radius # degree
radii_dec = 1 radii_dec = 1
...@@ -163,7 +169,8 @@ def getSelectPointingList(center = [60,-40], radius = 2): ...@@ -163,7 +169,8 @@ def getSelectPointingList(center = [60,-40], radius = 2):
if radii_ra > 180: if radii_ra > 180:
radii_ra = 180 radii_ra = 180
c_eclip = coord.SkyCoord(points[:,2]*u.degree, points[:,1]*u.degree,frame='barycentrictrueecliptic') c_eclip = coord.SkyCoord(
points[:, 2]*u.degree, points[:, 1]*u.degree, frame='barycentrictrueecliptic')
c_equtor = c_eclip.transform_to('icrs') c_equtor = c_eclip.transform_to('icrs')
# print(np.min((c_equtor.ra*u.degree).value), np.max((c_equtor.ra*u.degree).value)) # print(np.min((c_equtor.ra*u.degree).value), np.max((c_equtor.ra*u.degree).value))
...@@ -174,13 +181,15 @@ def getSelectPointingList(center = [60,-40], radius = 2): ...@@ -174,13 +181,15 @@ def getSelectPointingList(center = [60,-40], radius = 2):
ra_range_lo = center[0]-radii_ra ra_range_lo = center[0]-radii_ra
ra_range_hi = center[0]+radii_ra ra_range_hi = center[0]+radii_ra
if ra_range_lo< 0: if ra_range_lo < 0:
ids1 = ((c_equtor.ra*u.degree).value<ra_range_hi) | ((c_equtor.ra*u.degree).value>360+ra_range_lo) ids1 = ((c_equtor.ra*u.degree).value <
ra_range_hi) | ((c_equtor.ra*u.degree).value > 360+ra_range_lo)
elif ra_range_hi > 360: elif ra_range_hi > 360:
ids1 = ((c_equtor.ra*u.degree).value>ra_range_lo) | ((c_equtor.ra*u.degree).value<ra_range_hi-360) ids1 = ((c_equtor.ra*u.degree).value >
ra_range_lo) | ((c_equtor.ra*u.degree).value < ra_range_hi-360)
else: else:
ids1 = ((c_equtor.ra*u.degree).value > ra_range_lo) & ((c_equtor.ra*u.degree).value < ra_range_hi) ids1 = ((c_equtor.ra*u.degree).value >
ra_range_lo) & ((c_equtor.ra*u.degree).value < ra_range_hi)
dec_range_lo = center[1]-radii_dec dec_range_lo = center[1]-radii_dec
if center[1]-radii_dec < -90: if center[1]-radii_dec < -90:
...@@ -198,25 +207,24 @@ def getSelectPointingList(center = [60,-40], radius = 2): ...@@ -198,25 +207,24 @@ def getSelectPointingList(center = [60,-40], radius = 2):
p_result = np.zeros([num, 5]) p_result = np.zeros([num, 5])
i = 0 i = 0
for p,p_ in zip(points[ids1][ids3][ids4],c_equtor[ids1][ids3][ids4]): for p, p_ in zip(points[ids1][ids3][ids4], c_equtor[ids1][ids3][ids4]):
ra = (p_.ra*u.degree).value ra = (p_.ra*u.degree).value
dec = (p_.dec*u.degree).value dec = (p_.dec*u.degree).value
# print(ra, dec) # print(ra, dec)
lon = p[2] lon = p[2]
lat = p[1] lat = p[1]
p_result[i,0] = ra p_result[i, 0] = ra
p_result[i,1] = dec p_result[i, 1] = dec
p_result[i,2] = lon p_result[i, 2] = lon
p_result[i,3] = lat p_result[i, 3] = lat
p_result[i,4] = getobsPA(ra, dec) + 90 p_result[i, 4] = getobsPA(ra, dec) + 90
i = i + 1 i = i + 1
return p_result return p_result
def findPointingbyChipID(chipID=8, ra=60., dec=-40.):
def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.):
"""_summary_ """_summary_
Args: Args:
...@@ -228,7 +236,7 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.): ...@@ -228,7 +236,7 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.):
_type_: [ra, dec, rotation angle] _type_: [ra, dec, rotation angle]
""" """
chip_center = [ra, dec] chip_center = [ra, dec]
p_list = getSelectPointingList(center = chip_center) p_list = getSelectPointingList(center=chip_center)
pchip = Chip(chipID) pchip = Chip(chipID)
p_num = p_list.shape[0] p_num = p_list.shape[0]
...@@ -238,10 +246,10 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.): ...@@ -238,10 +246,10 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.):
r_ra = ra r_ra = ra
r_dec = dec r_dec = dec
r_rot = 0. r_rot = 0.
for i in np.arange(0,p_num,1): for i in np.arange(0, p_num, 1):
ra_n = p_list[i,0] ra_n = p_list[i, 0]
dec_n = p_list[i,1] dec_n = p_list[i, 1]
rot = p_list[i,4]*galsim.degrees rot = p_list[i, 4]*galsim.degrees
chip_wcs = pchip.getTanWCS(ra_n, dec_n, rot) chip_wcs = pchip.getTanWCS(ra_n, dec_n, rot)
c_center = pchip.getChipCenter() c_center = pchip.getChipCenter()
...@@ -259,13 +267,12 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.): ...@@ -259,13 +267,12 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.):
r_rot = rot.deg r_rot = rot.deg
if min_d == max_value: if min_d == max_value:
print("RA:%f,Dec:%f不在指向范围内,请于巡天规划序列比对!!!!!"%(ra, dec)) print("RA:%f,Dec:%f不在指向范围内,请于巡天规划序列比对!!!!!" % (ra, dec))
return [r_ra, r_dec , r_rot] return [r_ra, r_dec, r_rot]
if __name__ == "__main__": if __name__ == "__main__":
tchip, tra, tdec = 13, 60., -40. tchip, tra, tdec = 13, 60., -40.
pointing = findPointingbyChipID(chipID=tchip, ra=tra, dec=tdec) pointing = findPointingbyChipID(chipID=tchip, ra=tra, dec=tdec)
print("[ra_center, dec_center, image_rot]: ", pointing) print("[ra_center, dec_center, image_rot]: ", pointing)
from pylab import * from pylab import *
import math, sys, numpy as np import math
import sys
import numpy as np
import astropy.coordinates as coord import astropy.coordinates as coord
from astropy.coordinates import SkyCoord from astropy.coordinates import SkyCoord
from astropy import wcs, units as u from astropy import wcs, units as u
...@@ -14,8 +16,9 @@ def transRaDec2D(ra, dec): ...@@ -14,8 +16,9 @@ def transRaDec2D(ra, dec):
z1 = np.sin(dec / 57.2957795) z1 = np.sin(dec / 57.2957795)
return np.array([x1, y1, z1]) return np.array([x1, y1, z1])
def ecl2radec(lon_ecl, lat_ecl): def ecl2radec(lon_ecl, lat_ecl):
## convert from ecliptic coordinates to equatorial coordinates # convert from ecliptic coordinates to equatorial coordinates
c_ecl = SkyCoord( c_ecl = SkyCoord(
lon=lon_ecl * u.degree, lat=lat_ecl * u.degree, frame="barycentrictrueecliptic" lon=lon_ecl * u.degree, lat=lat_ecl * u.degree, frame="barycentrictrueecliptic"
) )
...@@ -25,18 +28,19 @@ def ecl2radec(lon_ecl, lat_ecl): ...@@ -25,18 +28,19 @@ def ecl2radec(lon_ecl, lat_ecl):
def radec2ecl(ra, dec): def radec2ecl(ra, dec):
## convert from equatorial coordinates to ecliptic coordinates # convert from equatorial coordinates to ecliptic coordinates
c_eq = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame="icrs") c_eq = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame="icrs")
c_ecl = c_eq.transform_to("barycentrictrueecliptic") c_ecl = c_eq.transform_to("barycentrictrueecliptic")
lon_ecl, lat_ecl = c_ecl.lon.degree, c_ecl.lat.degree lon_ecl, lat_ecl = c_ecl.lon.degree, c_ecl.lat.degree
return lon_ecl, lat_ecl return lon_ecl, lat_ecl
def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID = 1, pa = -23.5):
### [ra_FieldCenter, dec_FieldCenter] is the center ra, dec of calibration fileds, such as: NEP, NGC 6397, etc. def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID=1, pa=-23.5):
### [ra_ChipCenter, dec_ChipCenter] is the center ra, dec of the Chip center.
### [ra_PointCenter, dec_PointCenter] is the telescope pointing center. # [ra_FieldCenter, dec_FieldCenter] is the center ra, dec of calibration fileds, such as: NEP, NGC 6397, etc.
## Calculate PA angle # [ra_ChipCenter, dec_ChipCenter] is the center ra, dec of the Chip center.
# [ra_PointCenter, dec_PointCenter] is the telescope pointing center.
# Calculate PA angle
chip = Chip(chipID) chip = Chip(chipID)
h_ext = ImageHeader.generateExtensionHeader( h_ext = ImageHeader.generateExtensionHeader(
...@@ -75,17 +79,18 @@ def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID = 1, pa ...@@ -75,17 +79,18 @@ def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID = 1, pa
return ra_PointCenter, dec_PointCenter, lon_ecl_PointCenter, lat_ecl_PointCenter return ra_PointCenter, dec_PointCenter, lon_ecl_PointCenter, lat_ecl_PointCenter
def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID = 1, pa = -23.5):
### [ra_FieldCenter, dec_FieldCenter] is the center ra, dec of calibration fileds, such as: NEP, NGC 6397, etc. def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID=1, pa=-23.5):
### [ra_ChipCenter, dec_ChipCenter] is the center ra, dec of the Chip center.
### [ra_PointCenter, dec_PointCenter] is the telescope pointing center. # [ra_FieldCenter, dec_FieldCenter] is the center ra, dec of calibration fileds, such as: NEP, NGC 6397, etc.
# [ra_ChipCenter, dec_ChipCenter] is the center ra, dec of the Chip center.
# [ra_PointCenter, dec_PointCenter] is the telescope pointing center.
ra_FieldCenter, dec_FieldCenter = ecl2radec( ra_FieldCenter, dec_FieldCenter = ecl2radec(
lon_ecl_FieldCenter, lat_ecl_FieldCenter lon_ecl_FieldCenter, lat_ecl_FieldCenter
) )
## Calculate PA angle # Calculate PA angle
chip = Chip(chipID) chip = Chip(chipID)
h_ext = ImageHeader.generateExtensionHeader( h_ext = ImageHeader.generateExtensionHeader(
...@@ -124,7 +129,8 @@ def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID = ...@@ -124,7 +129,8 @@ def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID =
return ra_PointCenter, dec_PointCenter, lon_ecl_PointCenter, lat_ecl_PointCenter return ra_PointCenter, dec_PointCenter, lon_ecl_PointCenter, lat_ecl_PointCenter
def getChipCenterRaDec(chipID = 1, p_ra = 60., p_dec = -40.):
def getChipCenterRaDec(chipID=1, p_ra=60., p_dec=-40.):
chip = Chip(chipID) chip = Chip(chipID)
h_ext = ImageHeader.generateExtensionHeader( h_ext = ImageHeader.generateExtensionHeader(
...@@ -149,17 +155,18 @@ def getChipCenterRaDec(chipID = 1, p_ra = 60., p_dec = -40.): ...@@ -149,17 +155,18 @@ def getChipCenterRaDec(chipID = 1, p_ra = 60., p_dec = -40.):
RA_chip, Dec_chip = world_point[0][0], world_point[0][1] RA_chip, Dec_chip = world_point[0][0], world_point[0][1]
return RA_chip, Dec_chip return RA_chip, Dec_chip
if __name__ == '__main__': if __name__ == '__main__':
ra_input, dec_input = 270.00000, 66.56000 # NEP ra_input, dec_input = 270.00000, 66.56000 # NEP
pa = 23.5 pa = 23.5
# chipid = 2 # chipid = 2
for chipid in np.arange(1,31,1): for chipid in np.arange(1, 31, 1):
ra, dec, lon_ecl, lat_ecl = cal_FoVcenter_1P_equatorial( ra, dec, lon_ecl, lat_ecl = cal_FoVcenter_1P_equatorial(
ra_input, dec_input,chipID=chipid, pa=pa) ra_input, dec_input, chipID=chipid, pa=pa)
print("chip id is %d, chip center [ra,dec] is [%f, %f], pointing center calculated [ra,dec] is [%f, %f]"%(chipid, ra_input, dec_input, ra, dec)) print("chip id is %d, chip center [ra,dec] is [%f, %f], pointing center calculated [ra,dec] is [%f, %f]" % (
#for check the result chipid, ra_input, dec_input, ra, dec))
# for check the result
# testRA, testDec = getChipCenterRaDec(chipID = chipid, p_ra = ra, p_dec = dec) # testRA, testDec = getChipCenterRaDec(chipID = chipid, p_ra = ra, p_dec = dec)
# print(ra_input-testRA, dec_input-testDec) # print(ra_input-testRA, dec_input-testDec)
from flask import Flask, render_template, request, redirect
import yaml
import ast
app = Flask(__name__)
key_type_map = {
'obs_type': str,
'obs_type_code': str,
'obs_id': str,
'run_chips': list,
'call_sequence': {
'scie_obs': {
'shutter_effect': bool,
'flat_fielding': bool,
'field_dist': bool,
},
'sky_background': {
'shutter_effect': bool,
'flat_fielding': bool,
'enable_straylight_model': bool,
'flat_level': None,
'flat_level_filt': None,
},
'PRNU_effect': {},
'cosmic_rays': {
'save_cosmic_img': bool,
},
'poisson_and_dark': {
'add_dark': bool,
},
'bright_fatter': {},
'detector_defects': {
'hot_pixels': bool,
'dead_pixels': bool,
'bad_columns': bool,
},
'nonlinearity': {},
'blooming': {},
'prescan_overscan': {
'add_dark': bool,
},
'bias': {
'bias_16channel': bool,
},
'readout_noise': {},
'gain': {
'gain_16channel': bool,
},
'quantization_and_output': {
'format_output': bool,
},
},
}
def convert_dict_values(d, key_type_map):
for key, value in d.items():
if isinstance(value, dict):
convert_dict_values(value, key_type_map[key])
elif key in key_type_map:
if key_type_map[key] is int:
d[key] = int(value)
if key_type_map[key] is float:
d[key] = float(value)
if key_type_map[key] is bool:
if d[key].lower() == 'yes' or d[key].lower() == 'true':
d[key] = True
else:
d[key] = False
if key_type_map[key] is str:
d[key] = str(value)
if key_type_map[key] is list:
d[key] = ast.literal_eval(value)
if key_type_map[key] is None:
d[key] = None
def load_yaml():
with open('templates/obs_config_SCI.yaml', 'r') as file:
return yaml.safe_load(file)
def save_yaml(data):
convert_dict_values(data, key_type_map)
with open('config_reset/obs_config_SCI_reset.yaml', 'w') as file:
yaml.dump(data, file, default_flow_style=False, sort_keys=False)
def render_form(data, parent_key=''):
form_html = ''
for key, value in data.items():
full_key = f"{parent_key}.{key}" if parent_key else key
if isinstance(value, dict): # 处理字典
form_html += f"<div class='block'><h2>{key}</h2>{render_form(value, full_key)}</div>"
else:
form_html += f"<label for='{full_key}'>{key}:</label>"
form_html += f"<input type='text' id='{full_key}' name='{full_key}' value='{value}'><br>"
return form_html
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
data = load_yaml()
for key in request.form:
keys = key.split('.')
temp = data
for k in keys[:-1]:
temp = temp[k]
temp[keys[-1]] = request.form[key]
save_yaml(data)
return redirect('/')
data = load_yaml()
form_html = render_form(data)
return render_template('index_obs.html', form_html=form_html)
if __name__ == '__main__':
app.run(debug=True)
from flask import Flask, render_template, request, redirect
import yaml
import ast
app = Flask(__name__)
key_type_map = {
'work_dir': str,
'run_name': str,
'project_cycle': int,
'run_counter': int,
'run_option': {
'out_cat_only': bool,
},
'catalog_options': {
'input_path': {
'cat_dir': str,
'star_cat': str,
'galaxy_cat': str,
},
'SED_templates_path': {
'star_SED': str,
'galaxy_SED': str,
'AGN_SED': str,
},
'star_only': bool,
'galaxy_only': bool,
'rotateEll': float,
'enable_mw_ext_gal': bool,
'planck_ebv_map': str,
},
'obs_setting': {
'pointing_file': str,
'obs_config_file': str,
'run_pointings': list,
'enable_astrometric_model': bool,
'cut_in_band': str,
'mag_sat_margin': float,
'mag_lim_margin': float,
},
'psf_setting': {
'psf_model': str,
'psf_pho_dir': str,
'psf_sls_dir': str,
},
'shear_setting': {
'shear_type': str,
'reduced_g1': float,
'reduced_g2': float,
},
'output_setting': {
'output_format': str,
'shutter_output': bool,
'prnu_output': bool,
},
'random_seeds': {
'seed_poisson': int,
'seed_CR': int,
'seed_flat': int,
'seed_prnu': int,
'seed_gainNonUniform': int,
'seed_biasNonUniform': int,
'seed_rnNonUniform': int,
'seed_badcolumns': int,
'seed_defective': int,
'seed_readout': int,
},
}
def convert_dict_values(d, key_type_map):
for key, value in d.items():
if isinstance(value, dict):
convert_dict_values(value, key_type_map[key])
elif key in key_type_map:
if key_type_map[key] is int:
d[key] = int(value)
if key_type_map[key] is float:
d[key] = float(value)
if key_type_map[key] is bool:
if d[key].lower() == 'yes' or d[key].lower() == 'true':
d[key] = True
else:
d[key] = False
if key_type_map[key] is str:
d[key] = str(value)
if key_type_map[key] is list:
d[key] = ast.literal_eval(value)
def load_yaml():
with open('templates/config_overall.yaml', 'r') as file:
return yaml.safe_load(file)
def save_yaml(data):
convert_dict_values(data, key_type_map)
with open('config_reset/config_overall_reset.yaml', 'w') as file:
yaml.dump(data, file, default_flow_style=False, sort_keys=False)
def render_form(data, parent_key=''):
form_html = ''
for key, value in data.items():
full_key = f"{parent_key}.{key}" if parent_key else key
if isinstance(value, dict): # 处理字典
form_html += f"<div class='block'><h2>{key}</h2>{render_form(value, full_key)}</div>"
else:
form_html += f"<label for='{full_key}'>{key}:</label>"
form_html += f"<input type='text' id='{full_key}' name='{full_key}' value='{value}'><br>"
return form_html
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
data = load_yaml()
for key in request.form:
keys = key.split('.')
temp = data
for k in keys[:-1]:
temp = temp[k]
temp[keys[-1]] = request.form[key]
save_yaml(data)
return redirect('/')
data = load_yaml()
form_html = render_form(data)
return render_template('index_overall.html', form_html=form_html)
if __name__ == '__main__':
app.run(debug=True)
---
###############################################
#
# Configuration file for CSST simulation
# Overall settings
# CSST-Sim Group, 2024/01/08
#
###############################################
# Base diretories and naming setup
# can add some of the command-line arguments here as well;
# ok to pass either way or both, as long as they are consistent
work_dir: "/public/home/fangyuedong/project/workplace/"
run_name: "ext_on"
# Project cycle and run counter are used to name the outputs
project_cycle: 9
run_counter: 1
# Run options
run_option:
# Output catalog only?
# If yes, no imaging simulation will be run. Only the catalogs
# of corresponding footprints will be generated.
out_cat_only: NO
###############################################
# Catalog setting
###############################################
# Configure the input catalog: options should be implemented
# in the corresponding (user defined) 'Catalog' class
catalog_options:
input_path:
cat_dir: "/public/share/yangxuliu/CSSOSDataProductsSims/data_50sqDeg/"
star_cat: "starcat_C9/"
galaxy_cat: "qsocat/cat2CSSTSim_bundle-50sqDeg/"
SED_templates_path:
star_SED: "/public/share/yangxuliu/CSSOSDataProductsSims/data_50sqDeg/starcat_C9/"
galaxy_SED: "/public/share/yangxuliu/CSSOSDataProductsSims/data_50sqDeg/sedlibs/"
AGN_SED: "/public/share/yangxuliu/CSSOSDataProductsSims/data_50sqDeg/qsocat/qsosed/"
# Only simulate stars?
star_only: NO
# Only simulate galaxies?
galaxy_only: NO
# rotate galaxy ellipticity
rotateEll: 0. # [degree]
# Whether to apply milky way extinction to galaxies
enable_mw_ext_gal: YES
planck_ebv_map: "/public/home/fangyuedong/project/ext_maps/planck/HFI_CompMap_ThermalDustModel_2048_R1.20.fits"
###############################################
# Observation setting
###############################################
obs_setting:
# (Optional) a file of point list
# if you just want to run default pointing:
# - pointing_dir: null
# - pointing_file: null
pointing_file: "/public/share/yangxuliu/CSSOSDataProductsSims/data_50sqDeg/pointing50_C9/pointing_50_1_n.dat"
obs_config_file: "/public/home/fangyuedong/project/csst_msc_sim/config/obs_config_SCI.yaml"
# Run specific pointing(s):
# - give a list of indexes of pointings: [ip_1, ip_2...]
# - run all pointings: null
# Note: only valid when a pointing list is specified
run_pointings: [0, 1, 2, 3, 4]
# Whether to enable astrometric modeling
enable_astrometric_model: YES
# Cut by saturation magnitude in which band?
cut_in_band: "z"
# saturation magnitude margin
mag_sat_margin: -2.5
# mag_sat_margin: -15.
# limiting magnitude margin
mag_lim_margin: +1.0
###############################################
# PSF setting
###############################################
psf_setting:
# Which PSF model to use:
# "Gauss": simple gaussian profile
# "Interp": Interpolated PSF from sampled ray-tracing data
psf_model: "Interp"
# PSF size [arcseconds]
# radius of 80% energy encircled
# NOTE: only valid for "Gauss" PSF
# psf_rcont: 0.15
# path to PSF data
# NOTE: only valid for "Interp" PSF
# PSF models for photometry survey simulation
psf_pho_dir: "/public/share/yangxuliu/CSSOSDataProductsSims/dataC6/psfCube1"
# PSF models for slitless spectrum survey simulation
psf_sls_dir: "/public/share/yangxuliu/CSSOSDataProductsSims/data_50sqDeg/SLS_PSF_PCA_fp/"
###############################################
# Shear setting
###############################################
shear_setting:
# Options to generate mock shear field:
# "constant": all galaxies are assigned a constant reduced shear
# "catalog": get shear values from catalog
shear_type: "constant"
# For constant shear field
reduced_g1: 0.
reduced_g2: 0.
###############################################
# Output options
###############################################
output_setting:
output_format: "channels" # Whether to export as 16 channels (subimages) with pre- and over-scan ("image"/"channels")
shutter_output: NO # Whether to export shutter effect 16-bit image
prnu_output: NO # Whether to export the PRNU (pixel-to-pixel flat-fielding) files
###############################################
# Random seeds
###############################################
random_seeds:
seed_poisson: 20210601 # Seed for Poisson noise
seed_CR: 20210317 # Seed for generating random cosmic ray maps
seed_flat: 20210101 # Seed for generating random flat fields
seed_prnu: 20210102 # Seed for photo-response non-uniformity
seed_gainNonUniform: 20210202 # Seed for gain nonuniformity
seed_biasNonUniform: 20210203 # Seed for bias nonuniformity
seed_rnNonUniform: 20210204 # Seed for readout-noise nonuniformity
seed_badcolumns: 20240309 # Seed for bad columns
seed_defective: 20210304 # Seed for defective (bad) pixels
seed_readout: 20210601 # Seed for read-out gaussian noise
...
\ No newline at end of file
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>csst_msc_sim_CONF</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f4f4f4;
color: #333;
}
h1 {
text-align: center;
color: #4CAF50;
}
.container {
max-width: 800px;
margin: 0 auto;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.block {
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 4px;
padding: 10px;
background-color: #fafafa;
}
h2 {
color: #4CAF50;
font-size: 1.2em;
margin-bottom: 10px;
}
label {
display: block;
margin: 5px 0;
}
input[type="text"] {
width: calc(100% - 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 10px;
transition: border 0.3s;
}
input[type="text"]:focus {
border-color: #4CAF50;
outline: none;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 15px;
border-radius: 4px;
cursor: pointer;
font-size: 1em;
transition: background-color 0.3s;
}
input[type="submit"]:hover {
background-color: #45a049;
}
table {
width: 100%;
border: 1px solid #ddd;
border-radius: 8px; /* 圆角 */
overflow: hidden; /* 隐藏超出表格的内容 */
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* 添加阴影 */
}
th, td {
border-bottom: 1px solid #ddd; /* 单元格底部边框 */
padding: 12px; /* 内边距 */
text-align: left;
}
tr:hover {
background-color: #ADD8E6; /* 悬停时背景颜色 */
}
</style>
</head>
<body>
<div class="container">
<h1>配置obs_config_SCI.yaml</h1>
<p><strong>说明:</strong>
1,该脚本可用于生成CSST主巡天成像仿真的参数文件,相关参数说明见本页脚注;2,用户必须修改相关路径参数,其他参数可参考默认值
.
</p>
<hr style="border: 2px solid green;">
<form method="POST">
{{ form_html | safe }}
<input type="submit" value="保存">
</form>
</div>
<footer class="mt-4">
<p class="text-center">这是一个有用的网页</p>
<table>
<tr>
<th>KEYS</th>
<th>VALUES</th>
<th>COMMENTS</th>
</tr>
<tr>
<th>obs_type</th>
<td>"SCI", [str]</td>
<td>仿真图像类型</td>
</tr>
<tr>
<th>obs_type_code</th>
<td>"101", [str]</td>
<td>数据系统内部标号</td>
</tr>
<tr>
<th>obs_id</th>
<td>"00000001", [str]</td>
<td>this setting will only be used if pointing list file is not given</td>
</tr>
<tr>
<th>run_chips</th>
<td>[7,8,9], [list]</td>
<td>Define list of chips</td>
</tr>
<tr>
<th>scie_obs:<span style="font-weight: normal;">shutter_effect</span></th>
<td>YES, [bool]</td>
<td>是否应用快门效应</td>
</tr>
<tr>
<th>scie_obs:<span style="font-weight: normal;">flat_fielding</span></th>
<td>YES, [bool]</td>
<td>是否应用平场模块</td>
</tr>
<tr>
<th>scie_obs:<span style="font-weight: normal;">field_dist</span></th>
<td>YES, [bool]</td>
<td> </td>
</tr>
<tr>
<th>sky_background:<span style="font-weight: normal;">shutter_effect</span></th>
<td>YES, [bool]</td>
<td>是否应用快门效应</td>
</tr>
<tr>
<th>sky_background:<span style="font-weight: normal;">flat_fielding</span></th>
<td>YES, [bool]</td>
<td>是否应用平场模块</td>
</tr>
<tr>
<th>sky_background:<span style="font-weight: normal;">enable_straylight_model</span></th>
<td>YES, [bool]</td>
<td>是否应用杂散光模块</td>
</tr>
<tr>
<th>sky_background:<span style="font-weight: normal;">flat_level</span></th>
<td>null [null or int]</td>
<td>set the total skybackground value (e-) in the exptime,if none,set null, or delete the key</td>
</tr>
<tr>
<th>sky_background:<span style="font-weight: normal;">flat_level_filt</span></th>
<td>null, [str]</td>
<td>the vale of "flat_level" is in the filter "flat_level_filt", can set NUV, u, g, r, i, z, y, if none,set null,or delete the key</td>
</tr>
<tr>
<th>PRNU_effect<span style="font-weight: normal;"></span></th>
<td>---</td>
<td>应用像素间不均匀响应模块;如果需关闭,请在生成的yaml文件中直接注释</td>
</tr>
<tr>
<th>cosmic_rays:<span style="font-weight: normal;">save_cosmic_img</span></th>
<td>YES, [bool]</td>
<td>是否保存宇宙线图像</td>
</tr>
<tr>
<th>poisson_and_dark:<span style="font-weight: normal;">add_dark</span></th>
<td>YES, [bool]</td>
<td>是否添加暗电流</td>
</tr>
<tr>
<th>bright_fatter<span style="font-weight: normal;"></span></th>
<td>YES, [bool]</td>
<td>应用亮胖效应模块;如果需关闭,请在生成的yaml文件中直接注释</td>
</tr>
<tr>
<th>detector_defects:<span style="font-weight: normal;">hot_pixels</span></th>
<td>YES, [bool]</td>
<td>是否添加热像元</td>
</tr>
<tr>
<th>detector_defects:<span style="font-weight: normal;">dead_pixels</span></th>
<td>YES, [bool]</td>
<td>是否添加坏像元</td>
</tr>
<tr>
<th>detector_defects:<span style="font-weight: normal;">bad_columns</span></th>
<td>YES, [bool]</td>
<td>是否添加坏像列</td>
</tr>
<tr>
<th>nonlinearity<span style="font-weight: normal;"></span></th>
<td>---</td>
<td>应用非线性响应模块;如果需关闭,请在生成的yaml文件中直接注释</td>
</tr>
<tr>
<th>blooming<span style="font-weight: normal;"></span></th>
<td>---</td>
<td>是否应用饱和溢出模块;如果需关闭,请在生成的yaml文件中直接注释</td>
</tr>
<tr>
<th>prescan_overscan:<span style="font-weight: normal;">add_dark</span></th>
<td>YES, [bool]</td>
<td> 是否在pre/over-scan区域添加暗电流/</td>
</tr>
<tr>
<th>bias:<span style="font-weight: normal;">bias_16channel</span></th>
<td>YES, [bool]</td>
<td>是否添加16通道的偏置电压</td>
</tr>
<tr>
<th>readout_noise<span style="font-weight: normal;"></span></th>
<td>---</td>
<td>添加读出噪声;如果需关闭,请在生成的yaml文件中直接注释</td>
</tr>
<tr>
<th>gain:<span style="font-weight: normal;">gain_16channel</span></th>
<td>YES, [bool]</td>
<td>是否应用增益</td>
</tr>
<tr>
<th>quantization_and_output:<span style="font-weight: normal;">format_output</span></th>
<td>YES, [bool]</td>
<td>是否按0级数据格式定义输出图像</td>
</tr>
</table>
</footer>
</body>
</html>
This diff is collapsed.
This diff is collapsed.
...@@ -221,8 +221,8 @@ def ccdLayout(xpixTar, ypixTar, figout="ccdLayout.pdf"): ...@@ -221,8 +221,8 @@ def ccdLayout(xpixTar, ypixTar, figout="ccdLayout.pdf"):
ax.text(ix0+500, iy0+1500, "%s#%s" % ax.text(ix0+500, iy0+1500, "%s#%s" %
(fType, ischip), fontsize=12, color="grey") (fType, ischip), fontsize=12, color="grey")
ax.plot(xpixTar, ypixTar, "r*", ms=12) ax.plot(xpixTar, ypixTar, "r*", ms=12)
ax.set_xlabel("$X\,[\mathrm{pixels}]$", fontsize=20) ax.set_xlabel(r"$X\,[\mathrm{pixels}]$", fontsize=20)
ax.set_ylabel("$Y\,[\mathrm{pixels}]$", fontsize=20) ax.set_ylabel(r"$Y\,[\mathrm{pixels}]$", fontsize=20)
ax.invert_yaxis() ax.invert_yaxis()
ax.axis('off') ax.axis('off')
plt.savefig(figout) plt.savefig(figout)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment