def k_index_plot(mag_data, mag_qdc, filename, exif_tags): md_filt = mag_data if ap.has_site_info(mag_data.project, mag_data.site, 'k_index_filter'): kfilt = ap.get_site_info(mag_data.project, mag_data.site, 'k_index_filter') if kfilt is not None: md_filt = kfilt(mag_data) k_index = ap.auroralactivity.KIndex(magdata=md_filt, magqdc=mag_qdc) # Fix the start/end times to the data, not the 3h K index samples k_index.start_time = md_filt.start_time k_index.end_time = md_filt.end_time k_index.plot() fig = plt.gcf() fig.set_figwidth(6.4) fig.set_figheight(4.8) fig.subplots_adjust(bottom=0.1, top=0.85, left=0.15, right=0.925) mysavefig(fig, filename, exif_tags)
def activity_plot(mag_data, mag_qdc, filename, exif_tags, k_index_filename=None): global activity channel = mag_data.channels[0] pos = [0.15, 0.1, 0.775, 0.75] if mag_qdc is None: activity = None mag_data.plot(channels=channel, label=channel, color='black') fig = plt.gcf() ax2 = plt.gca() else: # assert np.all(mag_data.channels == mag_qdc.channels) \ # and len(mag_data.channels) == 1 \ # and len(mag_qdc.channels) == 1, \ # 'Bad value for channels' activity = ap.auroralactivity.AuroraWatchActivity(magdata=mag_data, magqdc=mag_qdc, channels=channel, fit=None) # To get another axes the position must be different. It is made # the same position later. pos2 = copy.copy(pos) pos2[0] += 0.1 fig = plt.figure(facecolor='w') ax = plt.axes(pos) activity.plot(axes=ax, units_prefix='n', label='Activity (' + channel + ')') ax2 = plt.axes(pos2) # Set Y limit to be 1.5 times highest threshold. Units are # nanotesla since that was set when plotting. ax.set_ylim(0, activity.thresholds[-1] * 1.5 * 1e9) mag_data.plot(channels=channel, label=channel, color='black', axes=ax2) # Align the QDC to regular intervals between start and end times qdc_cadence = np.timedelta64(1, 'm') # num = ((mag_data.end_time - mag_data.start_time)/ qdc_cadence) + 1 # qdc_sample_times = np.linspace(mag_data.start_time.astype('M8[m]'), # mag_data.end_time.astype('M8[m]'), # num) qdc_sample_times = list(dt64.dt64_range(mag_data.start_time, mag_data.end_time, qdc_cadence)) qdc_aligned = mag_qdc.align(qdc_sample_times) qdc_aligned.plot(channels=channel, label=channel + ' QDC', color='cyan', axes=ax2) ax.set_axis_bgcolor('w') ax.axison = False ax2.set_title(activity.make_title()) ax2.set_axis_bgcolor('none') ax2.set_position(pos) min_ylim_range = 400 ax2_ylim = ax2.get_ylim() if np.diff(ax2_ylim) < min_ylim_range: ax2.set_ylim(round_to(np.mean(ax2_ylim), 50) + min_ylim_range * np.array([-0.5, 0.5])) fig.set_figwidth(6.4) fig.set_figheight(4.8) mysavefig(fig, filename, exif_tags) r = [activity] if k_index_filename is not None: md_filt = mag_data if ap.has_site_info(mag_data.project, mag_data.site, 'k_index_filter'): kfilt = ap.get_site_info(mag_data.project, mag_data.site, 'k_index_filter') if kfilt is not None: md_filt = kfilt(mag_data) k_index = ap.auroralactivity.KIndex(magdata=md_filt, magqdc=mag_qdc) # Fix the start/end times to the data, not the 3h K index samples k_index.start_time = md_filt.start_time k_index.end_time = md_filt.end_time k_index.plot() fig = plt.gcf() fig.set_figwidth(6.4) fig.set_figheight(4.8) fig.subplots_adjust(bottom=0.1, top=0.85, left=0.15, right=0.925) mysavefig(fig, k_index_filename, exif_tags) r.append(k_index) return r