Skip to content

try except in summartStar #2

@sousasag

Description

@sousasag

try:
fileName = np.array(search['ARCFILE'])
spectrograph = np.array(search['Instrument'])
obsDate = np.array(search['Date Obs'])
snr = np.array(search['SNR (spectra)'])
#number of spectra
print('Total number of spectra found: {0}'.format(snr.size), file = f)
value, count = np.unique(spectrograph, return_counts=True)
for i in range(value.size):
specSNR = search[search['Instrument']==value[i]]['SNR (spectra)']
quadSum = np.sqrt(np.sum(specSNR**2))
print('\n{0} spectra: {1}'.format(value[i], count[i]), '|',
'SNR Quadradratic Sum: {0}'.format(quadSum), file = f)
comparison = search[search['Instrument']==value[i]]['SNR (spectra)']
maxSNRpos = np.argmax(comparison)
print('Maximum SNR: {0}'.format(comparison[maxSNRpos]), file=f)
minSNRpos = np.argmin(comparison)
print('Minimum SNR: {0}'.format(comparison[minSNRpos]), file=f)
#spectra found
if printFiles:
print('ARCFILE\tInstrument\tObservationDate\tSNR', file = f)
for i, j in enumerate(fileName):
print('{0}\t{1}\t{2}\t{3}'.format(j, spectrograph[i],
obsDate[i], snr[i]), file = f)
if saveFile:
f.close()
except:
print('{0} not found in archive\n'.format(star), file = f)

Comment on this part of the code:
This try except is a "bit" to large, the exception catch everything, the message might be misleading.

You need to include the try only where the specific problem might occur, or alternative, you have to catch the correct exception...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions