From 7ef020b13bb82242f8cb43bb03e491e79803f0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Le=20Guyader?= <loic.le.guyader@xfel.eu> Date: Mon, 6 Apr 2020 16:54:04 +0200 Subject: [PATCH] Load and close netcdf file to avoid unwanted caching behavior --- DSSC1module.py | 5 +++-- FastCCD.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DSSC1module.py b/DSSC1module.py index 6762de8..eea4232 100644 --- a/DSSC1module.py +++ b/DSSC1module.py @@ -290,6 +290,7 @@ class DSSC1module: warnings.warn(f'Overwriting file: {save_path}') os.remove(save_path) data.to_netcdf(save_path, group='data') + data.close() os.chmod(save_path, 0o664) print('saving: ', save_path) else: @@ -306,7 +307,7 @@ class DSSC1module: save_folder = self.save_folder self.run_nr = dark_runNB - self.dark_data = xr.open_dataset(os.path.join(save_folder, f'run{dark_runNB}_dark.h5'), group='data') + self.dark_data = xr.load_dataset(os.path.join(save_folder, f'run{dark_runNB}_dark.h5'), group='data') self.plot_title = f"{self.proposal} dark: {self.dark_data['run'].values}" def show_rois(self): @@ -422,4 +423,4 @@ def process_one_module(job): module_data['std_data'] += (temp**2).sum(dim='trainId') module_data['counts'] += n_trains - return module_data \ No newline at end of file + return module_data diff --git a/FastCCD.py b/FastCCD.py index 32e21ab..e919dc1 100644 --- a/FastCCD.py +++ b/FastCCD.py @@ -369,6 +369,7 @@ class FastCCD: warnings.warn(f'Overwriting file: {save_path}') os.remove(save_path) self.module_data.to_netcdf(save_path, group='data') + self.module_data.close() os.chmod(save_path, 0o664) print('saving: ', save_path) else: @@ -389,10 +390,10 @@ class FastCCD: self.plot_title = f'{self.proposal} run: {runNB} dark: {dark_runNB}' - binned = xr.open_dataset(os.path.join(save_folder, f'run{runNB}.h5'), group='data', cache=False) + binned = xr.load_dataset(os.path.join(save_folder, f'run{runNB}.h5'), group='data') if dark_runNB is not None: - dark = xr.open_dataset(os.path.join(save_folder, f'run{dark_runNB}_dark.h5'), group='data', cache=False) + dark = xr.load_dataset(os.path.join(save_folder, f'run{dark_runNB}_dark.h5'), group='data') binned['pumped'] = self.gain*(binned['pumped'] - dark['pumped'].squeeze(drop=True)) binned['unpumped'] = self.gain*(binned['unpumped'] - dark['unpumped'].squeeze(drop=True)) @@ -638,4 +639,4 @@ def process_one_module(job): module_data['xgm_unpumped'] = data_unpumped['xgm'] module_data['workerId'] = workerId - return module_data \ No newline at end of file + return module_data -- GitLab