CatalogBase.py 3.94 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

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
Fang Yuedong's avatar
Fang Yuedong committed
26

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

    @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
Fang Yuedong's avatar
Fang Yuedong committed
88

89
    @staticmethod
Fang Yuedong's avatar
Fang Yuedong committed
90
    def convert_sed(mag, sed, target_filt, norm_filt=None, mu=1.):
91
        bandpass = target_filt.bandpass_full
Fang Yuedong's avatar
Fang Yuedong committed
92

93
94
95
96
        if norm_filt is not None:
            norm_thr_rang_ids = norm_filt['SENSITIVITY'] > 0.001
        else:
            norm_filt = Table(
Fang Yuedong's avatar
Fang Yuedong committed
97
98
                np.array(np.array([bandpass.wave_list*10.0, bandpass.func(
                    bandpass.wave_list)])).T, names=(['WAVELENGTH', 'SENSITIVITY'])
99
100
            )
            norm_thr_rang_ids = norm_filt['SENSITIVITY'] > 0.001
Fang Yuedong's avatar
Fang Yuedong committed
101

102
        sedNormFactor = getNormFactorForSpecWithABMAG(ABMag=mag,
Fang Yuedong's avatar
Fang Yuedong committed
103
104
105
106
107
                                                      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]))
108
        sed_photon = copy.copy(sed)
Fang Yuedong's avatar
Fang Yuedong committed
109
110
111
112
        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] * mu), interpolant='nearest')
113
        # Get magnitude
Fang Yuedong's avatar
Fang Yuedong committed
114
115
        sed_photon = galsim.SED(sed_photon, wave_type='A',
                                flux_type='1', fast=False)
116
117
118
119
120
121
        interFlux = integrate_sed_bandpass(sed=sed_photon, bandpass=bandpass)
        mag_csst = getABMAG(
            interFlux=interFlux,
            bandpass=bandpass
        )
        if target_filt.survey_type == "photometric":
122
            return sed_photon, mag_csst, interFlux
123
124
        elif target_filt.survey_type == "spectroscopic":
            del sed_photon
Fang Yuedong's avatar
Fang Yuedong committed
125
            return sed, mag_csst, interFlux