Skip to content
Snippets Groups Projects
Commit 1f655899 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

scripts: createdataset: create a tar file instead of a directory of files

parent d8460af6
No related branches found
No related tags found
No related merge requests found
import argparse import argparse
import os import os
from tqdm import tqdm from tqdm import tqdm
import tarfile
from chargefile import ChargeFile from chargefile import ChargeFile
from spectrafile import SpectraFile from spectrafile import SpectraFile
...@@ -39,9 +40,17 @@ if __name__ == "__main__": ...@@ -39,9 +40,17 @@ if __name__ == "__main__":
step = int(tokens[0]) step = int(tokens[0])
cellid = int(tokens[1]) cellid = int(tokens[1])
substep = int(tokens[2]) substep = int(tokens[2])
celldir = os.path.join(args.out, str(cellid))
if not os.path.exists(celldir):
os.makedirs(celldir)
sf = SpectraFile(os.path.join(args.data, filename), cellid, step, substep, charge_files, len(cells)) sf = SpectraFile(os.path.join(args.data, filename), cellid, step, substep, charge_files, len(cells))
sf.write(celldir) sf.write(args.out)
try:
os.remove(f"{args.out}.tar")
except FileNotFoundError:
pass
tar = tarfile.open(f"{args.out}.tar", mode="x")
for filename in tqdm(os.listdir(args.out)):
path = os.path.join(args.out, filename)
tar.add(path, arcname=os.path.split(path)[-1])
os.remove(path)
os.rmdir(args.out)
...@@ -26,11 +26,14 @@ class SpectraFile: ...@@ -26,11 +26,14 @@ class SpectraFile:
raise ParseError(f"file name and file content of SpectraFile {filename} do not match") raise ParseError(f"file name and file content of SpectraFile {filename} do not match")
def write(self, directory: str): def write(self, directory: str):
meta_dsc_string = "step, substep, cellid, temparature, ocv, charge_cycles, thermal_cycles, last_avg_cap, last_avg_step, last_cap, last_cap_step, soc" metaList = [float(self.step), float(self.substep), float(self.cellid), float(self.temperature), float(self.ocv),
metastring = f"{self.step}, {self.substep}, {self.cellid}, {self.temperature}, {self.ocv}, {self.meta.charge_cycles}, {self.meta.thermal_cycles}, " float(self.meta.charge_cycles), float(self.meta.thermal_cycles), float(self.meta.last_avg_cap), float(self.meta.last_avg_cap_step),
metastring += f"{self.meta.last_avg_cap}, {self.meta.last_avg_cap_step}, {self.meta.last_cap}, {self.meta.last_cap_step}, {self.meta.soc}" float(self.meta.last_cap), float(self.meta.last_cap_step), float(self.meta.soc)]
self.spectra.setLabels(metaList)
self.spectra.headerDescription = meta_dsc_string meta_dsc_strings = ["step", "substep", "cellid", "temparature", "ocv", "charge_cycles", "thermal_cycles",
self.spectra.header = metastring "last_avg_cap", "last_avg_step", "last_cap", "last_cap_step", "soc"]
self.spectra.headerDescription = "File origin"
self.spectra.header = "CoinCellHell mesurement file"
self.spectra.labelNames = meta_dsc_strings
self.spectra.saveToDisk(os.path.join(directory, self.filename)) self.spectra.saveToDisk(os.path.join(directory, self.filename))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment