Skip to content

Commit 728ddba

Browse files
authored
Merge pull request #542 from lmauviard/285-make-instrument-errors-explicit
Made warning and error messages in Instrument more explicit
2 parents 63c0303 + 63925fc commit 728ddba

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

xpsi/Instrument.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ def matrix(self, matrix):
132132
for j in range(matrix.shape[1]):
133133
assert matrix[:,j].any()
134134
except AssertionError:
135-
raise ResponseError('Each row and column of the matrix must contain at least one positive number.'
136-
' Try reducing the \"gap\" between the minimum input energy '
137-
'and minimum input channel.')
135+
raise ResponseError('Each row and column of the matrix must contain at least one positive number.')
138136
self._matrix = matrix
139137

140138
def construct_matrix(self):
@@ -290,20 +288,19 @@ def channels(self, channel_array):
290288
try:
291289
channel_array = _np.array(channel_array)
292290
except TypeError:
293-
raise ChannelError('Channel numbers must be in a one-dimensional array of positive integers'
294-
'(including zero).')
291+
raise ChannelError('Channel numbers must be in an array.')
295292

296293
try:
297294
assert channel_array.ndim == 1
298295
assert (channel_array >= 0).all()
299296
assert channel_array.shape[0] == self._matrix.shape[0]
300297
except AssertionError:
301-
raise ChannelError('Channel numbers must be in a one-dimensional array of positive integers'
302-
'(including zero).')
298+
raise ChannelError('Channel numbers must be in a one-dimensional array of positive integers (including zero), with a '
299+
'length equal to the number of channel in the matrix.')
300+
303301

304302
if (channel_array[1:] - channel_array[:-1] != 1).any():
305-
yield ('Warning: Channel numbers do not uniformly increment by one.\n'
306-
' Please check for correctness.')
303+
print('WARNING: Channel numbers do not uniformly increment by one.')
307304

308305
self._channels = channel_array
309306

@@ -355,9 +352,11 @@ def trim_response(self,
355352

356353
# Print if any trimming happens
357354
if empty_inputs.sum() > 0:
358-
print(f'Triming the response matrix because it contains lines with only values <= {threshold}.\n Now min energy={self.energy_edges[0]} and max_input={self.energy_edges[-1]}')
355+
print(f'Triming the response matrix because it contains rows with only values <= {threshold}.\n '
356+
f'Now min_energy={self.energy_edges[0]} and max_energy={self.energy_edges[-1]}')
359357
if empty_channels.sum() > 0:
360-
print(f'Triming the response matrix because it contains columns with only values <= {threshold}.\n Now min_channel={self.channels[0]} and max_channel={self.channels[-1]}')
358+
print(f'Triming the response matrix because it contains columns with only values <= {threshold}.\n '
359+
f'Now min_channel={self.channels[0]} and max_channel={self.channels[-1]}')
361360

362361
# If ARF and RMF, trim them
363362
if hasattr( self , 'ARF' ):
@@ -478,9 +477,11 @@ def from_ogip_fits(cls,
478477
channels = channels[ ~empty_channels ]
479478
inputs = inputs[ ~empty_inputs ]
480479
if empty_inputs.sum() > 0:
481-
print(f'Triming the response matrix because it contains lines with only 0 values.\n Now min_input={inputs[0]} and max_input={inputs[-1]}')
480+
print(f'Triming the response matrix because it contains rows with only 0 values.\n '
481+
f'Now min_energy={inputs[0]} and max_energy={inputs[-1]}')
482482
if empty_channels.sum() > 0:
483-
print(f'Triming the response matrix because it contains columns with only 0 values.\n Now min_channel={channels[0]} and max_channel={channels[-1]}')
483+
print(f'Triming the response matrix because it contains columns with only 0 values.\n'
484+
f' Now min_channel={channels[0]} and max_channel={channels[-1]}')
484485

485486
# Get the edges of energies for both input and channel
486487
energy_edges = _np.append( RMF_MATRIX['ENERG_LO'][inputs-1], RMF_MATRIX['ENERG_HI'][inputs[-1]-1]).astype(dtype=_np.double)

0 commit comments

Comments
 (0)