Skip to content

Commit 60a3926

Browse files
committed
Update config interaction. Not yet working
1 parent 951df26 commit 60a3926

File tree

8 files changed

+136
-77
lines changed

8 files changed

+136
-77
lines changed

lya_2pt/defaults.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
cosmo = {
3+
"use-picca-cosmo": False,
4+
"omega_m": 0.315,
5+
"omega_r": 7.963219132297603e-05,
6+
"hubble-constant": 67.36,
7+
"use-h-units": True,
8+
"omega_k": 0.0,
9+
"w0": -1,
10+
}
11+
12+
13+
settings = {
14+
"nside": 16,
15+
"num-cpu": 1,
16+
"z_min": 0,
17+
"z_max": 10,
18+
"rp_min": 0,
19+
"rp_max": 200,
20+
"rt_max": 200,
21+
"num_bins_rp": 50,
22+
"num_bins_rt": 50,
23+
"num_bins_rp_model": 50,
24+
"num_bins_rt_model": 50,
25+
"rejection_fraction": 0.99,
26+
"get-old-distortion": True
27+
}
28+
29+
tracer_reader = {
30+
"tracer-type": "continuous",
31+
"absorption-line": "LYA",
32+
"project-deltas": True,
33+
"projection-order": 1,
34+
"use-old-projection": True,
35+
"rebin": 1,
36+
"redshift-evolution": 2.9,
37+
"reference-redshift": 2.25,
38+
}
39+
40+
output = {
41+
"name": "lyaxlya",
42+
}
43+
44+
export = {
45+
"export-correlation": False,
46+
"export-distortion": False,
47+
"smooth-covariance": True,
48+
}

lya_2pt/export.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from multiprocessing import Pool
44

55
from lya_2pt.utils import parse_config
6+
from lya_2pt import defaults
67

7-
accepted_options = [
8-
"export-correlation", "export-distortion", "smooth-covariance"
9-
]
8+
# accepted_options = [
9+
# "export-correlation", "export-distortion", "smooth-covariance"
10+
# ]
1011

11-
defaults = {
12-
"export-correlation": False,
13-
"export-distortion": False,
14-
"smooth-covariance": True,
15-
}
12+
# defaults = {
13+
# "export-correlation": False,
14+
# "export-distortion": False,
15+
# "smooth-covariance": True,
16+
# }
1617

1718

1819
class Export:
@@ -22,7 +23,7 @@ class Export:
2223
Writes final correlation
2324
"""
2425
def __init__(self, config, name, output_directory, num_cpu):
25-
self.config = parse_config(config, defaults, accepted_options)
26+
self.config = parse_config(config, defaults.export)
2627

2728
self.num_cpu = num_cpu
2829
self.name = name

lya_2pt/forest_healpix_reader.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
from lya_2pt.errors import ReaderException
77
from lya_2pt.utils import parse_config
88
from lya_2pt.read_io import read_from_image, read_from_hdu
9-
10-
accepted_options = [
11-
"input-dir", "tracer-type", "absorption-line", "project-deltas",
12-
"projection-order", "use-old-projection", "rebin",
13-
"redshift-evolution", "reference-redshift"
14-
]
15-
16-
defaults = {
17-
"tracer-type": "continuous",
18-
"absorption-line": "LYA",
19-
"project-deltas": True,
20-
"projection-order": 1,
21-
"use-old-projection": True,
22-
"rebin": 1,
23-
"redshift-evolution": 2.9,
24-
"reference-redshift": 2.25,
25-
}
9+
from lya_2pt import defaults
10+
11+
# accepted_options = [
12+
# "input-dir", "tracer-type", "absorption-line", "project-deltas",
13+
# "projection-order", "use-old-projection", "rebin",
14+
# "redshift-evolution", "reference-redshift"
15+
# ]
16+
17+
# defaults = {
18+
# "tracer-type": "continuous",
19+
# "absorption-line": "LYA",
20+
# "project-deltas": True,
21+
# "projection-order": 1,
22+
# "use-old-projection": True,
23+
# "rebin": 1,
24+
# "redshift-evolution": 2.9,
25+
# "reference-redshift": 2.25,
26+
# }
2627

2728

2829
class ForestHealpixReader:
@@ -73,7 +74,7 @@ def __init__(self, config, file, cosmo, auto_flag=False, need_distortion=False):
7374
ReaderException if the blinding strategy is not valid
7475
"""
7576
# parse configuration
76-
reader_config = parse_config(config, defaults, accepted_options)
77+
reader_config = parse_config(config, defaults.tracer_reader)
7778
self.healpix_id = int(file.name.split("delta-")[-1].split(".fits")[0])
7879

7980
# extract parameters from config

lya_2pt/interface.py

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,41 @@
22

33
import numpy as np
44
import tqdm
5+
from lyacosmo import AstropyCosmo, PiccaCosmo
56

67
import lya_2pt.global_data as globals
78
from lya_2pt.correlation import compute_xi
89
from lya_2pt.distortion import compute_dmat
9-
from lya_2pt.cosmo import Cosmology
10+
# from lya_2pt.cosmo import Cosmology
1011
from lya_2pt.forest_healpix_reader import ForestHealpixReader
1112
from lya_2pt.tracer2_reader import Tracer2Reader
1213
from lya_2pt.utils import find_path, parse_config, compute_ang_max
1314
from lya_2pt.output import Output
1415
from lya_2pt.export import Export
15-
16-
accepted_options = [
17-
"nside", "num-cpu", "z_min", "z_max", "rp_min", "rp_max", "rt_max",
18-
"num_bins_rp", "num_bins_rt", "num_bins_rp_model", "num_bins_rt_model",
19-
"rejection_fraction", "get-old-distortion"
20-
]
21-
22-
defaults = {
23-
"nside": 16,
24-
"num-cpu": 1,
25-
"z_min": 0,
26-
"z_max": 10,
27-
"rp_min": 0,
28-
"rp_max": 200,
29-
"rt_max": 200,
30-
"num_bins_rp": 50,
31-
"num_bins_rt": 50,
32-
"num_bins_rp_model": 50,
33-
"num_bins_rt_model": 50,
34-
"rejection_fraction": 0.99,
35-
"get-old-distortion": True
36-
}
16+
from lya_2pt import defaults
17+
18+
19+
# accepted_options = [
20+
# "nside", "num-cpu", "z_min", "z_max", "rp_min", "rp_max", "rt_max",
21+
# "num_bins_rp", "num_bins_rt", "num_bins_rp_model", "num_bins_rt_model",
22+
# "rejection_fraction", "get-old-distortion"
23+
# ]
24+
25+
# defaults = {
26+
# "nside": 16,
27+
# "num-cpu": 1,
28+
# "z_min": 0,
29+
# "z_max": 10,
30+
# "rp_min": 0,
31+
# "rp_max": 200,
32+
# "rt_max": 200,
33+
# "num_bins_rp": 50,
34+
# "num_bins_rt": 50,
35+
# "num_bins_rp_model": 50,
36+
# "num_bins_rt_model": 50,
37+
# "rejection_fraction": 0.99,
38+
# "get-old-distortion": True
39+
# }
3740

3841

3942
class Interface:
@@ -79,11 +82,23 @@ def __init__(self, config):
7982
"""
8083
self.config = config
8184

82-
# intialize cosmology
83-
self.cosmo = Cosmology(config["cosmology"])
85+
# Intialize cosmology
86+
cosmo_config = parse_config(config["cosmology"], defaults.cosmo)
87+
if cosmo_config.getboolean("use-picca-cosmo"):
88+
self.cosmo = PiccaCosmo(
89+
cosmo_config.getfloat('omega_m'), cosmo_config.getfloat('omega_k'),
90+
cosmo_config.getfloat('omega_r'), cosmo_config.getfloat('w0')
91+
)
92+
else:
93+
self.cosmo = AstropyCosmo(
94+
cosmo_config.getfloat('omega_m'), cosmo_config.getfloat('omega_k'),
95+
cosmo_config.getfloat('omega_r'), cosmo_config.getfloat('w0'),
96+
cosmo_config.getfloat('hubble-constant'), cosmo_config.getboolean('use-h-units'),
97+
)
98+
# self.cosmo = Cosmology(config["cosmology"])
8499

85100
# parse config
86-
self.settings = parse_config(config["settings"], defaults, accepted_options)
101+
self.settings = parse_config(config["settings"], defaults.settings)
87102
globals.z_min = self.settings.getfloat("z_min")
88103
globals.z_max = self.settings.getfloat("z_max")
89104
globals.rp_min = self.settings.getfloat('rp_min')

lya_2pt/output.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import fitsio
22

33
from lya_2pt.utils import check_dir, parse_config, find_path
4+
from lya_2pt import defaults
45

5-
accepted_options = [
6-
"name", "output-dir"
7-
]
6+
# accepted_options = [
7+
# "name", "output-dir"
8+
# ]
89

9-
defaults = {
10-
"name": "lyaxlya",
11-
}
10+
# defaults = {
11+
# "name": "lyaxlya",
12+
# }
1213

1314

1415
class Output:
1516
def __init__(self, config):
16-
self.config = parse_config(config, defaults, accepted_options)
17+
self.config = parse_config(config, defaults.output)
1718
self.name = self.config.get('name')
1819
self.output_directory = find_path(self.config.get('output-dir'), enforce=False)
1920
check_dir(self.output_directory)

lya_2pt/tracer2_reader.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
from lya_2pt.forest_healpix_reader import ForestHealpixReader
88
from lya_2pt.utils import find_path, parse_config
99
from lya_2pt.errors import ReaderException
10+
from lya_2pt import defaults
1011

1112
# Read defaults from the healpix reader and add tracer2 specific options
12-
accepted_options = forest_healpix_reader.accepted_options
13-
accepted_options += []
13+
# accepted_options = forest_healpix_reader.accepted_options
14+
# accepted_options += []
1415

15-
defaults = forest_healpix_reader.defaults
16-
defaults |= {}
16+
# defaults = forest_healpix_reader.defaults
17+
# defaults |= {}
1718

1819

1920
class Tracer2Reader:
@@ -44,7 +45,7 @@ def __init__(self, config, healpix_neighbours, cosmo, num_cpu, need_distortion=F
4445
Fiducial cosmology used to go from angles and redshift to distances
4546
"""
4647
# parse configuration
47-
reader_config = parse_config(config, defaults, accepted_options)
48+
reader_config = parse_config(config, defaults.tracer_reader)
4849

4950
self.tracers = {}
5051

lya_2pt/utils.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from lya_2pt.errors import ParserError
99

1010

11-
def parse_config(config, defaults, accepted_options):
11+
def parse_config(config, defaults):
1212
"""Parse the given configuration
1313
1414
Check that all required variables are present
@@ -22,9 +22,6 @@ def parse_config(config, defaults, accepted_options):
2222
defaults: dict
2323
The default options for the given config section
2424
25-
accepted_options: list of str
26-
The accepted keys for the given config section
27-
2825
Return
2926
------
3027
config: configparser.SectionProxy
@@ -35,17 +32,11 @@ def parse_config(config, defaults, accepted_options):
3532
if key not in config:
3633
config[key] = str(value)
3734

38-
# make sure all the required variables are present
39-
for key in accepted_options:
40-
if key not in config:
41-
raise ParserError(f"Missing option {key}")
42-
4335
# check that all arguments are valid
4436
for key in config:
45-
if key not in accepted_options:
37+
if key not in defaults:
4638
raise ParserError(
47-
f"Unrecognised option. Found: '{key}'. Accepted options are "
48-
f"{accepted_options}")
39+
f"Unrecognised option. Found: '{key}'. Accepted options are {defaults.keys()}")
4940

5041
return config
5142

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ scipy
33
astropy
44
healpy
55
fitsio
6+
lyacosmo
67
numba
78
setuptools
89
gitpython

0 commit comments

Comments
 (0)