Skip to content

Commit

Permalink
fix and upgrade export button
Browse files Browse the repository at this point in the history
  • Loading branch information
greyltc committed May 9, 2019
1 parent ab8186f commit e9cfeba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
70 changes: 58 additions & 12 deletions batch_iv_analysis/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#TODO: make area editable

from collections import OrderedDict
from itertools import zip_longest

import os, sys, inspect, csv

from numpy import inf
import scipy.io as sio # for savemat
import numpy as np
import h5py

Expand Down Expand Up @@ -65,11 +66,11 @@ class MainWindow(QMainWindow):
fileNames = []
supportedExtensions = ['*.csv','*.tsv','*.txt','*.liv1','*.liv2','*.div1','*.div2', '*.h5']
bounds = {}
bounds['I0'] = [0, inf]
bounds['Iph'] = [0, inf]
bounds['Rs'] = [0, inf]
bounds['Rsh'] = [0, inf]
bounds['n'] = [0, inf]
bounds['I0'] = [0, np.inf]
bounds['Iph'] = [0, np.inf]
bounds['Rs'] = [0, np.inf]
bounds['Rsh'] = [0, np.inf]
bounds['n'] = [0, np.inf]
symbolCalcsNotDone = True
upperVLim = float('inf')
lowerVLim = float('-inf')
Expand Down Expand Up @@ -525,20 +526,65 @@ def myShowMessage(*args, **kwargs):
return args[0].oldShowMessage(*args[1:], **kwargs)

def exportInterp(self,row):
# these will be the col names for the output file
colnames = []
cols = () # data columns for output file

thisGraphData = self.ui.tableWidget.item(row,list(self.cols.keys()).index('plotBtn')).data(Qt.UserRole)

colname = 'Interpolated Voltage [V]'
fitX = thisGraphData["fitX"]
modelY = thisGraphData["modelY"]
cols = cols + ([(colname,x) for x in fitX], )
colnames.append(colname)

colname = 'Spline Fit Current Density [mA/cm^2]'
splineY = thisGraphData["splineY"]
a = np.asarray([fitX, modelY, splineY])
a = np.transpose(a).astype(float)
cols = cols + ([(colname,x) for x in splineY], )
colnames.append(colname)

colname = 'Char. Eqn. Fit Current Density [mA/cm^2]'
modelY = thisGraphData["modelY"]
if not np.isnan(modelY[0]): # only include this col if the fit has been done
cols = cols + ([(colname,x) for x in modelY], )
colnames.append(colname)

colname = 'Device Voltage[V]'
v = thisGraphData["v"]
cols = cols + ([(colname,x) for x in v], )
colnames.append(colname)

colname = 'Measured CurrentDensity[mA/cm^2]'
j = thisGraphData["j"]
cols = cols + ([(colname,x) for x in j], )
colnames.append(colname)

destinationFolder = os.path.join(self.workingDirectory,'exports')
QDestinationFolder = QDir(destinationFolder)

if not QDestinationFolder.exists():
QDir().mkdir(destinationFolder)
saveFile = os.path.join(destinationFolder,str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('file')).text())+'.csv')
header = 'Voltage [V],CharEqn Current [mA/cm^2],Spline Current [mA/cm^2]'
# data origin
file = str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('file')).text())
subs = str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('substrate')).text())
pix = str(self.ui.tableWidget.item(row,list(self.cols.keys()).index('pixel')).text())
if subs == '?':
subs = ''
else:
subs = '_' + subs
if pix == '?':
pix = ''
else:
pix = '_' + pix
saveFile = os.path.join(destinationFolder,file+subs+pix+'.csv')

# get the column data ready to be written
data = [dict(filter(None, a)) for a in zip_longest(*cols)]

try:
np.savetxt(saveFile, a, delimiter=",",header=header)
with open(saveFile, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=colnames)
writer.writeheader()
writer.writerows(data)
self.goodMessage()
self.ui.statusbar.showMessage("Exported " + saveFile,5000)
except:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="mutovis-analysis",
version="3.0.6",
version="3.0.7",
author="Grey Christoforo",
author_email="grey@mutovis.com",
description="Software for analyzing solar cell i-v curves",
Expand Down

0 comments on commit e9cfeba

Please sign in to comment.