-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_pyilc_analysis.py
105 lines (82 loc) · 4.08 KB
/
main_pyilc_analysis.py
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
"""
This script runs a pipeline for analysis of the cleaned CMB signal generated with PyILC.
The pipeline consists of the following steps:
1. Generating per-pixel analysis results for each simulation
2. Generating per-pixel summary statistics for each simulation
3. Converting the theory power spectrum to a format that can be used for analysis
4. Generating per-ell power spectrum analysis results for each simulation
5. Generating per-ell power spectrum summary statistics for each simulation
And also generating various analysis figures, throughout.
Because settings in PyILC cause conflicts for Matplotlib, this analysis is performed separately from `main_pyilc_predict.py`.
The script uses the Hydra library for configuration management.
Usage:
python main_pyilc_predict.py
"""
from functools import partial
import logging
import hydra
from cmbml.utils.check_env_var import validate_environment_variable
from cmbml.core import (
PipelineContext,
LogMaker
)
from cmbml.core.A_check_hydra_configs import HydraConfigCheckerExecutor
from cmbml.sims import MaskCreatorExecutor
from cmbml.analysis import (
# NILCShowSimsPostExecutor,
CommonRealPostExecutor,
CommonPyILCPredPostExecutor,
CommonNILCShowSimsPostExecutor,
CommonNILCShowSimsPostIndivExecutor,
PixelAnalysisExecutor,
PixelSummaryExecutor,
ConvertTheoryPowerSpectrumExecutor,
MakeTheoryPSStats,
PyILCMakePSExecutor,
PixelSummaryFigsExecutor,
PowerSpectrumAnalysisExecutor,
PowerSpectrumSummaryExecutor,
PowerSpectrumSummaryFigsExecutor,
ShowOnePSExecutor,
PostAnalysisPsFigExecutor)
logger = logging.getLogger(__name__)
# config_pyilc_t_HILC_backup
@hydra.main(version_base=None, config_path="cfg", config_name="config_pyilc")
def run_pyilc_analysis(cfg):
logger.debug(f"Running {__name__} in {__file__}")
log_maker = LogMaker(cfg)
log_maker.log_procedure_to_hydra(source_script=__file__)
pipeline_context = PipelineContext(cfg, log_maker)
pipeline_context.add_pipe(HydraConfigCheckerExecutor)
# In the following, "Common" means "Apply the same postprocessing to all models"; requires a mask
# Apply to the target (CMB realization)
pipeline_context.add_pipe(CommonRealPostExecutor)
pipeline_context.add_pipe(CommonPyILCPredPostExecutor)
# Show results of cleaning
pipeline_context.add_pipe(CommonNILCShowSimsPostExecutor)
pipeline_context.add_pipe(CommonNILCShowSimsPostIndivExecutor)
pipeline_context.add_pipe(PixelAnalysisExecutor)
pipeline_context.add_pipe(PixelSummaryExecutor)
pipeline_context.add_pipe(PixelSummaryFigsExecutor)
# # Not needed in every analysis pipeline, but needed in one
pipeline_context.add_pipe(ConvertTheoryPowerSpectrumExecutor)
pipeline_context.add_pipe(MakeTheoryPSStats)
# PyILC's Predictions as Power Spectra Anaylsis
pipeline_context.add_pipe(PyILCMakePSExecutor)
# # pipeline_context.add_pipe(ShowOnePSExecutor) # Used for debugging; does not require full set of theory ps for simulations
pipeline_context.add_pipe(PowerSpectrumAnalysisExecutor)
pipeline_context.add_pipe(PowerSpectrumSummaryExecutor)
pipeline_context.add_pipe(PowerSpectrumSummaryFigsExecutor)
pipeline_context.add_pipe(PostAnalysisPsFigExecutor)
pipeline_context.prerun_pipeline()
try:
pipeline_context.run_pipeline()
except Exception as e:
logger.exception("An exception occured during the pipeline.", exc_info=e)
raise e
finally:
logger.info("Pipeline completed.")
log_maker.copy_hydra_run_to_dataset_log()
if __name__ == "__main__":
validate_environment_variable("CMB_ML_LOCAL_SYSTEM")
run_pyilc_analysis()