Skip to content

Commit e9cfeba

Browse files
committed
fix and upgrade export button
1 parent ab8186f commit e9cfeba

File tree

2 files changed

+59
-13
lines changed

2 files changed

+59
-13
lines changed

batch_iv_analysis/gui.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
#TODO: make area editable
1313

1414
from collections import OrderedDict
15+
from itertools import zip_longest
1516

1617
import os, sys, inspect, csv
1718

18-
from numpy import inf
19+
import scipy.io as sio # for savemat
1920
import numpy as np
2021
import h5py
2122

@@ -65,11 +66,11 @@ class MainWindow(QMainWindow):
6566
fileNames = []
6667
supportedExtensions = ['*.csv','*.tsv','*.txt','*.liv1','*.liv2','*.div1','*.div2', '*.h5']
6768
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]
7374
symbolCalcsNotDone = True
7475
upperVLim = float('inf')
7576
lowerVLim = float('-inf')
@@ -525,20 +526,65 @@ def myShowMessage(*args, **kwargs):
525526
return args[0].oldShowMessage(*args[1:], **kwargs)
526527

527528
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+
528533
thisGraphData = self.ui.tableWidget.item(row,list(self.cols.keys()).index('plotBtn')).data(Qt.UserRole)
534+
535+
colname = 'Interpolated Voltage [V]'
529536
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]'
531541
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+
534561
destinationFolder = os.path.join(self.workingDirectory,'exports')
535562
QDestinationFolder = QDir(destinationFolder)
563+
536564
if not QDestinationFolder.exists():
537565
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+
540583
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)
542588
self.goodMessage()
543589
self.ui.statusbar.showMessage("Exported " + saveFile,5000)
544590
except:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="mutovis-analysis",
8-
version="3.0.6",
8+
version="3.0.7",
99
author="Grey Christoforo",
1010
author_email="[email protected]",
1111
description="Software for analyzing solar cell i-v curves",

0 commit comments

Comments
 (0)