Skip to content

Commit

Permalink
use better test for exiting fopen context
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiang87 committed Sep 12, 2018
1 parent 196408b commit ac5de90
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions python/desc/imsim/trim.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def degrees_separation(ra0, dec0, ra, dec):
np.radians(ra), np.radians(dec)))

class Disaggregator:
""".
Class to disaggregate instance catalog object lines into per chip
"""
Class to disaggregate instance catalog object lines per chip using
acceptance cones.
"""
def __init__(self, object_lines, trimmer):
Expand Down Expand Up @@ -170,13 +170,12 @@ def _process_objects(self, sensor_list, chunk_size, radius=0.18,
for each sensor using the Disaggregator class to apply the
acceptance cone cut centered on each sensor.
"""
num_lines = self._get_num_lines() if numRows is None else numRows
self.update({sensor: [] for sensor in sensor_list})
with desc.imsim.fopen(self.instcat_file, mode='rt') as fd:
nread = 0
while nread < num_lines:
while numRows is None or nread < numRows:
object_lines = []
for _, line in zip(range(chunk_size), fd):
for ichunk, line in zip(range(chunk_size), fd):
nread += 1
if not line.startswith('object'):
continue
Expand All @@ -186,18 +185,8 @@ def _process_objects(self, sensor_list, chunk_size, radius=0.18,
obj_list = disaggregator.get_object_entries(sensor,
radius=radius)
self[sensor].extend(obj_list)

def _get_num_lines(self):
"""
Get the total number of lines in the instance catalog.
This is needed for the exit condition in the _process_objects
method.
"""
num_lines = 0
with desc.imsim.fopen(self.instcat_file, mode='rt') as fd:
for _ in fd:
num_lines += 1
return num_lines
if ichunk < chunk_size - 1:
break

def _read_commands(self):
"""Read in the commands from the instance catalog."""
Expand Down

0 comments on commit ac5de90

Please sign in to comment.