-
Notifications
You must be signed in to change notification settings - Fork 28
/
lenstools.matter_power_spectrum
76 lines (56 loc) · 2.32 KB
/
lenstools.matter_power_spectrum
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
#!/usr/bin/env python-mpi
from importlib import import_module
import sys
import argparse
from lenstools import SimulationBatch
from lenstools.pipeline.settings import EnvironmentSettings
from lenstools.scripts.nbody import powerSpectrumExecution
import logging
from lenstools.simulations.logs import logpreamble
#MPI
from mpi4py import MPI
from lenstools.utils import MPIWhirlPool
#Parse command line options
parser = argparse.ArgumentParser()
parser.add_argument("-v","--verbose",dest="verbose",action="store_true",default=False,help="turn output verbosity")
parser.add_argument("-e","--environment",dest="environment",action="store",type=str,help="environment configuration file")
parser.add_argument("-c","--config",dest="config_file",action="store",type=str,help="configuration file")
parser.add_argument("id",nargs="*")
#Parse command arguments
cmd_args = parser.parse_args()
#Verbosity level
if cmd_args.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
#Initialize MPIWhirlPool
comm = MPI.COMM_WORLD
try:
pool = MPIWhirlPool(comm=comm)
except:
pool = None
logpreamble.debug("Couldn't initialize MPI Pool, running in series")
#check that all provided options are available
if (len(cmd_args.id)==0) or (cmd_args.config_file is None) or (cmd_args.environment is None):
if (pool is None) or (pool.is_master()):
parser.print_help()
sys.exit(0)
script_to_execute,settings_handler,kwargs = powerSpectrumExecution()
#Log to user
if (pool is None) or (pool.is_master()):
logpreamble.info("Executing: {0}()".format(script_to_execute.__name__))
logpreamble.info("Job configuration handler: {0}".format(settings_handler.__name__))
logpreamble.info("Keyword arguments: {0}".format(kwargs))
#Parse relevant options
if (pool is None) or (pool.is_master()):
logpreamble.info("Reading environment from {0}".format(cmd_args.environment))
logpreamble.info("Reading job configuration from {0}".format(cmd_args.config_file))
#Environment
environment_settings = EnvironmentSettings.read(cmd_args.environment)
#Get a handle on the simulation batch
batch = SimulationBatch(environment_settings)
#Lensing
settings = settings_handler.read(cmd_args.config_file)
#Cycle over ids to produce the planes
for batch_id in cmd_args.id:
script_to_execute(pool=pool,batch=batch,settings=settings,id=batch_id,**kwargs)