Commit 45682570 authored by Zhang Xin's avatar Zhang Xin
Browse files

pep8

parent d10eb6a8
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -336,7 +336,7 @@ class SpecDisperser(object):
        orders = {"A": "1st", "B": "0st", "C": "2st", "D": "-1st", "E": "-2st"}
        sens_file_name = conffile[0:-5] + \
            "_sensitivity_" + orders[beam] + ".fits"
        if not os.path.exists(sens_file_name) == True:
        if os.path.exists(sens_file_name) if False:
            senstivity_out = Table(
                array([w, sens]).T, names=("WAVELENGTH", "SENSITIVITY"))
            senstivity_out.write(sens_file_name, format="fits")
+45 −39
Original line number Diff line number Diff line
@@ -435,14 +435,15 @@ class PSFInterpSLS(PSFModel):
        # PSF_int_trans[ids_szero] = 0
        # print(PSF_int_trans[ids_szero].shape[0],PSF_int_trans.shape)
        PSF_int_trans = PSF_int_trans/np.sum(PSF_int_trans)
        ###DEBGU
        # DEBGU
        ids_szero = PSF_int_trans < 0
        n01 = PSF_int_trans[ids_szero].shape[0]

        n1 = np.sum(np.isinf(PSF_int_trans))
        n2 = np.sum(np.isnan(PSF_int_trans))
        if n1 > 0 or n2 > 0:
            print("DEBUG: PSFInterpSLS, inf:%d, nan:%d, 0 num:%d"%(n1, n2, n01))
            print("DEBUG: PSFInterpSLS, inf:%d, nan:%d, 0 num:%d" %
                  (n1, n2, n01))

        ####
        # from astropy.io import fits
@@ -537,7 +538,8 @@ class PSFInterpSLS(PSFModel):
        sumImg = np.sum(cutImg.array)
        tmp_img = cutImg*0
        for j in np.arange(npc):
            X_ = np.hstack((pos_p[:,1].flatten()[:, None], pos_p[:,0].flatten()[:, None]),dtype=np.float32)
            X_ = np.hstack((pos_p[:, 1].flatten()[:, None], pos_p[:, 0].flatten()[
                           :, None]), dtype=np.float32)
            Z_ = (pc_coeff[j].astype(np.float32)).flatten()
            # print(pc_coeff[j].shape[0], pos_p[:,1].shape[0], pos_p[:,0].shape[0])
            cx_len = int(chip.npix_x)
@@ -586,7 +588,8 @@ class PSFInterpSLS(PSFModel):
            img_tmp = cutImg
            img_tmp[bounds] = img_tmp[bounds]*U
            psf = pcs[:, j].reshape(m_size, m_size)
            tmp_img = tmp_img + signal.fftconvolve(img_tmp.array, psf, mode='same', axes=None)
            tmp_img = tmp_img + \
                signal.fftconvolve(img_tmp.array, psf, mode='same', axes=None)

            # t3=datetime.datetime.now()
            # print("time convole:", t3-t2)
@@ -598,7 +601,6 @@ class PSFInterpSLS(PSFModel):
            tmp_img = tmp_img/np.sum(tmp_img.array)*sumImg
        return tmp_img


    def convolveFullImgWithPCAPSF(self, chip, folding_threshold=5.e-3):
        keys_L1 = chip_utils.getChipSLSGratingID(chip.chipID)
        # keys_L2 = ['order-2','order-1','order0','order1','order2']
@@ -621,12 +623,12 @@ class PSFInterpSLS(PSFModel):
                for w in keys_L3:
                    img = chip.img_stack[gt][od][w]
                    pcs = psfCo_L2['band'+w[1]]['band_data'][0].data
                    pos_p = psfCo_L2['band'+w[1]]['band_data'][1].data/chip.pix_size - np.array([y_start, x_start])
                    pos_p = psfCo_L2['band'+w[1]]['band_data'][1].data / \
                        chip.pix_size - np.array([y_start, x_start])
                    pc_coeff = psfCo_L2['band'+w[1]]['band_data'][2].data
                    # print("DEBUG-----------",np.max(pos_p[:,1]),np.min(pos_p[:,1]), np.max(pos_p[:,0]),np.min(pos_p[:,0]))
                    sum_img = np.sum(img.array)

                    
                    # coeff_mat = np.zeros([npca, chip.npix_y, chip.npix_x])
                    # for m in np.arange(chip.npix_y):
                    #     for n in np.arange(chip.npix_x):
@@ -663,7 +665,8 @@ class PSFInterpSLS(PSFModel):
                    tmp_img = np.zeros_like(img.array, dtype=np.float32)
                    for j in np.arange(npca):
                        print(gt, od, w, j)
                        X_ = np.hstack((pos_p[:,1].flatten()[:, None], pos_p[:,0].flatten()[:, None]),dtype=np.float32)
                        X_ = np.hstack((pos_p[:, 1].flatten()[:, None], pos_p[:, 0].flatten()[
                                       :, None]), dtype=np.float32)
                        Z_ = (pc_coeff[j].astype(np.float32)).flatten()
                        # print(pc_coeff[j].shape[0], pos_p[:,1].shape[0], pos_p[:,0].shape[0])
                        sub_size = 4
@@ -681,14 +684,17 @@ class PSFInterpSLS(PSFModel):
                        U = np.zeros_like(chip.img.array, dtype=np.float32)
                        for mi in np.arange(cy_len):
                            for mj in np.arange(cx_len):
                                U[mi*sub_size:(mi+1)*sub_size, mj*sub_size:(mj+1)*sub_size]=U1[mi,mj]
                                U[mi*sub_size:(mi+1)*sub_size, mj *
                                  sub_size:(mj+1)*sub_size] = U1[mi, mj]
                        t2 = datetime.datetime.now()

                        print("time interpolate:", t2-t1)

                        img_tmp = img.array*U
                        psf = pcs[:, j].reshape(m_size, m_size)
                        tmp_img = tmp_img + signal.fftconvolve(img_tmp, psf, mode='same', axes=None)
                        tmp_img = tmp_img + \
                            signal.fftconvolve(
                                img_tmp, psf, mode='same', axes=None)

                        t3 = datetime.datetime.now()
                        print("time convole:", t3-t2)
+59 −52
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import galsim
import math
# from numba import jit


class Chip(object):
    def __init__(self, chipID):
        self.chipID = chipID
@@ -57,7 +58,8 @@ class Chip(object):
            WCS of the focal plane
        """
        if logger is not None:
            logger.info("    Construct the wcs of the entire image mosaic using Gnomonic/TAN projection")
            logger.info(
                "    Construct the wcs of the entire image mosaic using Gnomonic/TAN projection")
        if (xcen == None) or (ycen == None):
            xcen = self.cen_pix_x
            ycen = self.cen_pix_y
@@ -78,7 +80,8 @@ class Chip(object):
        # dvdx =  -np.cos(img_rot.rad) * pix_scale
        # dvdy =  +np.sin(img_rot.rad) * pix_scale
        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)
        WCS = galsim.TanWCS(affine, sky_center, units=galsim.arcsec)

@@ -99,8 +102,6 @@ class Chip(object):
            A galsim BoundsD object
        """



        chipID = self.chipID

        rowID, colID = self.getChipRowCol(chipID)
@@ -125,23 +126,27 @@ class Chip(object):

        return galsim.PositionD(xcen, ycen)


def transRaDec2D(ra, dec):
    x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795);
    y1 = np.cos(dec / 57.2957795) * np.sin(ra / 57.2957795);
    z1 = np.sin(dec / 57.2957795);
    x1 = np.cos(dec / 57.2957795) * np.cos(ra / 57.2957795)
    y1 = np.cos(dec / 57.2957795) * np.sin(ra / 57.2957795)
    z1 = np.sin(dec / 57.2957795)
    return np.array([x1, y1, z1])


def getobsPA(ra, dec):
    l1 = np.array([0, 0, 1])
    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')

    # print(polar_eq.ra.value,polar_eq.dec.value)
    polar_d = transRaDec2D(polar_eq.ra.value, polar_eq.dec.value)
    l1l2cross = np.cross(l2, l1)
    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 + 90
@@ -150,10 +155,11 @@ def getobsPA(ra, dec):
    return angle

# @jit()


def getSelectPointingList(center=[60, -40], radius=2):
    points = np.loadtxt('sky.dat')

    
    center = center  # ra dec
    radius = radius  # degree

@@ -163,7 +169,8 @@ def getSelectPointingList(center = [60,-40], radius = 2):
    if 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')

    # print(np.min((c_equtor.ra*u.degree).value), np.max((c_equtor.ra*u.degree).value))
@@ -175,12 +182,14 @@ def getSelectPointingList(center = [60,-40], radius = 2):
    ra_range_hi = center[0]+radii_ra

    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:
        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:
        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
    if center[1]-radii_dec < -90:
@@ -215,7 +224,6 @@ def getSelectPointingList(center = [60,-40], radius = 2):
    return p_result



def findPointingbyChipID(chipID=8, ra=60., dec=-40.):
    """_summary_

@@ -268,4 +276,3 @@ if __name__ == "__main__":
    tchip, tra, tdec = 13, 60., -40.
    pointing = findPointingbyChipID(chipID=tchip, ra=tra, dec=tdec)
    print("[ra_center, dec_center, image_rot]: ", pointing)
+32 −25
Original line number Diff line number Diff line

from pylab import *
import math, sys, numpy as np
import math
import sys
import numpy as np
import astropy.coordinates as coord
from astropy.coordinates import SkyCoord
from astropy import wcs, units as u
@@ -14,8 +16,9 @@ def transRaDec2D(ra, dec):
    z1 = np.sin(dec / 57.2957795)
    return np.array([x1, y1, z1])


def ecl2radec(lon_ecl, lat_ecl):
    ## convert from ecliptic coordinates to equatorial coordinates
    # convert from ecliptic coordinates to equatorial coordinates
    c_ecl = SkyCoord(
        lon=lon_ecl * u.degree, lat=lat_ecl * u.degree, frame="barycentrictrueecliptic"
    )
@@ -25,18 +28,19 @@ def ecl2radec(lon_ecl, lat_ecl):


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_ecl = c_eq.transform_to("barycentrictrueecliptic")
    lon_ecl, lat_ecl = c_ecl.lon.degree, c_ecl.lat.degree
    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.
    ### [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
    # [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.
    # Calculate PA angle
    chip = Chip(chipID)

    h_ext = ImageHeader.generateExtensionHeader(
@@ -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


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.
    ### [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(
        lon_ecl_FieldCenter, lat_ecl_FieldCenter
    )

    ## Calculate PA angle
    # Calculate PA angle
    chip = Chip(chipID)

    h_ext = ImageHeader.generateExtensionHeader(
@@ -124,6 +129,7 @@ def cal_FoVcenter_1P_ecliptic(lon_ecl_FieldCenter, lat_ecl_FieldCenter, chipID =

    return ra_PointCenter, dec_PointCenter, lon_ecl_PointCenter, lat_ecl_PointCenter


def getChipCenterRaDec(chipID=1, p_ra=60., p_dec=-40.):
    chip = Chip(chipID)

@@ -149,6 +155,7 @@ def getChipCenterRaDec(chipID = 1, p_ra = 60., p_dec = -40.):
    RA_chip, Dec_chip = world_point[0][0], world_point[0][1]
    return RA_chip, Dec_chip


if __name__ == '__main__':
    ra_input, dec_input = 270.00000, 66.56000  # NEP
    pa = 23.5
@@ -158,8 +165,8 @@ if __name__ == '__main__':
        ra, dec, lon_ecl, lat_ecl = cal_FoVcenter_1P_equatorial(
            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]" % (
            chipid, ra_input, dec_input, ra, dec))
        # for check the result
        # testRA, testDec = getChipCenterRaDec(chipID = chipid, p_ra = ra, p_dec = dec)
        # print(ra_input-testRA, dec_input-testDec)
+7 −7

File changed.

Contains only whitespace changes.