Skip to content

Commit

Permalink
Generate new (small) dataio test dataset. Fix issue with make_megalib…
Browse files Browse the repository at this point in the history
…_test_file.py, function now requires output_name
  • Loading branch information
israelmcmc committed May 7, 2024
1 parent c8eb536 commit 124d47b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cosipy/data_io/ReadTraTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ReadTraTest(UnBinnedData):

"""Old method for reading tra file, used for unit testing."""

def read_tra_old(self,make_plots=True):
def read_tra_old(self, output_name, make_plots=True):

"""Reads in MEGAlib .tra (or .tra.gz) file.
Expand Down Expand Up @@ -202,7 +202,7 @@ def read_tra_old(self,make_plots=True):
self.cosi_dataset = cosi_dataset

# Write unbinned data to file (either fits or hdf5):
self.write_unbinned_output()
self.write_unbinned_output(output_name)

return

Binary file modified cosipy/test_data/unbinned_data_MEGAlib_calc.hdf5
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/dataIO/make_megalib_test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
yaml = os.path.join(test_data.path,"inputs_crab.yaml")
analysis = ReadTraTest(yaml)
analysis.data_file = os.path.join(test_data.path,analysis.data_file)
analysis.read_tra_old(make_plots=False)
analysis.read_tra_old(output_name = test_data.path/"unbinned_data_MEGAlib_calc", make_plots=False)
7 changes: 4 additions & 3 deletions tests/dataIO/test_unbinned_data_with_MEGAlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ def test_unbinned_data_with_MEGAlib():
chi_loc_dict,psi_loc_dict,chi_gal_dict,psi_gal_dict]
for each in test_list:
diff = compare(each["old"],each["new"],each["name"],make_plots=False)
if np.amax(diff) > 1e-12:
bad_index = diff > 1e-12
thresh = 1e-12
if np.amax(diff) > thresh:
bad_index = diff > thresh
len_bad = len(each["new"][bad_index])
len_tot = len(each["new"])
bad_frac = len_bad/len_tot
raise Exception(f"WARNING: Definition does not match MEGAlib: {each['name']}. "
f"Fraction with diff > 1e-12: {bad_frac}. "
f"Fraction with diff > {thresh}: {bad_frac}. "
f"Max difference: {np.amax(np.absolute(diff))} {each['units']}")
else:
print("Passed: %s" %each["name"])

0 comments on commit 124d47b

Please sign in to comment.