From 4e1004f8f8208f2e440b52a79c0f89e4e41355dd Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Fri, 5 Jan 2018 19:51:36 +0100 Subject: [PATCH] Add doc --- python/cosmotool/smooth.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/python/cosmotool/smooth.py b/python/cosmotool/smooth.py index b28d329..a377ed6 100644 --- a/python/cosmotool/smooth.py +++ b/python/cosmotool/smooth.py @@ -6,7 +6,37 @@ import h5py as h5 import numpy as np import weakref -def smooth_particle_density(position, velocities=None, radius=1e6, boxsize=None, resolution=128, center=None ): +def smooth_particle_density( + position, + velocities=None, + radius=1e6, + boxsize=None, + resolution=128,i + center=None, tmpprefix=None ): + """Use adaptive smoothing to produce density and momentum fields. + + Parameters: + position : numpy array NxQ + the particle positions + if Q==3, only positions. Q==6 means full space phase + velocities : Optional numpy array Nx3. + It is only optional if the above Q is 6. + radius : float + Maximum radius to which we need to compute fields + boxsize : float + Size of the box for the generated fields + resolution : int + Resolution of the output boxes + center : list of 3 floats + Center of the new box. It depends on the convention + for particles. If those are between [0, L], then [0,0,0] + is correct. If those are [-L/2,L/2] then you should set + [L/2,L/2,L/2]. + tmpprefix : string + prefix of the temporary directory that will be used. + It needs to have a lot of space available. By default + '/tmp/ will be typically used. + """ if len(position.shape) != 2: raise ValueError("Invalid position array shape") @@ -19,7 +49,7 @@ def smooth_particle_density(position, velocities=None, radius=1e6, boxsize=None, raise ValueError("Need a boxsize") cx,cy,cz=center - with TemporaryDirectory() as tmpdir: + with TemporaryDirectory(prefix=tmpprefix) as tmpdir: h5_file = os.path.join(tmpdir, 'particles.h5') with h5.File(h5_file, mode="w") as f: data = f.create_dataset('particles', shape=(position.shape[0],7), dtype=np.float32)