config.py 2.01 KB
Newer Older
Chen Yili's avatar
Chen Yili committed
1
2
3
import os, yaml
import warnings

Chen Yili's avatar
Chen Yili committed
4
5
cpism_refdata = '/home/ubuntu/Downloads/cpic-img-sim-master/cpic-img-sim-master/cpism_refdata'
print(cpism_refdata)
Chen Yili's avatar
Chen Yili committed
6
7
8
9
if not os.path.exists(cpism_refdata):  # pragma: no cover
    raise Exception(
        "Can not find CPISM reference data.")

Chen Yili's avatar
Chen Yili committed
10
11
os.environ['PYSYN_CDBS'] = '/home/ubuntu/Downloads/cpic-img-sim-master/cpic-img-sim-master/trd/grp/redcat/trds/'
if not os.path.exists(os.environ.get('PYSYN_CDBS', '/home/ubuntu/Downloads/cpic-img-sim-master/cpic-img-sim-master/trd/grp/redcat/trds/')):  # pragma: no cover
Chen Yili's avatar
Chen Yili committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
    raise Exception(
        "Can not find PYSYN Stellar reference data.")

# we need to ignore the warning from pysynphot, because we only use the star models.
with warnings.catch_warnings():  # pragma: no cover
    warnings.filterwarnings("ignore")
    import pysynphot as S

solar_spectrum = S.FileSpectrum(
    f"{os.environ['PYSYN_CDBS']}/grid/solsys/solar_spec.fits")
solar_spectrum.convert('photlam')

config_file = cpism_refdata + '/optics/optics_config.yaml'
if not os.path.exists(config_file):  # pragma: no cover
    raise FileNotFoundError(f"光学配置文件不存在({config_file})")
with open(config_file, 'r') as f:
    optics_config = yaml.load(f, Loader=yaml.FullLoader)

MAG_SYSTEM = 'abmag'

__version__ = '1.0.0'

def which_focalplane(band):
    """
    Return the name of the focalplane which the band belongs to.

    Parameters
    -----------
    band: str
        The name of the band.
        from ['f565', 'f661', 'f743', 'f883', 'f940', 'f1265', 'f1425', 'f1542', 'wfs']

    Returns
    --------
    str
        The name of the focalplane.
        'vis' or 'nir' or 'wfs'

    Raises
    -------
    ValueError
        If the band is not in ['f565', 'f661', 'f743', 'f883', 'f940', 'f1265', 'f1425', 'f1542', 'wfs']
    """
    band = band.lower()
Chen Yili's avatar
Chen Yili committed
56
    if band in ['f565', 'f661', 'f743', 'f883']:
Chen Yili's avatar
Chen Yili committed
57
58
59
60
61
62
        return 'vis'
    if band in ['f940', 'f1265', 'f1425', 'f1542']:
        return 'nir'
    if band in ['wfs']:
        return 'wfs'

Chen Yili's avatar
Chen Yili committed
63
    raise ValueError(f"未知的波段{band}")