From d248744ce7f5f79938712c89f559dd4af0e4efbb Mon Sep 17 00:00:00 2001 From: Johannes Hjorth Date: Mon, 23 Sep 2024 15:34:59 +0200 Subject: [PATCH] Added fallback filename if unable to write simulation --- .../data/da_experiment_cur_inj_on_bath.json | 6 +++--- snudda/simulate/save_network_recording.py | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/notebooks/neuromodulation/data/da_experiment_cur_inj_on_bath.json b/examples/notebooks/neuromodulation/data/da_experiment_cur_inj_on_bath.json index 95bc80c3d..61c4294aa 100644 --- a/examples/notebooks/neuromodulation/data/da_experiment_cur_inj_on_bath.json +++ b/examples/notebooks/neuromodulation/data/da_experiment_cur_inj_on_bath.json @@ -2,7 +2,7 @@ "network_file": "networks/neuromodulation_bath_current/network-synapses.hdf5", "output_file": "networks/neuromodulation_bath_current/simulation/output_neuromodulation_ON.hdf5", "log_file": "networks/neuromodulation_bath_current/log/network-simulation-ON.txt", - "time": 1.5, + "time": 2.5, "record_all_soma": true, "record_rxd_species_all": [0, 1], "record_density_mechanism": { @@ -30,8 +30,8 @@ "rxd_enable_extracellular": false, "bath_application": { "DA": { - "time": [0, 0.499, 0.5, 0.99, 1.0, 10], - "concentration": [20e-6, 20e-6, 60e-6, 60e-6, 100e-6, 100e-6], + "time": [0, 0.499, 0.5, 0.99, 1.0, 1.5, 1.51, 10], + "concentration": [20e-9, 20e-9, 60e-6, 60e-6, 100e-6, 100e-6, 0, 0], "interpolate": true } }, diff --git a/snudda/simulate/save_network_recording.py b/snudda/simulate/save_network_recording.py index 062fa04cd..1def5d773 100644 --- a/snudda/simulate/save_network_recording.py +++ b/snudda/simulate/save_network_recording.py @@ -280,7 +280,24 @@ def write_header(self): os.mkdir(os.path.dirname(self.output_file)) print(f"Writing network output to {self.output_file}") - out_file = h5py.File(self.output_file, "w") + + try: + out_file = h5py.File(self.output_file, "w") + except Exception as e: + + print(e) + print(f"Trying to recover, and save to different file name.") + + ctr = 1 + temp_name = f"{self.output_file}-{ctr}" + + while os.path.isfile(temp_name): + print(f"File exists: {temp_name}") + ctr += 1 + temp_name = f"{self.output_file}-{ctr}" + + print(f"\n!!! Unable to create {self.output_file} (file locked?), using {temp_name} instead\n\n") + out_file = h5py.File(temp_name, "w") meta_data = out_file.create_group("meta_data")