CatalogBase.py 3.58 KB
Newer Older
1
2
3
import numpy as np
import galsim
import copy
4
import cmath
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

from astropy.table import Table
from abc import abstractmethod, ABCMeta
from ObservationSim.MockObject._util import integrate_sed_bandpass, getNormFactorForSpecWithABMAG, getABMAG


class CatalogBase(metaclass=ABCMeta):
    def __init__(self):
        pass

    @abstractmethod
    def load_sed(self, obj, **kward):
        pass

    @abstractmethod
    def _load(self, **kward):
        pass

    @abstractmethod
    def load_norm_filt(self, obj):
        return None
    
    @staticmethod
    def initialize_param():
        param = {
            "star":-1,
            "id":-1,
            "ra":0,
33
34
35
36
            "dec":0.,
            "ra_orig":0.,
            "dec_orig":0.,
            "z":0.,
37
38
            "sed_type":-1,
            "model_tag":"unknown",
39
40
41
            "mag_use_normal":100.,
            "theta":0.,
            "kappa":0.,
Fang Yuedong's avatar
Fang Yuedong committed
42
43
            "g1":0.,
            "g2":0.,
44
45
46
47
48
49
50
51
            "bfrac":0.,
            "av":0.,
            "redden":0.,
            "hlr_bulge":0.,
            "hlr_disk":0.,
            "ell_bulge":0.,
            "ell_disk":0.,
            "ell_tot":0.,
Fang Yuedong's avatar
Fang Yuedong committed
52
53
54
55
            "e1_disk":0.,
            "e2_disk":0.,
            "e1_bulge":0.,
            "e2_bulge":0.,
56
57
58
            "teff":0.,
            "logg":0.,
            "feh":0.,
Fang Yuedong's avatar
Fang Yuedong committed
59
60
61
62
63
64
65
66
67
68
69
            # C6 galaxies parameters
            "e1":0.,
            "e2":0.,
            "bulgemass":0.,
            "diskmass":0.,
            "size":0.,
            "detA":0.,
            "type":0,
            "veldisp":0.,
            "coeff": np.zeros(20),
            # Astrometry related
70
71
72
            "pmra":0.,
            "pmdec":0.,
            "rv":0.,
73
            "parallax":1e-9
74
75
        }
        return param
76
77
78
79
80
81
82
83
84
85

    @staticmethod
    def rotate_ellipticity(e1, e2, rotation=0., unit='radians'):
        if unit == 'degree':
            rotation = np.radians(rotation)
        e_total = np.sqrt(e1**2 + e2**2)
        phi = cmath.phase(complex(e1, e2))
        e1 = e_total * np.cos(phi + 2*rotation)
        e2 = e_total * np.sin(phi + 2*rotation)
        return e1, e2, e_total
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    
    @staticmethod
    def convert_sed(mag, sed, target_filt, norm_filt=None):
        bandpass = target_filt.bandpass_full
        
        if norm_filt is not None:
            norm_thr_rang_ids = norm_filt['SENSITIVITY'] > 0.001
        else:
            norm_filt = Table(
                np.array(np.array([bandpass.wave_list*10.0, bandpass.func(bandpass.wave_list)])).T, names=(['WAVELENGTH', 'SENSITIVITY'])
            )
            norm_thr_rang_ids = norm_filt['SENSITIVITY'] > 0.001
        
        sedNormFactor = getNormFactorForSpecWithABMAG(ABMag=mag,
                spectrum=sed,
                norm_thr=norm_filt,
                sWave=np.floor(norm_filt[norm_thr_rang_ids][0][0]),
                eWave=np.ceil(norm_filt[norm_thr_rang_ids][-1][0]))
        sed_photon = copy.copy(sed)
        sed_photon = np.array([sed_photon['WAVELENGTH'], sed_photon['FLUX']*sedNormFactor]).T
        sed_photon = galsim.LookupTable(x=np.array(sed_photon[:, 0]), f=np.array(sed_photon[:, 1]), interpolant='nearest')
        # Get magnitude
        sed_photon = galsim.SED(sed_photon, wave_type='A', flux_type='1', fast=False)
        interFlux = integrate_sed_bandpass(sed=sed_photon, bandpass=bandpass)
        mag_csst = getABMAG(
            interFlux=interFlux,
            bandpass=bandpass
        )
        if target_filt.survey_type == "photometric":
115
            return sed_photon, mag_csst, interFlux
116
117
        elif target_filt.survey_type == "spectroscopic":
            del sed_photon
118
            return sed, mag_csst, interFlux