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()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# get_pointing # get_pointing
# PURPOSE: # PURPOSE:
# Return the pointing of CSST from a given [ra, dec] # Return the pointing of CSST from a given [ra, dec]
# CALLING: # CALLING:
# pointing = findPointingbyChipID(chipID=tchip, ra=tra, dec=tdec) # pointing = findPointingbyChipID(chipID=tchip, ra=tra, dec=tdec)
# INPUTS: # INPUTS:
# chipID - chip-# of CSST, int # chipID - chip-# of CSST, int
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
# HISTORY: # HISTORY:
# Written by Xin Zhang, 23 Apr. 2023 # Written by Xin Zhang, 23 Apr. 2023
# Included by csst-simulation, C.W. 25 Apr. 2023 # Included by csst-simulation, C.W. 25 Apr. 2023
# #
# #
from tkinter.tix import INTEGER from tkinter.tix import INTEGER
import astropy.coordinates as coord import astropy.coordinates as coord
...@@ -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
...@@ -41,9 +42,9 @@ class Chip(object): ...@@ -41,9 +42,9 @@ class Chip(object):
self.npix_x = 9216 self.npix_x = 9216
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
...@@ -72,23 +74,24 @@ class Chip(object): ...@@ -72,23 +74,24 @@ class Chip(object):
dudy = +np.sin(img_rot.rad) * pix_scale dudy = +np.sin(img_rot.rad) * pix_scale
dvdx = -np.sin(img_rot.rad) * pix_scale dvdx = -np.sin(img_rot.rad) * pix_scale
dvdy = -np.cos(img_rot.rad) * pix_scale dvdy = -np.cos(img_rot.rad) * pix_scale
# dudx = +np.sin(img_rot.rad) * pix_scale # dudx = +np.sin(img_rot.rad) * pix_scale
# dudy = +np.cos(img_rot.rad) * pix_scale # dudy = +np.cos(img_rot.rad) * pix_scale
# 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)
return WCS return WCS
def getChipRowCol(self, chipID): def getChipRowCol(self, chipID):
rowID = ((chipID - 1) % 5) + 1 rowID = ((chipID - 1) % 5) + 1
colID = 6 - ((chipID - 1) // 5) colID = 6 - ((chipID - 1) // 5)
return rowID, colID return rowID, colID
def getChipCenter(self): def getChipCenter(self):
"""Calculate the edges in pixel for a given CCD chip on the focal plane """Calculate the edges in pixel for a given CCD chip on the focal plane
NOTE: There are 5*4 CCD chips in the focus plane for photometric observation. NOTE: There are 5*4 CCD chips in the focus plane for photometric observation.
...@@ -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,37 +126,42 @@ class Chip(object): ...@@ -125,37 +126,42 @@ 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):
def getSelectPointingList(center=[60, -40], radius=2):
points = np.loadtxt('sky.dat') points = np.loadtxt('sky.dat')
center = center # ra dec
center = center#ra dec radius = radius # degree
radius = radius # degree
radii_dec = 1 radii_dec = 1
radii_ra = 1/math.cos(math.pi*center[1]/180) radii_ra = 1/math.cos(math.pi*center[1]/180)
...@@ -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:
...@@ -189,7 +198,7 @@ def getSelectPointingList(center = [60,-40], radius = 2): ...@@ -189,7 +198,7 @@ def getSelectPointingList(center = [60,-40], radius = 2):
dec_range_hi = center[1]+radii_dec dec_range_hi = center[1]+radii_dec
if center[1]+radii_dec > 90: if center[1]+radii_dec > 90:
dec_range_hi = 90 dec_range_hi = 90
ids3 = (c_equtor[ids1].dec*u.degree).value > dec_range_lo ids3 = (c_equtor[ids1].dec*u.degree).value > dec_range_lo
ids4 = (c_equtor[ids1][ids3].dec*u.degree).value < dec_range_hi ids4 = (c_equtor[ids1][ids3].dec*u.degree).value < dec_range_hi
...@@ -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:
...@@ -226,9 +234,9 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.): ...@@ -226,9 +234,9 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.):
Returns: Returns:
_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()
...@@ -257,15 +265,14 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.): ...@@ -257,15 +265,14 @@ def findPointingbyChipID(chipID = 8, ra = 60., dec = -40.):
r_ra = ra_n r_ra = ra_n
r_dec = dec_n r_dec = dec_n
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,25 +28,26 @@ def ecl2radec(lon_ecl, lat_ecl): ...@@ -25,25 +28,26 @@ 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(
chip=chip, chip=chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=(ra_FieldCenter * u.degree).value, ra=(ra_FieldCenter * u.degree).value,
dec=(dec_FieldCenter * u.degree).value, dec=(dec_FieldCenter * u.degree).value,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
...@@ -54,7 +58,7 @@ def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID = 1, pa ...@@ -54,7 +58,7 @@ def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID = 1, pa
pixel_size=chip.pix_size, pixel_size=chip.pix_size,
xcen=chip.x_cen, xcen=chip.x_cen,
ycen=chip.y_cen, ycen=chip.y_cen,
) )
# assume that the telescope point to the sky center; then abtain the chip center under this situation; then calculate the differenc between the assumed telescope center and chip center; then add this difference to the sky center # assume that the telescope point to the sky center; then abtain the chip center under this situation; then calculate the differenc between the assumed telescope center and chip center; then add this difference to the sky center
...@@ -75,24 +79,25 @@ def cal_FoVcenter_1P_equatorial(ra_FieldCenter, dec_FieldCenter, chipID = 1, pa ...@@ -75,24 +79,25 @@ 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(
chip=chip, chip=chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=(ra_FieldCenter * u.degree).value, ra=(ra_FieldCenter * u.degree).value,
dec=(dec_FieldCenter * u.degree).value, dec=(dec_FieldCenter * u.degree).value,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
...@@ -103,7 +108,7 @@ def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID = ...@@ -103,7 +108,7 @@ def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID =
pixel_size=chip.pix_size, pixel_size=chip.pix_size,
xcen=chip.x_cen, xcen=chip.x_cen,
ycen=chip.y_cen, ycen=chip.y_cen,
) )
# assume that the telescope point to the sky center; then abtain the chip center under this situation; then calculate the differenc between the assumed telescope center and chip center; then add this difference to the sky center # assume that the telescope point to the sky center; then abtain the chip center under this situation; then calculate the differenc between the assumed telescope center and chip center; then add this difference to the sky center
...@@ -124,14 +129,15 @@ def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID = ...@@ -124,14 +129,15 @@ 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(
chip=chip, chip=chip,
xlen=chip.npix_x, xlen=chip.npix_x,
ylen=chip.npix_y, ylen=chip.npix_y,
ra=(p_ra * u.degree).value, ra=(p_ra * u.degree).value,
dec=(p_dec * u.degree).value, dec=(p_dec * u.degree).value,
pa=pa, pa=pa,
gain=chip.gain, gain=chip.gain,
...@@ -142,24 +148,25 @@ def getChipCenterRaDec(chipID = 1, p_ra = 60., p_dec = -40.): ...@@ -142,24 +148,25 @@ def getChipCenterRaDec(chipID = 1, p_ra = 60., p_dec = -40.):
pixel_size=chip.pix_size, pixel_size=chip.pix_size,
xcen=chip.x_cen, xcen=chip.x_cen,
ycen=chip.y_cen, ycen=chip.y_cen,
) )
wcs_h = wcs.WCS(h_ext) wcs_h = wcs.WCS(h_ext)
pixs = np.array([[4608, 4616]]) pixs = np.array([[4608, 4616]])
world_point = wcs_h.wcs_pix2world(pixs, 0) world_point = wcs_h.wcs_pix2world(pixs, 0)
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)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -26,7 +26,7 @@ def focalPlaneInf(ra_target, dec_target, ra_point, dec_point, image_rot=-113.433 ...@@ -26,7 +26,7 @@ def focalPlaneInf(ra_target, dec_target, ra_point, dec_point, image_rot=-113.433
float, in unit of degrees; float, in unit of degrees;
image_rot : orientation of the camera with respect the sky; image_rot : orientation of the camera with respect the sky;
float, in unit of degrees; float, in unit of degrees;
NOTE: image_rot=-113.4333 is the default value NOTE: image_rot=-113.4333 is the default value
in current CSST image simulation; in current CSST image simulation;
figout : location of the target object in the focal plane; figout : location of the target object in the focal plane;
str str
...@@ -36,7 +36,7 @@ def focalPlaneInf(ra_target, dec_target, ra_point, dec_point, image_rot=-113.433 ...@@ -36,7 +36,7 @@ def focalPlaneInf(ra_target, dec_target, ra_point, dec_point, image_rot=-113.433
the pointing center (ra_point dec_point) of the telescope the pointing center (ra_point dec_point) of the telescope
1) open a terminal 1) open a terminal
2) type >> python TargetLocationCheck.py ra_target dec_target ra_point dec_point 2) type >> python TargetLocationCheck.py ra_target dec_target ra_point dec_point
or type >> python TargetLocationCheck.py ra_target dec_target ra_point dec_point -image_rot=floatNum or type >> python TargetLocationCheck.py ra_target dec_target ra_point dec_point -image_rot=floatNum
or type >> python TargetLocationCheck.py ra_target dec_target ra_point dec_point -image_rot=floatNum -figout=FigureName or type >> python TargetLocationCheck.py ra_target dec_target ra_point dec_point -image_rot=floatNum -figout=FigureName
""" """
print("^_^ Input target coordinate: [Ra, Dec] = [%10.6f, %10.6f]" % ( print("^_^ Input target coordinate: [Ra, Dec] = [%10.6f, %10.6f]" % (
...@@ -105,7 +105,7 @@ def ccdParam(): ...@@ -105,7 +105,7 @@ def ccdParam():
def getTanWCS(ra, dec, img_rot, pix_scale=0.074): def getTanWCS(ra, dec, img_rot, pix_scale=0.074):
""" """
Get the WCS of the image mosaic using Gnomonic/TAN projection Get the WCS of the image mosaic using Gnomonic/TAN projection
Parameter: Parameter:
ra, dec: float ra, dec: float
...@@ -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