Skip to content

Commit

Permalink
Removed last old style readers returning dict
Browse files Browse the repository at this point in the history
  • Loading branch information
andLaing committed Feb 28, 2020
1 parent 4872453 commit 6ca6062
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 76 deletions.
50 changes: 0 additions & 50 deletions invisible_cities/io/mcinfo_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ def __call__(self, mctables: (tb.Table, tb.Table, tb.Table, tb.Table),
self.generator_table.flush()


def load_mchits(file_name: str,
event_range=(0, int(1e9))) -> Mapping[int, Sequence[MCHit]]:

with tb.open_file(file_name, mode='r') as h5in:
mchits_dict = read_mchit_info(h5in, event_range)

return mchits_dict


def load_mchits_df(file_name : str) -> pd.DataFrame:
"""
Opens file and calls read_mchits_df
Expand Down Expand Up @@ -482,44 +473,3 @@ def read_mcinfo_evt (mctables: (tb.Table, tb.Table, tb.Table, tb.Table), event_n
break

return hit_rows, particle_rows, generator_rows


def compute_mchits_dict(mcevents:Mapping[int, Mapping[int, MCParticle]]) -> Mapping[int, Sequence[MCHit]]:
"""Returns all hits in the event"""
mchits_dict = {}
for event_no, particle_dict in mcevents.items():
hits = []
for particle_no in particle_dict.keys():
particle = particle_dict[particle_no]
hits.extend(particle.hits)
mchits_dict[event_no] = hits
return mchits_dict


def read_mchit_info(h5f, event_range=(0, int(1e9))) -> Mapping[int, Sequence[MCHit]]:
"""Returns all hits in the event"""
mc_info = tbl.get_mc_info(h5f)
h5extents = mc_info.extents
events_in_file = len(h5extents)

all_events = {}

for iext in range(*event_range):
if iext >= events_in_file:
break

current_event = {}
evt_number = h5extents[iext]['evt_number']
hit_rows, _, _ = read_mcinfo_evt(mc_info, evt_number, iext, True)

hits = []
for h5hit in hit_rows:
hit = MCHit(h5hit['hit_position'],
h5hit['hit_time'],
h5hit['hit_energy'],
h5hit['label'].decode('utf-8','ignore'))
hits.append(hit)

all_events[evt_number] = hits

return all_events
26 changes: 0 additions & 26 deletions invisible_cities/io/mcinfo_io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from os.path import expandvars
from numpy.testing import assert_allclose

from . mcinfo_io import load_mchits
from . mcinfo_io import load_mchits_df
from . mcinfo_io import read_mchits_df
from . mcinfo_io import load_mcparticles_df
Expand Down Expand Up @@ -175,31 +174,6 @@ def test_mc_info_writer_filter_first_event_of_first_file(output_tmpdir, ICDATADI
assert all(x<y for x, y in zip(last_hit_list, last_hit_list[1:]))



def test_load_mchits_correct_number_of_hits(mc_all_hits_data):
efile, number_of_hits, evt_number = mc_all_hits_data
mchits_dict = load_mchits(efile)

assert len(mchits_dict[evt_number]) == number_of_hits


def test_load_mchits(mc_particle_and_hits_nexus_data):
efile, _, _, _, _, _, _, X, Y, Z, E, t = mc_particle_and_hits_nexus_data

mchits_dict = load_mchits(efile)
hX = [hit.X for hit in mchits_dict[0]]
hY = [hit.Y for hit in mchits_dict[0]]
hZ = [hit.Z for hit in mchits_dict[0]]
hE = [hit.E for hit in mchits_dict[0]]
ht = [hit.time for hit in mchits_dict[0]]

assert np.allclose(X, hX)
assert np.allclose(Y, hY)
assert np.allclose(Z, hZ)
assert np.allclose(E, hE)
assert np.allclose(t, ht)


def test_read_mchits_df(mc_particle_and_hits_nexus_data):
efile, _, _, _, _, _, _, X, Y, Z, E, t = mc_particle_and_hits_nexus_data

Expand Down

0 comments on commit 6ca6062

Please sign in to comment.