Commit a77daf97 authored by Wouter Kessels's avatar Wouter Kessels

Save temp data to temp folder

parent faf09a8a
......@@ -7,6 +7,7 @@ Takes input parameters from execute.ipynb.
import os
import pickle
import shutil
from datetime import datetime
from glob import glob
from objects import *
......@@ -15,7 +16,7 @@ from movements import *
from observables import *
import matplotlib.pyplot as plt
def pipeline(bodies, settings):
"""Defines the pipeline for the calculations and saving the data.
......@@ -116,8 +117,11 @@ def save_data(bodies, info, settings, overwrite, name=None, temp_name=None, desc
if not overwrite:
now ="%y_%m_%d_%H_%M_%S")
name = "temp_" + now + "_data" + ".pkl"
name_folder = "/home/student/project3/temp_" + now + "_data"
name_file = name_folder + "/temporary.pkl"
description = 'temporary'
elif overwrite:
# Check whether new file path is unique and temp_file path is specified
if not os.path.isfile(name):
......@@ -135,14 +139,14 @@ def save_data(bodies, info, settings, overwrite, name=None, temp_name=None, desc
'settings': settings
out_file = open(name, "wb")
out_file = open(name_file, "wb")
pickle.dump(data, out_file)
return name
return name_file
def del_temp(name):
def del_temp(folder):
"""Delete specified temporary file.
......@@ -150,15 +154,15 @@ def del_temp(name):
name: str
File path and name of temporary file to delete
def del_temps():
"""Delete all temporary files in directory, characterized by '/temp_' in the path."""
dir_path = os.path.dirname(os.path.realpath(__file__))
condition = dir_path + "/temp_*.pkl"
temp_files = glob(condition)
for file in temp_files:
condition = dir_path + "/temp_*"
temp_folders = glob(condition)
for folder in temp_folders:
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment