Exemple #1
0
    def loop(self, debug=False):
        """
        Loop over the HILT files and run the following steps:
        - get the date from the file name,
        - verify that SAMPEX was not in spin mode,
        - load and resolve the 20 ms HILT file,
        - Run the microburst detection code on it, and
        - save to self.microbursts.
        """
        self.get_file_names()
        self.load_spin_times()
        self.microburst_times = pd.DataFrame(
            data=np.zeros((0, 2)), columns=['dateTime', 'burst_param'])

        for hilt_file in progressbar.progressbar(self.hilt_files,
                                                 redirect_stdout=True):
            date = self.get_filename_date(hilt_file)

            # Skip if the file name date was during the SAMPEX spin.
            # OR the data is from 1996
            if self.date_during_spin(date) or (date.year == 1996):
                continue

            # Load the data
            try:
                self.hilt_obj = load_hilt_data.Load_SAMPEX_HILT(date)
            except RuntimeError as err:
                if str(err) == "The SAMPEX HITL data is not in order.":
                    continue
                else:
                    raise
            # Resolve the 20 ms data
            self.hilt_obj.resolve_counts_state4()

            # Use the hilt data to id microbursts
            try:
                self.id_microbursts(debug=debug)
            except ValueError as err:
                if str(err) == 'No detections found':
                    print(err, hilt_file.name)
                    continue
                else:
                    raise
            # self.test_detections()
        return
Exemple #2
0
    def plot(self):
        """ 
        Given a self.current_row in the dataframe, make a space-time plot 
        """

        # DEBUG
        curframe = inspect.currentframe()
        calframe = inspect.getouterframes(curframe, 2)
        print('caller name:', calframe[1][3])

        current_row = self.catalog.iloc[self.index]
        current_time = self.catalog.index[self.index]
        print(f'Index position = {self.index}/{self.catalog.shape[0]-1} | '
              f'at time = {current_time}')
        self.index_box.set_val(self.index)
        self._clear_ax()

        if current_time.date() != self.prev_date:
            # Load current day AC-6 data if not loaded already
            print('Loading data from {}...'.format(current_time.date()),
                  end=' ',
                  flush=True)
            l = load_hilt_data.Load_SAMPEX_HILT(current_time)
            l.resolve_counts_state4()
            self.hilt = l.hilt_resolved
            self.prev_date = current_time.date()
            print('done.')

        # Turn microburst button green if this index has been marked as a microburst.
        if self.index in self.microburst_idx:
            self.bmicroburst.color = 'g'
        else:
            self.bmicroburst.color = '0.85'

        start_time = current_time - self.plot_half_width_s
        end_time = current_time + self.plot_half_width_s
        filtered_hilt = self.hilt.loc[start_time:end_time, :]
        self.ax.plot(filtered_hilt.index, filtered_hilt.counts, c='k')
        self.ax.axvline(current_time, ls=':', c='g')

        # Plot the peak width in red
        print(self.catalog.columns)
        if 'left_peak_base' in self.catalog.columns:
            print(current_row[[
                'width_height', 'left_peak_base', 'right_peak_base'
            ]])
            self.ax.hlines(current_row['width_height'],
                           current_row['left_peak_base'],
                           current_row['right_peak_base'],
                           colors='r')

        self.ax.set_title('SAMPEX Microburst Browser\n {} {}'.format(
            current_time.date(), current_time.time()))
        self.ax.set_ylabel('[counts/s]')
        self.ax.set_xlabel('UTC')

        self._print_aux_info(current_row)

        t = num2date(
            self.ax.get_xlim()[0]).replace(tzinfo=None).replace(microsecond=0)
        save_datetime = t.strftime('%Y%m%d_%H%M')
        self.fig.canvas.get_default_filename = lambda: (
            f'{save_datetime}_sampex_microburst.png')
        plt.draw()
        return
Exemple #3
0
"""
A command-line interface to plot the daily SAMPEX/HILT data 
"""
import time
from datetime import datetime
import argparse

import matplotlib.pyplot as plt

from sampex_microburst_widths.misc import load_hilt_data

parser = argparse.ArgumentParser(description=('This script plots the '
                                              'SAMPEX HILT data.'))
parser.add_argument('date',
                    nargs=3,
                    type=int,
                    help=('This is the date to plot formatted as YYYY MM DD'))
args = parser.parse_args()
date = datetime(*args.date)

start_time = time.time()
l = load_hilt_data.Load_SAMPEX_HILT(date)
l.resolve_counts_state4()
# a = load_hilt_data.Load_SAMPEX_Attitude(date)
print(f'Load time = {time.time()-start_time} s')

plt.plot(l.hilt_resolved.index[::10], l.hilt_resolved.counts[::10])
# plt.yscale('log')
plt.show()
Exemple #4
0
    n = 5
    plot_df = cat.sample(n=n, replace=False).sort_index()
else:
    n = len(times)
    plot_df = cat.loc[times, :]

fig, ax = plt.subplots(1, n, figsize=(12, 4))

for label_i, ax_i, (row_time, row) in zip(string.ascii_lowercase, ax,
                                          plot_df.iterrows()):
    print(label_i, row_time)
    time_range = [row_time - plot_half_width, row_time + plot_half_width]
    start_time_sec_floor = time_range[0].replace(second=0, microsecond=0)

    # Load and plot the HILT data
    hilt_data = load_hilt_data.Load_SAMPEX_HILT(row_time)
    hilt_data.resolve_counts_state4()
    hilt_filtered = hilt_data.hilt_resolved.loc[time_range[0]:time_range[1], :]
    ax_i.plot(hilt_filtered.index,
              (count_rate_conversion / yaxis_scale_factor) *
              hilt_filtered.counts,
              c='k')

    # Plot the fit
    current_date = hilt_filtered.index[0].floor('d')
    time_seconds = (hilt_filtered.index - current_date).total_seconds()
    popt = row.loc[['A', 't0', 'fwhm', 'y-int', 'slope']]
    popt[1] = (popt[1] - current_date).total_seconds()
    popt[2] = popt[2] / 2.355  # Convert the Gaussian FWHM to std
    y = SAMPEX_Microburst_Widths.gaus_lin_function(time_seconds, *popt)
    ax_i.plot(hilt_filtered.index,