Package ComboCode :: Package cc :: Package tools :: Package numerical :: Module Gridding
[hide private]
[frames] | no frames]

Source Code for Module ComboCode.cc.tools.numerical.Gridding

 1  # -*- coding: utf-8 -*- 
 2   
 3  """ 
 4  Tools for making coordinate grids. 
 5   
 6  Author: R. Lombaert 
 7   
 8  """ 
 9   
10  import numpy as np 
11   
12   
13 -def makeGrid(minval,maxval,gridpoints=0,log=0,make_int=0):
14 15 """ 16 Make grid between max and min value. 17 18 @param minval: lower boundary of grid range 19 @type minval: float 20 @param maxval: upper boundary of grid range 21 @type maxval: float 22 23 @keyword gridpoints: number of grid points, including boundaries. If 0 it 24 is replaced by 2, if 1 then minval is gridpoint 25 26 (default: 0) 27 @type gridpoints: int 28 @keyword log: if grid should be calculated in logspace 29 30 (default: 0) 31 @type log: bool 32 @keyword make_int: 0 if final gridpoints should be rounded to nearest 33 integer 34 35 (default: 0) 36 @type make_int: bool 37 38 @return: the grid points including the boundaries 39 @rtype: array 40 41 """ 42 43 #-- Make floats of in and out 44 minval = float(minval) 45 maxval = float(maxval) 46 47 #-- Check validity of number of grid points. 48 if int(gridpoints) < 2: 49 gridpoints = 2 50 else: 51 gridpoints = int(gridpoints) 52 53 #-- In case of logspace 54 if log: 55 grid = np.logspace(np.log10(minval),np.log10(maxval),gridpoints) 56 #-- In case of linear space 57 else: 58 grid = np.linspace(minval,maxval,gridpoints) 59 60 #-- Round to the nearest integer if requested 61 if bool(make_int): grid = np.around(grid) 62 63 return grid
64