run_sim.py 2.35 KB
Newer Older
1
from ObservationSim.ObservationSim import Observation
2
from ObservationSim._util import parse_args, make_run_dirs, generate_pointing_list
3
4
5
6
7
8
import os
import yaml

import gc
gc.enable()

Fang Yuedong's avatar
Fang Yuedong committed
9
def run_sim(Catalog):
10
11
    """
    Main method for simulation call.
12
13
14
15
16
17
18
19
20

    Parameters
    ----------
    Catalog : Class
        a catalog class which is inherited from ObservationSim.MockObject.CatalogBase 
    
    Returns
    ----------
        None
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    """
    args = parse_args()
    if args.config_dir is None:
        args.config_dir = ''
    args.config_dir = os.path.abspath(args.config_dir)
    args.config_file = os.path.join(args.config_dir, args.config_file)
    with open(args.config_file, "r") as stream:
        try:
            config = yaml.safe_load(stream)
            for key, value in config.items():
                print (key + " : " + str(value))
        except yaml.YAMLError as exc:
            print(exc)

    # Overwrite the data and working directories
    # if they are specified by the command line inputs
    if args.data_dir is not None:
        config['data_dir'] = args.data_dir
    if args.work_dir is not None:
        config['work_dir'] = args.work_dir

42
    # Generate lists pointings based on the input pointing list (or default 
43
44
    # pointing RA, DEC) and "config["obs_setting"]["run_pointings"]".
    # "config['obs_setting']['np_cal']"" is the number of CAL pointings which will be 
45
    # appended to the front.
46
    # NOTE: the implementation of gerenating time_stamps is temporary.
47
    pointing_list = generate_pointing_list(config=config, pointing_filename=config['pointing_file'], data_dir=config['pointing_dir'])
48
49

    # Make the main output directories
50
    make_run_dirs(work_dir=config['work_dir'], run_name=config['run_name'], pointing_list=pointing_list)
51
52
53
54
55
56

    # Initialize the simulation
    obs = Observation(config=config, Catalog=Catalog, work_dir=config['work_dir'], data_dir=config['data_dir'])
    
    # Run simulation
    obs.runExposure_MPI_PointingList(
57
        pointing_list=pointing_list,
58
59
60
61
        use_mpi=config["run_option"]["use_mpi"],
        chips=config["obs_setting"]["run_chips"])

if __name__=='__main__':
62
63
64
65
    # To run with the example input catalog
    # from Catalog.Catalog_example import Catalog_example
    # run_sim(Catalog=Catalog_example)
    
66
    # To run cycle-3 simulation
67
68
    from Catalog.C3Catalog import C3Catalog
    run_sim(Catalog=C3Catalog)