#!/usr/bin/env python from scipy import io import numpy as np import csv import matplotlib as mp import matplotlib.pyplot as plt import os, glob from matplotlib.font_manager import FontProperties #path = 'C:\Users\c\Desktop\import' #for f in glob.glob( os.path.join(path, '*.mat')): # matfile = scipy.io.loadmat(f, struct_as_record=True) flight_number = '653201001031841' inMATFile = flight_number + '.mat' raw_data = io.loadmat(inMATFile, struct_as_record=True, squeeze_me=False) # dict test_matrix = np.array(raw_data) # ndarray file = open(flight_number+'-retinax-parameters.txt','w') mywriter = csv.writer(file) parameter_headings = "#, description, short name (aka alpha), size (X by 1), rate, dtype, units, example value" mywriter.writerow([parameter_headings]) #counter i = 1 #looping through the parameter matrices in 1 .mat file. There are a total of 189 parameters in a .mat file. for j in raw_data.keys(): #there are a few meta parameters that trip up to loop, so we blank them but still count them, e.g. #162 if j[0] == '_': #print i line = "%3s, %s" %(i,j) mywriter.writerow([line]) i += 1 continue #for each of the valid parameter matrices, we pull out the relevant meta data #rate: sampling frequency [Hz] rate = raw_data[j]['Rate'][0][0] #units: unit of the parameter try: units = raw_data[j]['Units'][0][0][0] except IndexError: units = " " #description: long form description of the parameter description = raw_data[j]['Description'][0][0][0] #alpha: short form description of the parameter alpha = raw_data[j]['Alpha'][0][0][0] #data: this is the matrix holding the values of the parameter. the length of this matrix correlates to the #frequency of the sampling rate. data = raw_data[j]['data'][0][0] shape = data.shape size = data.size dtype = data.dtype value_lookahead = data[size-1] #create a line per parameter and write to file line = "%3s, %35s, %-20s, %5i, %5i, %10s, %15s, %s" %(i, description, alpha, size, rate, dtype, units, value_lookahead) #print line mywriter.writerow([line]) #increment counter i += 1 #close file file.close() #some other test stuff to easily print to the stout. abrk_raw = raw_data['ABRK'] abrk = raw_data['ABRK']['data'][0][0] size = abrk.size if (len(raw_data) == 189): print 'SUCCESS' # playing around with printing the graphs to images font0 = FontProperties() font0.set_style('italic') font0.set_weight('bold') font0.set_size('x-small') time = np.linspace(0,1,size) b1 = raw_data['ALT']['data'][0][0] b1 = b1[0:b1.size:4] b2 = raw_data['AOAI']['data'][0][0] b2 = b2[0:b2.size:4] b3 = raw_data['TAS']['data'][0][0] b3 = b3[0:b3.size:4] b4 = raw_data['WOW']['data'][0][0] plt.title(flight_number) plt.subplot(4,1,1) plt.plot(time,b1,'r') plt.ylabel('Pressure Altitude (ALT)') plt.subplot(4,1,2) plt.plot(time,b2,'b') plt.ylabel('Angle of Attack (IAOA)') plt.subplot(4,1,3) plt.plot(time,b3,'g') plt.ylabel('True Air Speed (TAS)') plt.subplot(4,1,4) plt.plot(time,b4,'g') plt.ylabel('Weight On Wheels (WOW)') plt.xlabel('time (normalized)') plt.savefig('test.png') plt.show()