|
12 | 12 | #TODO: make area editable |
13 | 13 |
|
14 | 14 | from collections import OrderedDict |
| 15 | +from itertools import zip_longest |
15 | 16 |
|
16 | 17 | import os, sys, inspect, csv |
17 | 18 |
|
18 | | -from numpy import inf |
| 19 | +import scipy.io as sio # for savemat |
19 | 20 | import numpy as np |
20 | 21 | import h5py |
21 | 22 |
|
@@ -65,11 +66,11 @@ class MainWindow(QMainWindow): |
65 | 66 | fileNames = [] |
66 | 67 | supportedExtensions = ['*.csv','*.tsv','*.txt','*.liv1','*.liv2','*.div1','*.div2', '*.h5'] |
67 | 68 | bounds = {} |
68 | | - bounds['I0'] = [0, inf] |
69 | | - bounds['Iph'] = [0, inf] |
70 | | - bounds['Rs'] = [0, inf] |
71 | | - bounds['Rsh'] = [0, inf] |
72 | | - bounds['n'] = [0, inf] |
| 69 | + bounds['I0'] = [0, np.inf] |
| 70 | + bounds['Iph'] = [0, np.inf] |
| 71 | + bounds['Rs'] = [0, np.inf] |
| 72 | + bounds['Rsh'] = [0, np.inf] |
| 73 | + bounds['n'] = [0, np.inf] |
73 | 74 | symbolCalcsNotDone = True |
74 | 75 | upperVLim = float('inf') |
75 | 76 | lowerVLim = float('-inf') |
@@ -525,20 +526,65 @@ def myShowMessage(*args, **kwargs): |
525 | 526 | return args[0].oldShowMessage(*args[1:], **kwargs) |
526 | 527 |
|
527 | 528 | def exportInterp(self,row): |
| 529 | + # these will be the col names for the output file |
| 530 | + colnames = [] |
| 531 | + cols = () # data columns for output file |
| 532 | + |
528 | 533 | thisGraphData = self.ui.tableWidget.item(row,list(self.cols.keys()).index('plotBtn')).data(Qt.UserRole) |
| 534 | + |
| 535 | + colname = 'Interpolated Voltage [V]' |
529 | 536 | fitX = thisGraphData["fitX"] |
530 | | - modelY = thisGraphData["modelY"] |
| 537 | + cols = cols + ([(colname,x) for x in fitX], ) |
| 538 | + colnames.append(colname) |
| 539 | + |
| 540 | + colname = 'Spline Fit Current Density [mA/cm^2]' |
531 | 541 | splineY = thisGraphData["splineY"] |
532 | | - a = np.asarray([fitX, modelY, splineY]) |
533 | | - a = np.transpose(a).astype(float) |
| 542 | + cols = cols + ([(colname,x) for x in splineY], ) |
| 543 | + colnames.append(colname) |
| 544 | + |
| 545 | + colname = 'Char. Eqn. Fit Current Density [mA/cm^2]' |
| 546 | + modelY = thisGraphData["modelY"] |
| 547 | + if not np.isnan(modelY[0]): # only include this col if the fit has been done |
| 548 | + cols = cols + ([(colname,x) for x in modelY], ) |
| 549 | + colnames.append(colname) |
| 550 | + |
| 551 | + colname = 'Device Voltage[V]' |
| 552 | + v = thisGraphData["v"] |
| 553 | + cols = cols + ([(colname,x) for x in v], ) |
| 554 | + colnames.append(colname) |
| 555 | + |
| 556 | + colname = 'Measured CurrentDensity[mA/cm^2]' |
| 557 | + j = thisGraphData["j"] |
| 558 | + cols = cols + ([(colname,x) for x in j], ) |
| 559 | + colnames.append(colname) |
| 560 | + |
534 | 561 | destinationFolder = os.path.join(self.workingDirectory,'exports') |
535 | 562 | QDestinationFolder = QDir(destinationFolder) |
| 563 | + |
536 | 564 | if not QDestinationFolder.exists(): |
537 | 565 | QDir().mkdir(destinationFolder) |
538 | | - saveFile = os.path.join(destinationFolder,str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('file')).text())+'.csv') |
539 | | - header = 'Voltage [V],CharEqn Current [mA/cm^2],Spline Current [mA/cm^2]' |
| 566 | + # data origin |
| 567 | + file = str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('file')).text()) |
| 568 | + subs = str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('substrate')).text()) |
| 569 | + pix = str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('pixel')).text()) |
| 570 | + if subs == '?': |
| 571 | + subs = '' |
| 572 | + else: |
| 573 | + subs = '_' + subs |
| 574 | + if pix == '?': |
| 575 | + pix = '' |
| 576 | + else: |
| 577 | + pix = '_' + pix |
| 578 | + saveFile = os.path.join(destinationFolder,file+subs+pix+'.csv') |
| 579 | + |
| 580 | + # get the column data ready to be written |
| 581 | + data = [dict(filter(None, a)) for a in zip_longest(*cols)] |
| 582 | + |
540 | 583 | try: |
541 | | - np.savetxt(saveFile, a, delimiter=",",header=header) |
| 584 | + with open(saveFile, 'w') as csvfile: |
| 585 | + writer = csv.DictWriter(csvfile, fieldnames=colnames) |
| 586 | + writer.writeheader() |
| 587 | + writer.writerows(data) |
542 | 588 | self.goodMessage() |
543 | 589 | self.ui.statusbar.showMessage("Exported " + saveFile,5000) |
544 | 590 | except: |
|
0 commit comments