-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.py
76 lines (65 loc) · 3.11 KB
/
input.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
import yaml
import numpy as np
##########################
# simple function for opening the file
def read_dict_from_yaml(yaml_file):
assert(yaml_file != None)
with open(yaml_file) as f:
config = yaml.safe_load(f)
return config
##########################
##########################
"""
class that contains map info (and associated data), specifications, etc., and handles input
"""
class Info(object):
def __init__(self, input_file, mask_provided=True):
self.input_file = input_file
p = read_dict_from_yaml(self.input_file)
#If mask needs to be created
if not mask_provided:
self.nsims = p['nsims']
assert type(self.nsims) is int and self.nsims>=0, "nsims"
self.ellmax = p['ellmax']
assert type(self.ellmax) is int and self.ellmax>=0, "ellmax"
self.ell_sum_max = p['ell_sum_max']
assert type(self.ell_sum_max) is int and self.ell_sum_max>=self.ellmax, "ell_sum_max"
self.remove_high_ell_power = p['remove_high_ell_power']
self.nside = p['nside']
assert type(self.nside) is int and (self.nside & (self.nside-1) == 0) and self.nside != 0, "nside"
assert self.ellmax <= 3*self.nside-1, "ellmax > 3*nside-1"
self.nside_for_masking = p['nside_for_masking']
assert type(self.nside_for_masking) is int and (self.nside_for_masking & (self.nside_for_masking-1) == 0) and self.nside_for_masking != 0, "nside_for_masking"
self.comp = p['comp']
assert type(self.comp) is str and self.comp in ['ISW', 'CMB'], "comp"
self.cut = p['cut']
self.aposcale = p['aposcale']
self.cut_high = p['cut_high']
self.cut_low = p['cut_low']
self.map_file = p['map_file']
assert type(self.map_file) is str
self.wigner_file = p['wigner_file']
assert type(self.wigner_file) is str
self.output_dir = p['output_dir']
assert type(self.output_dir) is str
self.save_files = p['save_files']
self.plot = p['plot']
#If doing single realization with specified map and mask
else:
self.ellmax = p['ellmax']
assert type(self.ellmax) is int and self.ellmax>=0, "ellmax"
self.ell_sum_max = p['ell_sum_max']
assert type(self.ell_sum_max) is int and self.ell_sum_max>=self.ellmax, "ell_sum_max"
self.nside = p['nside']
assert type(self.nside) is int and (self.nside & (self.nside-1) == 0) and self.nside != 0, "nside"
assert self.ellmax <= 3*self.nside-1, "ellmax > 3*nside-1"
self.map_file = p['map_file']
assert type(self.map_file) is str
self.mask_file = p['mask_file']
assert type(self.mask_file) is str
self.wigner_file = p['wigner_file']
assert type(self.wigner_file) is str
self.output_dir = p['output_dir']
assert type(self.output_dir) is str
self.save_files = p['save_files']
self.plot = p['plot']