From 8aec5532e8ae6e1ca9c3fd043d29bb81d4b8cc32 Mon Sep 17 00:00:00 2001 From: Noe Brucy Date: Tue, 5 Jan 2021 16:09:00 +0100 Subject: [PATCH] [comparator] [log extractor] extract cons even without emag output --- .flake8 | 2 ++ comparator.py | 16 ++++++++++------ pp_params.yml | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.flake8 b/.flake8 index f5fac5c..3551fe6 100644 --- a/.flake8 +++ b/.flake8 @@ -5,3 +5,5 @@ ignore = E203 # Line break before binary operator W503 + # Invalid escape sequence '\[' + W605 diff --git a/comparator.py b/comparator.py index e8d5bb9..405a61f 100644 --- a/comparator.py +++ b/comparator.py @@ -253,11 +253,13 @@ class Comparator(Aggregator, HDF5Container): return series def _extract_cons_from_log(self, series, log_filename, run): - cmd_grep = "grep 'Main step' {} -A 2".format(log_filename) + mhd = self.pp_params.input.mhd + nlines = 2 + int(mhd) # Number of useful lines + cmd_grep = "grep 'Main step' {} -A {}".format(log_filename, nlines - 1) content = os.popen(cmd_grep).readlines() - for i in range(0, len(content), 4): + for i in range(0, len(content), nlines + 1): series["time"][run].append( - np.float(content[i + 2].split("=")[2].split()[0]) + np.float(content[i + nlines - 1].split("=")[2].split()[0]) ) series["step"][run].append(np.int(content[i].split("=")[1].split()[0])) series["mcons"][run].append(np.float(content[i].split("=")[2].split()[0])) @@ -265,9 +267,11 @@ class Comparator(Aggregator, HDF5Container): series["epot"][run].append(np.float(content[i].split("=")[4].split()[0])) series["ekin"][run].append(np.float(content[i].split("=")[5].split()[0])) series["eint"][run].append(np.float(content[i].split("=")[6].split()[0])) - series["emag"][run].append( - np.float(content[i + 1].split("=")[1].split()[0]) - ) + if mhd: + emag = np.float(content[i + 1].split("=")[1].split()[0]) + series["emag"][run].append(emag) + else: + series["emag"][run].append(0.0) return series def _extract_rms_from_log(self, series, log_filename, run): diff --git a/pp_params.yml b/pp_params.yml index 55876e3..3e6c2fb 100644 --- a/pp_params.yml +++ b/pp_params.yml @@ -45,6 +45,7 @@ pymses: # Parameters for Pymses reader variables : ["rho","vel","Br","Bl","P", "g", "phi"] # Read these variables order : '<' # Bit order + # Processing options levelmax : 20 # Maximal AMR level visited when looking levels fft : False # Quick and dirty rendering using FFT @@ -66,6 +67,7 @@ input: # Parameters on how to look for input files (= output from Ramses) log_prefix : "run.log" # Prefix of the log file label_filename : "label.txt" # Name of the label file nml_filename : "run.nml" # name of the namelist file + mhd : True # Is MHD activated out: # Parameters for post processing tag : "" # Tag for the image