#!/usr/bin/env python from scipy import io import numpy as np import matplotlib as mp import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import os, glob from matplotlib.font_manager import FontProperties from matplotlib.backends.backend_pdf import PdfPages flight_number = '670200106231735' inMATFile = flight_number + '.mat' raw_data = io.loadmat(inMATFile, struct_as_record=True, squeeze_me=False) # dict test_matrix = np.array(raw_data) # ndarray # Generate the time vector using a known 1Hz feature abrk = raw_data['ABRK']['data'][0][0] size = abrk.size time = np.linspace(0,1,size) # Generate Pressure Altitude data vector for reference alt = raw_data['ALT']['data'][0][0] alt = alt[0:alt.size:4] # Generate the pages, one for each individual feature (total of 186 features/pages) features = raw_data.keys() with PdfPages(flight_number+'_plots.pdf') as pdf: for key in features: page = pdf.get_pagecount() page += 1 # Filter out the 3 non-feature columns if key[0] == '_': continue # Assign the data vector and the sampling rate for the feature b1 = raw_data[key]['data'][0][0] rate = raw_data[key]['Rate'][0][0][0][0] long_description = raw_data[key]['Description'][0][0][0] # Create a figure instance (ie. a new page) fig = plt.figure(figsize=(11, 8.5), dpi=100) title = 'Feature ' + str(page) + ': ' + long_description fig.suptitle(title, fontsize=12, fontweight= 'bold') gs = gridspec.GridSpec(2,1, height_ratios=[5,1]) # For those features with a sampling rate < 0, upsample if rate == 0.25: b1 = np.resize(b1,(size,1)) ax1 = plt.subplot(gs[0]) #plt.subplots_adjust(top=0.9) plt.plot(time,b1,'b') ax1.set_ylabel(key) ax2 = plt.subplot(gs[1]) plt.plot(time,alt,'r') ax2.set_ylabel('altitude') #ax2.axis('off') ax2.set_yticklabels([]) ax2.set_yticks([]) ax2.set_xlabel('time (normalized)') ax2.text(0.5,0.01, flight_number, verticalalignment='bottom', horizontalalignment='right', transform = ax2.transAxes, color='green', fontsize=10) pdf.savefig() plt.close() # For those features with a sampling rate > 0, subsample else: b1 = b1[0:b1.size:rate] ax1 = plt.subplot(gs[0]) plt.plot(time,b1,'r') ax1.set_ylabel(key) ax2 = plt.subplot(gs[1]) plt.plot(time,alt,'r') ax2.set_ylabel('altitude') #ax2.axis('off') ax2.set_yticklabels([]) ax2.set_yticks([]) ax2.set_xlabel('time (normalized)') ax2.text(0.5,0.01, flight_number, verticalalignment='bottom', horizontalalignment='right', transform = ax2.transAxes, color='green', fontsize=10) pdf.savefig() plt.close()