forked from marcoviero/simstack3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_simstack_cmd_line.py
More file actions
114 lines (92 loc) · 3.96 KB
/
Copy pathrun_simstack_cmd_line.py
File metadata and controls
114 lines (92 loc) · 3.96 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
#!/usr/bin/env python
'''
Set Environment Variables
export MAPSPATH=$MAPSPATH/Users/marcoviero/data/Astronomy/maps/
export CATSPATH=$CATSPATH/Users/marcoviero/data/Astronomy/catalogs/
export PICKLESPATH=$PICKLESPATH/Users/marcoviero/data/Astronomy/pickles/
Setup New Virtual Environment
> conda create -n simstack python=3.9
> conda activate simstack
Install Packages
- matplotlib (> conda install matplotlib)
- seaborn (> conda install seaborn)
- numpy (> conda install numpy)
- pandas (> conda install pandas)
- astropy (> conda install astropy)
- lmfit (> conda install -c conda-forge lmfit)
- [jupyterlab, if you want to use notebooks]
To run from command line:
- First make this file executable (only needed once), e.g.:
> chmod +x run_simstack_cmd_line.py
- Run script:
> python run_simstack_cmd_line.py
Returned object contains:
- simstack_object.config_dict; dict_keys(['general', 'io', 'catalog', 'maps', 'cosmology_dict', 'distance_bins', 'parameter_names', 'pickles_path'])
- simstack_object.catalog_dict; dict_keys(['tables'])
- simstack_object.maps_dict; dict_keys(['spire_psw', 'spire_pmw', ...])
- simstack_object.results_dict; dict_keys(['maps_dict', 'SED_df'])
'''
# Standard modules
import os
import pdb
import sys
import time
import logging
# Modules within this package
from simstackwrapper import SimstackWrapper
os.environ["DATAPATH"] = "../newdata/"
def main():
# Set up logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(message)s',
datefmt='%Y-%d-%m %I:%M:%S %p')
# Get parameters from the provided parameter file
if len(sys.argv) > 1:
param_file_path = sys.argv[1]
else:
param_file_path = os.path.join('config', 'linsimstack.ini')
# Instantiate SIMSTACK object
simstack_object = SimstackWrapper(param_file_path, save_automatically=False,
read_maps=True, read_catalog=True)
simstack_object.copy_config_file(param_file_path, overwrite_results=False)
print('Now Stacking', param_file_path)
t0 = time.time()
# Stack according to parameters in parameter file
# Bootstrap
num_boots = 0
if 'bootstrap' in simstack_object.config_dict['general']['error_estimator']:
if simstack_object.config_dict['general']['error_estimator']['bootstrap']['iterations'] > 0:
num_boots = simstack_object.config_dict['general']['error_estimator']['bootstrap']['iterations']
init_boot = simstack_object.config_dict['general']['error_estimator']['bootstrap']['initial_bootstrap']
print('Bootstrapping {} iterations starting at {}'.format(num_boots, init_boot))
# Shuffle x/y positions as Null test
randomize = False
if 'randomize' in simstack_object.config_dict['general']['error_estimator']:
if simstack_object.config_dict['general']['error_estimator']['randomize']:
randomize = True
# Convolve maps to have same psf
force_fwhm = False
if 'force_fwhm' in simstack_object.config_dict['general']['binning']:
if simstack_object.config_dict['general']['binning']['force_fwhm']:
force_fwhm = simstack_object.config_dict['general']['binning']['force_fwhm']
for boot in range(num_boots + 1):
if boot:
boot_in = boot - 1 + init_boot
simstack_object.perform_simstack(bootstrap=boot_in, randomize=randomize, force_fwhm=force_fwhm)
else:
simstack_object.perform_simstack(bootstrap=boot, randomize=randomize, force_fwhm=force_fwhm)
break
# Save Results
saved_pickle_path = simstack_object.save_stacked_fluxes(param_file_path)
# Summarize timing
t1 = time.time()
tpass = t1 - t0
logging.info("Stacking Successful!")
logging.info("Find Results in {}".format(saved_pickle_path))
logging.info("")
logging.info("Total time : {:.4f} minutes\n".format(tpass / 60.))
if __name__ == "__main__":
main()
else:
logging.info("Note: `mapit` module not being run as main executable.")