Skip to content

Commit

Permalink
More CPUs if available, and fix paths for TS significance.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdstein committed Jul 16, 2020
1 parent 6936940 commit d1fd0d7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions flarestack/cluster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def analyse(mh_dict, cluster=False, n_cpu=None, **kwargs):

path = make_analysis_pickle(mh_dict)

print(path)

job_id = None

if cluster:
Expand All @@ -49,6 +51,8 @@ def analyse(mh_dict, cluster=False, n_cpu=None, **kwargs):
else:
if n_cpu is None:
n_cpu = min(os.cpu_count() - 1, 32)
else:
n_cpu = min(n_cpu, os.cpu_count() -1)
submit_local(mh_dict, n_cpu=n_cpu)

return job_id
20 changes: 13 additions & 7 deletions flarestack/core/unblinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def add_injector(self, season, sources):
def calculate_upper_limits(self):

try:
ul_dir = self.plot_dir + "upper_limits/"
ul_dir = os.path.join(self.plot_dir, "upper_limits/")
try:
os.makedirs(ul_dir)
except OSError:
Expand All @@ -182,9 +182,14 @@ def calculate_upper_limits(self):
x_axis = []

for subdir in os.listdir(self.pickle_dir):
new_path = self.unblind_dict["background_ts"] + subdir + "/"
with open(analysis_pickle_path(name=new_path), "rb") as f:
logging.info(f'Opening file {analysis_pickle_path(name=new_path)}')

root = os.path.join(self.unblind_dict["background_ts"], subdir)

new_path = analysis_pickle_path(name=root)

logging.info(f'Opening file {new_path}')

with open(new_path, "rb") as f:
mh_dict = pickle.load(f)
e_pdf_dict = mh_dict["inj_dict"]["injection_energy_pdf"]

Expand Down Expand Up @@ -287,7 +292,7 @@ def calculate_upper_limits(self):
with open(self.limit_path, "wb") as f:
pickle.dump(res_dict, f)

except (OSError, AttributeError) as e:
except AttributeError as e:
logging.warning("Unable to set limits. No TS distributions found.")

def compare_to_background_TS(self):
Expand All @@ -298,7 +303,8 @@ def compare_to_background_TS(self):
ts_array = list()

for subdir in os.listdir(self.pickle_dir):
merged_pkl = os.path.join(self.pickle_dir, os.path.join(subdir, "/merged/0.pkl"))

merged_pkl = os.path.join(os.path.join(self.pickle_dir, subdir), "merged/0.pkl")

logging.info("Loading {0}".format(merged_pkl))

Expand All @@ -318,7 +324,7 @@ def compare_to_background_TS(self):
try:
ts_array = list()

merged_pkl = os.path.join(self.pickle_dir,"merged/0.pkl")
merged_pkl = os.path.join(self.pickle_dir, "merged/0.pkl")

logging.info("No subfolders found, loading {0}".format(merged_pkl))

Expand Down
4 changes: 2 additions & 2 deletions tests/test_full_analysis_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def test_full_chain(self):
"scale": [3., 500.][j]
}

analyse(mh_dict, n_cpu=2, cluster=False)
analyse(mh_dict, n_cpu=24, cluster=False)

rh = ResultsHandler(mh_dict)

# Deliberately test a second time, to see performamnce once results have been combined
# Deliberately test a second time, to see performance once results have been combined

rh = ResultsHandler(mh_dict)

Expand Down

0 comments on commit d1fd0d7

Please sign in to comment.