From 61da2aaa46ceb91d5f06dba7faeb28d8a48f5fbf Mon Sep 17 00:00:00 2001 From: Noe Brucy Date: Mon, 14 Dec 2020 16:05:04 +0100 Subject: [PATCH] improve format --- baseprocessor.py | 54 +++++++++++++++++++++++++++---------------- fragdisk_galactica.py | 25 ++++++++++---------- gui.py | 18 +++++++++++---- ismfeed_galactica.py | 17 +++++++------- mypool.py | 1 - pipeline.py | 11 +++++---- plotter.py | 27 ++++++++++++---------- postprocessor.py | 31 ++++++++++++++----------- pp_params.py | 9 ++++---- pspec_new.py | 48 +++++--------------------------------- pspec_read.py | 6 ++--- ramses_astrophysix.py | 5 ++-- run_selector.py | 14 ++++++++--- 13 files changed, 134 insertions(+), 132 deletions(-) diff --git a/baseprocessor.py b/baseprocessor.py index ff86b1b..bf9a147 100644 --- a/baseprocessor.py +++ b/baseprocessor.py @@ -1,37 +1,42 @@ # coding: utf-8 -import sys -import os -import glob as glob import copy +import glob as glob +import os +import subprocess +import sys import time -import tables -from tables import HDF5ExtError +from abc import ABCMeta, abstractmethod +from functools import partial -import pymses import numpy as np -from numpy.polynomial.polynomial import polyfit -from scipy.stats import linregress - -from pymses.sources.ramses import output -from pymses.sources.hop.file_formats import * -from pymses.analysis import Camera, raytracing, slicing, splatting -from pymses.filters import CellsToPoints -from pymses.analysis import ScalarOperator, FractionOperator, MaxLevelOperator +import pymses +import tables from astrophysix.simdm import SimulationStudy from astrophysix.simdm.experiment import ( - Simulation, AppliedAlgorithm, ParameterSetting, ParameterVisibility, + Simulation, ) from astrophysix.simdm.results import GenericResult, Snapshot +from numpy.polynomial.polynomial import polyfit +from pymses.analysis import ( + Camera, + FractionOperator, + MaxLevelOperator, + ScalarOperator, + raytracing, + slicing, + splatting, +) +from pymses.filters import CellsToPoints +from pymses.sources.hop.file_formats import * +from pymses.sources.ramses import output +from scipy.stats import linregress +from tables import HDF5ExtError + from ramses_astrophysix import ramses - -import subprocess -from functools import partial -from abc import ABCMeta, abstractmethod - from run_selector import * from units import * @@ -429,6 +434,15 @@ class HDF5Container(BaseProcessor): name = transform_name + "_" + rule_src_name + self.rules[name] = Rule( + self, + fn, + group=group, + unit=unit, + description=description, + dependencies=[rule_src_name], + ) + def apply( self, fn, diff --git a/fragdisk_galactica.py b/fragdisk_galactica.py index 2ceb295..bdadec8 100644 --- a/fragdisk_galactica.py +++ b/fragdisk_galactica.py @@ -26,35 +26,36 @@ # negotiate a specific contract with a legal representative of CEA. # from __future__ import print_function, unicode_literals -import os -import numpy as N -import h5py -from astrophysix.simdm import SimulationStudy, Project, ProjectCategory +import datetime +import os + +import h5py +import numpy as N +from astrophysix import units as U +from astrophysix.simdm import Project, ProjectCategory, SimulationStudy +from astrophysix.simdm.datafiles import Datafile, PlotInfo, PlotType from astrophysix.simdm.experiment import ( - Simulation, AppliedAlgorithm, ParameterSetting, ParameterVisibility, ResolvedPhysicalProcess, + Simulation, ) from astrophysix.simdm.protocol import ( - SimulationCode, - AlgoType, Algorithm, + AlgoType, InputParameter, PhysicalProcess, Physics, + SimulationCode, ) from astrophysix.simdm.results import GenericResult, Snapshot -from astrophysix.simdm.datafiles import Datafile, PlotType, PlotInfo from astrophysix.utils.file import FileType -from astrophysix import units as U +from matplotlib import gridspec +from mpl_toolkits.axes_grid1 import AxesGrid, Grid from plotter import * -import datetime -from mpl_toolkits.axes_grid1 import AxesGrid, Grid -from matplotlib import gridspec P.rcParams["text.usetex"] = False diff --git a/gui.py b/gui.py index fe5db27..123561f 100644 --- a/gui.py +++ b/gui.py @@ -1,20 +1,28 @@ import matplotlib as mpl -import matplotlib.pyplot as plt -from matplotlib.widgets import Slider, Button, RadioButtons, LassoSelector -from matplotlib.widgets import SpanSelector, PolygonSelector, CheckButtons import matplotlib.patches as patches +import matplotlib.pyplot as plt from matplotlib.lines import Line2D from matplotlib.path import Path +from matplotlib.widgets import ( + Button, + CheckButtons, + LassoSelector, + PolygonSelector, + RadioButtons, + Slider, + SpanSelector, +) from scipy.stats import linregress -from postprocessor import * from skimage.draw import line +from postprocessor import * + class DraggablePoint: # http://stackoverflow.com/questions/21654008/matplotlib-drag-overlapping-points-interactively - lock = None # only one can be animated at a time + lock = None # only one can be animated at a time def __init__(self, parent, x=0.1, y=0.1, size=0.1): diff --git a/ismfeed_galactica.py b/ismfeed_galactica.py index 6354729..db32e4f 100644 --- a/ismfeed_galactica.py +++ b/ismfeed_galactica.py @@ -26,29 +26,30 @@ # negotiate a specific contract with a legal representative of CEA. # from __future__ import print_function, unicode_literals -import os -import numpy as N -from astrophysix.simdm import SimulationStudy, Project, ProjectCategory +import os + +import numpy as N +from astrophysix import units as U +from astrophysix.simdm import Project, ProjectCategory, SimulationStudy +from astrophysix.simdm.datafiles import Datafile, PlotInfo, PlotType from astrophysix.simdm.experiment import ( - Simulation, AppliedAlgorithm, ParameterSetting, ParameterVisibility, ResolvedPhysicalProcess, + Simulation, ) from astrophysix.simdm.protocol import ( - SimulationCode, - AlgoType, Algorithm, + AlgoType, InputParameter, PhysicalProcess, Physics, + SimulationCode, ) from astrophysix.simdm.results import GenericResult, Snapshot -from astrophysix.simdm.datafiles import Datafile, PlotType, PlotInfo from astrophysix.utils.file import FileType -from astrophysix import units as U # ----------------------------------------------- Project creation --------------------------------------------------- # # Available project categories are : diff --git a/mypool.py b/mypool.py index 7d48fce..ee26eaa 100644 --- a/mypool.py +++ b/mypool.py @@ -7,7 +7,6 @@ import multiprocessing # multiprocessing module. import multiprocessing.pool import time - from random import randint diff --git a/pipeline.py b/pipeline.py index d641b08..5a66b46 100644 --- a/pipeline.py +++ b/pipeline.py @@ -1,16 +1,17 @@ # coding: utf-8 -import os -import glob -from shutil import copy import argparse +import glob +import os import time -import numpy as np from functools import reduce +from shutil import copy + +import numpy as np -from pp_params import * from plotter import * from postprocessor import * +from pp_params import * fake_pp = PostProcessor() diff --git a/plotter.py b/plotter.py index eb46242..3576926 100644 --- a/plotter.py +++ b/plotter.py @@ -8,27 +8,30 @@ This is the plotter module. @author NoƩ Brucy 2019-2020 """ -import sys import os +import sys from functools import partial -import tables -import numpy as np -from scipy.stats import linregress -from numpy.polynomial.polynomial import polyfit -from scipy.ndimage.filters import gaussian_filter1d -from scipy import optimize -from astrophysix.simdm.datafiles import Datafile, PlotType, PlotInfo -from astrophysix.utils.file import FileType + import matplotlib as mpl +import numpy as np +import tables +from astrophysix.simdm.datafiles import Datafile, PlotInfo, PlotType +from astrophysix.utils.file import FileType +from numpy.polynomial.polynomial import polyfit +from scipy import optimize +from scipy.ndimage.filters import gaussian_filter1d +from scipy.stats import linregress if os.environ.get("DISPLAY", "") == "": print("No display found. Using non-interactive Agg backend") mpl.use("Agg") -import pylab as P -from comparator import * -import pspec_read import datetime +import pylab as P + +import pspec_read +from comparator import * + filetype_from_ext = {ext: ft for ft in FileType for ext in ft.extension_list} diff --git a/postprocessor.py b/postprocessor.py index 19e0104..3632e3d 100644 --- a/postprocessor.py +++ b/postprocessor.py @@ -1,13 +1,15 @@ # coding: utf-8 +import pickle + +import astropy.units as u import pandas as pd +import pymses.utils.regions as reg +from fil_finder import FilFinder2D +from pymses.filters import RegionFilter +from skimage.morphology import medial_axis + import pspec_new from baseprocessor import * -import pymses.utils.regions as reg -from pymses.filters import RegionFilter -import astropy.units as u -from fil_finder import FilFinder2D -import pickle -from skimage.morphology import medial_axis # Getters @@ -82,6 +84,15 @@ def mean_by_bins( # For each cell, bin_number contains the number of the bins it belongs to bin_number = np.zeros(len(y)) + # Go through the min value of x of each bin + for x_min in x_bins[1:-1]: + bin_number = bin_number + (x > x_min).astype(int) + + # Compute the mean in each bin + y_mean = np.zeros(len(x_bins) - 1) + for i in range(len(y_mean)): + y_mean[i] = np.mean(y[bin_number == i]) + # Get the center of each bin if logbins: centers = 10 ** (0.5 * (np.log10(x_bins[1:]) + np.log10(x_bins[:-1]))) @@ -1044,14 +1055,6 @@ class PostProcessor(HDF5Container): alpha_g = (2.0 / 3) * alpha_g return alpha_g - alpha_g = self._ax_avg(getter_alpha_grav, "z", unit=cst.none, surf_qty=True) / ( - coldens * T_avg - ) - - # alpha - alpha_g = (2.0 / 3) * alpha_g - return alpha_g - def _sinks(self): csv_name = ( self.path diff --git a/pp_params.py b/pp_params.py index ad9811c..369186b 100644 --- a/pp_params.py +++ b/pp_params.py @@ -1,10 +1,11 @@ # coding: utf-8 -import numpy as np -import re -import munch -import yaml import os +import re + +import munch +import numpy as np +import yaml _dir_path = os.path.dirname(os.path.realpath(__file__)) diff --git a/pspec_new.py b/pspec_new.py index 006fe64..e5589c6 100644 --- a/pspec_new.py +++ b/pspec_new.py @@ -1,25 +1,19 @@ """Compute power spectra""" -from __future__ import division -from __future__ import print_function +from __future__ import division, print_function -from builtins import range import argparse import sys import textwrap +from builtins import range import numpy as np -from numpy.fft import fftn, ifft - import pymses -from pymses.analysis import ScalarOperator, Camera -from pymses.analysis import cube3d import pymses.utils.misc - import tables as T - -from i_utils import args -from i_utils import tools +from i_utils import args, tools +from numpy.fft import fftn, ifft +from pymses.analysis import Camera, ScalarOperator, cube3d __generator__ = "pspec_new.py" __version__ = "0.2" @@ -434,37 +428,6 @@ parser = argparse.ArgumentParser( """ ), ) -parser.add_argument("repo", help="RAMSES output repository", type=str, default=".") -parser.add_argument("iouts", help="output numbers", type=args.selection, default=":") -parser.add_argument( - "outfile", help="output file format (see below for fields)", type=str -) -parser.add_argument( - "-n", - "--nodename", - help="node name format (see below for fields)", - type=str, - default="/out_%(iout)05d/d%(dim)d/%(varname)s", -) -parser.add_argument( - "-O", - "--order", - help="byte order (= for native)", - type=str, - default="=", - choices=["<", ">", "="], -) -parser.add_argument( - "-c", - "--center", - help="coordinates of the center", - type=args.center, - default=[0.5, 0.5, 0.5], -) -parser.add_argument("-s", "--size", help="cube size", type=float, default=1.0) -parser.add_argument( - "-l", "--level", help="cube level (default: levelMIN)", type=int, default=0 -) parser.add_argument( "repo", help="RAMSES output repository", type=str, default=".", nargs="?" ) @@ -617,6 +580,7 @@ def main(arg): % (clvl, read_lvl) ) clvl = read_lvl + # Degrade cubes ---------------------------------------------------------------- if clvl < read_lvl: print("Degrade cubes") diff --git a/pspec_read.py b/pspec_read.py index c8e3281..7f17211 100644 --- a/pspec_read.py +++ b/pspec_read.py @@ -1,8 +1,8 @@ from builtins import str -import tables as T -import numpy as np -import matplotlib.pyplot as P +import matplotlib.pyplot as P +import numpy as np +import tables as T ################################################################ # 3D diff --git a/ramses_astrophysix.py b/ramses_astrophysix.py index 7fc9e99..f3efb05 100644 --- a/ramses_astrophysix.py +++ b/ramses_astrophysix.py @@ -2,15 +2,14 @@ from astrophysix.simdm.protocol import ( - SimulationCode, - AlgoType, Algorithm, + AlgoType, InputParameter, PhysicalProcess, Physics, + SimulationCode, ) - # Simulation code definition # ramses = SimulationCode( name="Ramses 3 (MHD)", diff --git a/run_selector.py b/run_selector.py index c3ae12a..644065a 100644 --- a/run_selector.py +++ b/run_selector.py @@ -2,12 +2,14 @@ # coding: utf-8 -import os import glob +import os from functools import partial -from pp_params import * + import f90nml +from pp_params import * + class NamelistRecursive: def __init__(self, namelist): @@ -107,7 +109,13 @@ class RunSelector: in_nums[run] = nums_temp for i, run in enumerate(self.runs): - self.nums[run] = self.get_nums(run, in_nums[run], time_min, time_max, time) + self.nums[run] = self.get_nums( + run, + in_nums[run], + time_min, + time_max, + time, + ) def select( self,