def read(filepath): """ Takes a filepath, finds out what file type it is, and reads it into two list of lists, fix this! maybe Cell object? or pd array?""" # Check input file and create proper data thereafter fn, ext = os.path.splitext(filepath) LOG.debug(f"Reading file: '{filepath}'") if ext == ".xlsx": from ecdh.readers import Neware as NA df = NA.read_xlsx(filepath) elif ext == ".csv": from ecdh.readers import Neware as NA df = NA.read_csv( filepath ) #but this gives nested list with V/q data for each cycle. elif ext == ".mpt": from ecdh.readers import BioLogic as BL df = BL.read_mpt(filepath) elif ext == ".txt": from ecdh.readers import BatSmall as BS df = BS.read_txt(filepath) elif ext == ".ecdh": from ecdh.readers import Processed as PC df = PC.read_ecdh(filepath) else: LOG.error(f"File format not supported: {ext}") LOG.error("Exiting..") exit() return df
def plot(self): if not self.plotobj: LOG.error( "No plot object supplied to the cell, but cell.plot was still called! Exiting.." ) import sys sys.exit() if self.plotobj.vcplot: if self.df.experiment_mode == 2: self.edit_CV() self.plotobj.plot_CV(self) elif self.df.experiment_mode == 1: self.edit_GC() self.plotobj.plot_GC(self) if self.plotobj.qcplot: self.edit_cyclelife() self.plotobj.plot_cyclelife(self) if self.plotobj.rawplot: if self.plotobj.rawplot_capacity: self.edit_cumulative_capacity() self.plotobj.plot_raw(self) if self.plotobj.dqdvplot: self.edic_dQdV() self.plotobj.plot_dQdV(self)
def check_files(list): # Checks that files exist and then returns the ones that does. return_list = [] for file in list: filename = file[0] if os.path.isfile(filename): return_list.append(file) else: LOG.error( "File not found: '" + str(filename) + "' Please check that the correct path is typed in your input toml file. Skipping this file." ) return return_list
def read_config(path): try: toml_str = open(path, "r").read() except Exception as e: LOG.error(f"Couldn't read config file: {e}") import sys sys.exit() # Check toml string check_config(toml_str) # Fill toml config config = toml.loads(toml_str) config = fill_config(config) return config
def edit_cyclelife(self): import numpy as np import pandas as pd #First make sure that we have either CV capacity data or galvanostatic if self.df.experiment_mode == 2: if not self.CVdata_capacity: LOG.error( "in cell/edit_cyclelife, CVdata_capacity has not been made." ) self.edit_CV_capacity() elif self.df.experiment_mode == 1: #If the GC data doesn't exist, make it. if not self.GCdata: self.edit_GC() #Make temporary dataholders tmpdat = [] #loop through data and gather capacities for i, cycle in enumerate(self.GCdata): chg, dchg = cycle try: tmpdat.append([i, chg[0][-1], dchg[0][-1]]) except: try: tmpdat.append([i, chg[0][-1], 0]) except: try: tmpdat.append([i, 0, dchg[0][-1]]) except: tmpdat.append([i, 0, 0]) self.cyclelifedata = pd.DataFrame(tmpdat, columns=[ "cycle", "charge capacity/mAh", "discharge capacity/mAh" ]) self.cyclelifedata["coulombic efficiency"] = self.cyclelifedata[ "discharge capacity/mAh"] / self.cyclelifedata[ "charge capacity/mAh"] * 100
def run(): import sys if len(sys.argv) < 3: #Then no folder is specified, look for toml in local folder. if os.path.isfile("./ecdh.toml"): path = "./ecdh.toml" else: LOG.error("Could not find an ecdh.toml file in the current directory! \nOptions: \n1. Run ecdh with the argument 'run' followed by the path of your .toml file. \n2. Initiate toml file in this directory with the init argument.") sys.exit() elif os.path.isfile(sys.argv[2]):# File was inserted Read toml config path = sys.argv[2] else: LOG.error("Cannot find the .toml configuration file!") sys.exit() LOG.debug("Reading config file: '{}'".format(path)) # Read in configuration file config = read_config(path) settings = config["settings"] # Merge cycle range into specific cycles if settings['cycle_range']: try: cyclerange = np.linspace(settings['cycle_range'][0], settings['cycle_range'][1], settings['cycle_range'][1]-settings['cycle_range'][0] + 1).astype(int) if type(settings['specific_cycles']) is bool: settings['specific_cycles'] = cyclerange.tolist() else: settings['specific_cycles'] += cyclerange.tolist() LOG.info(f"Specific cycles: {settings['specific_cycles']}") except Exception as e: LOG.warning(f"Could not use the cycle range, Error: {e}") datatreatment = config["datatreatment"] # Check that files are found files = check_files(config["files"]) if len(files) == 0: import sys LOG.error("Could not load any datafiles. Exiting. Check that the filepaths are typed correctly in the configuration file.") sys.exit() LOG.success("Running ECDH: Found {} datafiles!".format(len(files))) # Define plot specifications plot = Plot(numfiles=len(files), **settings) # Run the data reading + plot generation cells = [] for f in files: try: am_mass = f[1] except: am_mass = None try: nickname = f[2] except: nickname = None cell = Cell(f[0], am_mass, nickname, plot=plot, specific_cycles = settings['specific_cycles']) cell.get_data() #cell.edit_GC() #cell.treat_data(settings) cell.plot() #cells.append(cell) if datatreatment['reduce_data']: cell.reduce_data(datatreatment) if datatreatment['smooth_data']: cell.smooth_data(datatreatment) if datatreatment['print_capacities']: if not os.path.isfile("capacity_intervals.json"): with open("capacity_intervals.json", "w") as f: f.close() import json new_json = cell.get_capacities(datatreatment) with open("capacity_intervals.json",'r+') as file: # First we load existing data into a dict. try: file_data = json.load(file) except: file_data = [] # Join new_data with file_data inside emp_details file_data.append(new_json) # Sets file's current position at offset. file.seek(0) # convert back to json. json.dump(file_data, file, indent = 4) if 'savefig' in settings: plot.draw(save = settings['savefig']) else: plot.draw()
def edit_CV_capacity(self): import numpy as np LOG.error( "Cell.py/edit_CV_capacity has not been made! Creating data with only zeros." ) self.CVdata_capacity = [(np.array([[0], [0]]), np.array([[0], [0]]))]