config.py 1.79 KB
Newer Older
Chen Yili's avatar
Chen Yili committed
1
2
3
4
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
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
61
62
63
import os, yaml
import warnings

cpism_refdata = 'D:/CPIC_image_process/cpic-img-sim-master/cpism_refdata'

if not os.path.exists(cpism_refdata):  # pragma: no cover
    raise Exception(
        "Can not find CPISM reference data.")


if not os.path.exists(os.environ.get('PYSYN_CDBS', './trd')):  # pragma: no cover
    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()
    if band in ['f520', 'f662', 'f720', 'f850']:
        return 'vis'
    if band in ['f940', 'f1265', 'f1425', 'f1542']:
        return 'nir'
    if band in ['wfs']:
        return 'wfs'

    raise ValueError(f"未知的波段{band}")