From 645fc5d4e0db196ef29f5bdf3f502150b96dd867 Mon Sep 17 00:00:00 2001 From: Shane Maloney Date: Sat, 30 Oct 2021 17:36:49 +0100 Subject: [PATCH] Update spectrogram for other spectrogram in eCallisto archive --- radiospectra/spectrogram2/spectrogram.py | 52 ++++++++++++++---------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/radiospectra/spectrogram2/spectrogram.py b/radiospectra/spectrogram2/spectrogram.py index 1ad504b..a4515ea 100644 --- a/radiospectra/spectrogram2/spectrogram.py +++ b/radiospectra/spectrogram2/spectrogram.py @@ -631,28 +631,7 @@ def _read_cdf(file): def _read_fits(file): hd_pairs = fits.read(file) - if 'e-CALLISTO' in hd_pairs[0].header.get('CONTENT', ''): - data = hd_pairs[0].data - times = hd_pairs[1].data['TIME'].flatten() * u.s - freqs = hd_pairs[1].data['FREQUENCY'].flatten() * u.MHz - start_time = parse_time(hd_pairs[0].header['DATE-OBS'] - + ' ' + hd_pairs[0].header['TIME-OBS']) - end_time = parse_time(hd_pairs[0].header['DATE-END'] - + ' ' + hd_pairs[0].header['TIME-END']) - times = start_time + times - meta = { - 'fits_meta': hd_pairs[0].header, - 'detector': 'e-CALLISTO', - 'instrument': 'e-CALLISTO', - 'observatory': hd_pairs[0].header['INSTRUME'], - 'start_time': start_time, - 'end_time': end_time, - 'wavelength': a.Wavelength(freqs.min(), freqs.max()), - 'times': times, - 'freqs': freqs - } - return data, meta - elif hd_pairs[0].header.get('TELESCOP', '') == 'EOVSA': + if hd_pairs[0].header.get('TELESCOP', '') == 'EOVSA': times = Time(hd_pairs[2].data['mjd'] + hd_pairs[2].data['time'] / 1000.0 / 86400., format='mjd') freqs = hd_pairs[1].data['sfreq'] * u.GHz @@ -673,6 +652,35 @@ def _read_fits(file): } return data, meta + # semi standard - spec in primary and time and freq in 1st extension + try: + data = hd_pairs[0].data + times = hd_pairs[1].data['TIME'].flatten() * u.s + freqs = hd_pairs[1].data['FREQUENCY'].flatten() * u.MHz + start_time = parse_time(hd_pairs[0].header['DATE-OBS'] + + ' ' + hd_pairs[0].header['TIME-OBS']) + end_time = parse_time(hd_pairs[0].header['DATE-END'] + + ' ' + hd_pairs[0].header['TIME-END']) + times = start_time + times + meta = { + 'fits_meta': hd_pairs[0].header, + 'start_time': start_time, + 'end_time': end_time, + 'wavelength': a.Wavelength(freqs.min(), freqs.max()), + 'times': times, + 'freqs': freqs, + 'instrument': hd_pairs[0].header.get('INSTRUME', ''), + 'observatory': hd_pairs[0].header.get('INSTRUME', ''), + 'detector': hd_pairs[0].header.get('DETECTOR', ''), + } + if 'e-CALLISTO' in hd_pairs[0].header['CONTENT']: + meta['detector'] = 'e-CALLISTO' + meta['instrument'] = 'e-CALLISTO' + + return data, meta + except KeyError: + raise ValueError('Could not load fits file into spectrogram') + @staticmethod def _read_idl_sav(file, instrument=None): data = readsav(file)