add an option to save all important files to path_out
This commit is contained in:
+28
-6
@@ -1,6 +1,9 @@
|
||||
# coding: utf-8
|
||||
|
||||
|
||||
import os
|
||||
from distutils.file_util import copy_file
|
||||
|
||||
import glob
|
||||
import numpy as np
|
||||
from functools import partial
|
||||
@@ -82,6 +85,20 @@ class StudyProcessor(Aggregator, HDF5Container):
|
||||
run0 = self.runs[0]
|
||||
self.info = selector.info[run0][self.nums[run0][0]]
|
||||
self.namelist = selector.namelist
|
||||
|
||||
# Save namelist and logs
|
||||
if self.params.out.copy_info:
|
||||
for run in self.runs:
|
||||
nml_src = f"{self.path}/{run}/{self.params.input.nml_filename}"
|
||||
nml_dest = f"{self.path_out}/{run}/{self.params.input.nml_filename}"
|
||||
copy_file(nml_src, nml_dest, update=1)
|
||||
|
||||
logs = self.get_logs(run)
|
||||
os.makedirs(f"{self.path_out}/{run}/logs", exist_ok=True)
|
||||
for log in logs:
|
||||
dest = f"{self.path_out}/{run}/logs/{os.path.basename(log)}"
|
||||
copy_file(log, dest, update=1)
|
||||
|
||||
# log info
|
||||
self.log_id = "[study {}] ".format(self.params.out.tag)
|
||||
|
||||
@@ -334,6 +351,14 @@ class StudyProcessor(Aggregator, HDF5Container):
|
||||
series["turb_energy"][run].append(np.nan)
|
||||
return series
|
||||
|
||||
def get_logs(self, run):
|
||||
glob_str = f"{self.path}/{run}/{self.params.input.log_prefix}*"
|
||||
logs = glob.glob(glob_str)
|
||||
if len(logs) == 0:
|
||||
glob_str = f"{self.path}/{run}/logs/{self.params.input.log_prefix}*"
|
||||
logs = glob.glob(glob_str)
|
||||
return logs
|
||||
|
||||
def _from_log(self, keys, extractor):
|
||||
|
||||
# Initialize series
|
||||
@@ -346,14 +371,11 @@ class StudyProcessor(Aggregator, HDF5Container):
|
||||
for key in keys:
|
||||
series[key][run] = []
|
||||
|
||||
# get one preprocessor
|
||||
path_run = self.path + "/" + run
|
||||
|
||||
# Get list of run files
|
||||
log_files = path_run + "/" + self.params.input.log_prefix + "*"
|
||||
# Get list of log files
|
||||
log_files = self.get_logs(run)
|
||||
|
||||
# Parse files
|
||||
for log_filename in glob.glob(log_files):
|
||||
for log_filename in log_files:
|
||||
series = extractor(series, log_filename, run)
|
||||
|
||||
# Numpify the lists
|
||||
|
||||
Reference in New Issue
Block a user