add support for python 3
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ import subprocess
|
|||||||
from mypool import MyPool as Pool
|
from mypool import MyPool as Pool
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
import bunch
|
|
||||||
|
|
||||||
from run_selector import *
|
from run_selector import *
|
||||||
from units import *
|
from units import *
|
||||||
|
|||||||
+19
-4
@@ -89,22 +89,37 @@ class Comparator(Aggregator, HDF5Container):
|
|||||||
return missing_nums
|
return missing_nums
|
||||||
|
|
||||||
def _get_units(self, unit, data=None):
|
def _get_units(self, unit, data=None):
|
||||||
"Get real units from info files"
|
"""
|
||||||
|
Get real units from info files
|
||||||
|
unit is either:
|
||||||
|
1. An instance of cst.Unit (pymses unit class)
|
||||||
|
2. A string beginning by "unit_", referring to a code unit,
|
||||||
|
available in self.info
|
||||||
|
3. A dict {unit1 : exp1, unit2: exp2, ...} with unitX as 2.
|
||||||
|
and expX a float, referring to the compound unit
|
||||||
|
unit1**exp1 * unit2**exp2
|
||||||
|
4. A dict {key: unit, ...} where key is a field name (eg. 'time', or 'mass')
|
||||||
|
and unit the corresponding unit (on one on the above format)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
1-3. : a cst.Unit instance
|
||||||
|
4. : a dict {key: unit, ...} with same key as input and unit being cst.Unit instances
|
||||||
|
"""
|
||||||
if isinstance(unit, cst.Unit):
|
if isinstance(unit, cst.Unit):
|
||||||
return unit
|
return unit
|
||||||
if isinstance(unit, str):
|
if isinstance(unit, str) and unit[:5] == "unit_":
|
||||||
res = self.info[unit]
|
res = self.info[unit]
|
||||||
if unit == "unit_length":
|
if unit == "unit_length":
|
||||||
res = res / self.info["boxlen"]
|
res = res / self.info["boxlen"]
|
||||||
return res
|
return res
|
||||||
if unit.keys()[0] in self.info:
|
if list(unit)[0][:5] == "unit_":
|
||||||
new_unit = cst.none
|
new_unit = cst.none
|
||||||
for base_unit_str in unit:
|
for base_unit_str in unit:
|
||||||
expo = unit[base_unit_str]
|
expo = unit[base_unit_str]
|
||||||
base_unit = self._get_units(base_unit_str)
|
base_unit = self._get_units(base_unit_str)
|
||||||
new_unit = new_unit * base_unit ** expo
|
new_unit = new_unit * base_unit ** expo
|
||||||
return new_unit
|
return new_unit
|
||||||
if (not data is None) and isinstance(data, dict) and unit.keys()[0] in data:
|
if (not data is None) and isinstance(data, dict) and list(unit)[0] in data:
|
||||||
for key in unit:
|
for key in unit:
|
||||||
unit[key] = self._get_units(unit[key])
|
unit[key] = self._get_units(unit[key])
|
||||||
return unit
|
return unit
|
||||||
|
|||||||
+3
-1
@@ -222,6 +222,8 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
if str(e) in [
|
if str(e) in [
|
||||||
"'LocatableAxes' object does not support indexing",
|
"'LocatableAxes' object does not support indexing",
|
||||||
"'AxesSubplot' object does not support indexing",
|
"'AxesSubplot' object does not support indexing",
|
||||||
|
"'AxesSubplot' object is not subscriptable",
|
||||||
|
"'LocatableAxes' object is not subscriptable",
|
||||||
]:
|
]:
|
||||||
self._plot_rule(
|
self._plot_rule(
|
||||||
rule,
|
rule,
|
||||||
@@ -786,7 +788,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
time_str = self.pp_params.plot.time_fmt.format(
|
time_str = self.pp_params.plot.time_fmt.format(
|
||||||
time.express(time_unit), time_unit.latex
|
time.express(time_unit), time_unit.latex
|
||||||
)
|
)
|
||||||
if len(label) > 0:
|
if label is not None and len(label) > 0:
|
||||||
label = label + " | " + time_str
|
label = label + " | " + time_str
|
||||||
else:
|
else:
|
||||||
label = time_str
|
label = time_str
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import re
|
import re
|
||||||
import bunch
|
import munch
|
||||||
import yaml
|
import yaml
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ _loader.add_implicit_resolver(
|
|||||||
def load_params(filename):
|
def load_params(filename):
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
para_disk = yaml.load(f, Loader=_loader)
|
para_disk = yaml.load(f, Loader=_loader)
|
||||||
return bunch.bunchify(para_disk)
|
return munch.munchify(para_disk)
|
||||||
|
|
||||||
|
|
||||||
def default_params():
|
def default_params():
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
"""Compute power spectra"""
|
"""Compute power spectra"""
|
||||||
|
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from builtins import range
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
@@ -840,7 +842,7 @@ def main(arg):
|
|||||||
"cos_vB",
|
"cos_vB",
|
||||||
"vz",
|
"vz",
|
||||||
]:
|
]:
|
||||||
for i in xrange(ns):
|
for i in range(ns):
|
||||||
pspec, kbins, pspec2, fbins = pspectrum(
|
pspec, kbins, pspec2, fbins = pspectrum(
|
||||||
pcubes2[v][:, :, i], cubes_k["k"][:, :, i], kbins, knorm, arg.fbins
|
pcubes2[v][:, :, i], cubes_k["k"][:, :, i], kbins, knorm, arg.fbins
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from builtins import str
|
||||||
import tables as T
|
import tables as T
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as P
|
import matplotlib.pyplot as P
|
||||||
|
|||||||
+16
-14
@@ -86,15 +86,15 @@ class RunSelector:
|
|||||||
for run in runs:
|
for run in runs:
|
||||||
value[run] = self.get_nml_value(nml_key, run)
|
value[run] = self.get_nml_value(nml_key, run)
|
||||||
if operator == "=":
|
if operator == "=":
|
||||||
runs = filter(lambda r: value[r] == operand, runs)
|
runs = list(filter(lambda r: value[r] == operand, runs))
|
||||||
if operator == "!=":
|
if operator == "!=":
|
||||||
runs = filter(lambda r: not value[r] == operand, runs)
|
runs = list(filter(lambda r: not value[r] == operand, runs))
|
||||||
elif operator == ">":
|
elif operator == ">":
|
||||||
runs = filter(lambda r: value[r] > operand, runs)
|
runs = list(filter(lambda r: value[r] > operand, runs))
|
||||||
elif operator == "<":
|
elif operator == "<":
|
||||||
runs = filter(lambda r: value[r] < operand, runs)
|
runs = list(filter(lambda r: value[r] < operand, runs))
|
||||||
elif operator == "in":
|
elif operator == "in":
|
||||||
runs = filter(lambda r: value[r] in operand, runs)
|
runs = list(filter(lambda r: value[r] in operand, runs))
|
||||||
return runs
|
return runs
|
||||||
|
|
||||||
def get_runs(self, in_runs=None, name_run="*", namelist_cond={}, sort_run_by=None):
|
def get_runs(self, in_runs=None, name_run="*", namelist_cond={}, sort_run_by=None):
|
||||||
@@ -106,13 +106,15 @@ class RunSelector:
|
|||||||
success = False
|
success = False
|
||||||
return success
|
return success
|
||||||
|
|
||||||
runs = map(
|
runs = list(
|
||||||
|
map(
|
||||||
os.path.basename,
|
os.path.basename,
|
||||||
filter(os.path.isdir, glob.glob(self.path_in + "/" + name_run)),
|
list(filter(os.path.isdir, glob.glob(self.path_in + "/" + name_run))),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if not in_runs is None:
|
if not in_runs is None:
|
||||||
runs = filter(lambda n: n in runs, in_runs)
|
runs = list(filter(lambda n: n in runs, in_runs))
|
||||||
runs = filter(try_load_nml, runs)
|
runs = list(filter(try_load_nml, runs))
|
||||||
|
|
||||||
# Select runs that match namelist conditions
|
# Select runs that match namelist conditions
|
||||||
runs = self.nml_select(runs, namelist_cond)
|
runs = self.nml_select(runs, namelist_cond)
|
||||||
@@ -160,12 +162,12 @@ class RunSelector:
|
|||||||
names = glob.glob(
|
names = glob.glob(
|
||||||
self.path_in + "/" + run + "/output_[0-9][0-9][0-9][0-9][0-9]"
|
self.path_in + "/" + run + "/output_[0-9][0-9][0-9][0-9][0-9]"
|
||||||
)
|
)
|
||||||
nums = map(lambda n: int(n.split("/")[-1].split("_")[1]), names)
|
nums = list(map(lambda n: int(n.split("/")[-1].split("_")[1]), names))
|
||||||
|
|
||||||
if type(in_nums) == int:
|
if type(in_nums) == int:
|
||||||
in_nums = [in_nums]
|
in_nums = [in_nums]
|
||||||
if type(in_nums) == list:
|
if type(in_nums) == list:
|
||||||
nums = filter(lambda n: n in nums, in_nums)
|
nums = list(filter(lambda n: n in nums, in_nums))
|
||||||
|
|
||||||
nums = np.sort(nums)
|
nums = np.sort(nums)
|
||||||
|
|
||||||
@@ -186,12 +188,12 @@ class RunSelector:
|
|||||||
else:
|
else:
|
||||||
nums = []
|
nums = []
|
||||||
else:
|
else:
|
||||||
nums = filter(try_load_info, nums)
|
nums = list(filter(try_load_info, nums))
|
||||||
|
|
||||||
if not time_min is None:
|
if not time_min is None:
|
||||||
nums = filter(lambda n: self.info[run][n]["time"] >= time_min, nums)
|
nums = list(filter(lambda n: self.info[run][n]["time"] >= time_min, nums))
|
||||||
if not time_max is None:
|
if not time_max is None:
|
||||||
nums = filter(lambda n: self.info[run][n]["time"] <= time_max, nums)
|
nums = list(filter(lambda n: self.info[run][n]["time"] <= time_max, nums))
|
||||||
|
|
||||||
if not time is None:
|
if not time is None:
|
||||||
times = np.asarray([[self.info[run][n]["time"], n] for n in nums])
|
times = np.asarray([[self.info[run][n]["time"], n] for n in nums])
|
||||||
|
|||||||
Reference in New Issue
Block a user