From 1f2758286769fec0bcff2be3457fe243035269a2 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 2 Feb 2018 13:31:30 +0800 Subject: Numba: disable/restrict the Numba JIT usage; needs refactor -> Cython ... --- bin/fg21sim | 2 +- bin/get-healpix-patch | 4 ++-- fg21sim/utils/grid.py | 37 ++++++++++++++++++++----------------- fg21sim/utils/transform.py | 14 +++++++------- fg21sim/webui/handlers/console.py | 4 ++-- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/bin/fg21sim b/bin/fg21sim index cf44efa..eb56df4 100755 --- a/bin/fg21sim +++ b/bin/fg21sim @@ -69,7 +69,7 @@ def main(): logger.info("Setup cosmology model with parameters from configs ...") COSMO.setup(**CONFIGS.cosmology) - logger.info("Importing modules + Numba JIT, waiting ...") + logger.info("Importing modules, waiting ...") from fg21sim.foregrounds import Foregrounds fg = Foregrounds(CONFIGS) fg.preprocess() diff --git a/bin/get-healpix-patch b/bin/get-healpix-patch index 5e4fceb..f985d44 100755 --- a/bin/get-healpix-patch +++ b/bin/get-healpix-patch @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2017 Weitian LI +# Copyright (c) 2017-2018 Weitian LI # MIT license # @@ -50,7 +50,7 @@ def main(): logger = logging.getLogger(tool) logger.info("COMMAND: {0}".format(" ".join(sys.argv))) - logger.info("Importing necessary modules + Numba JIT, waiting ...") + logger.info("Importing necessary modules, waiting ...") import scipy.ndimage import healpy as hp from reproject import reproject_from_healpix diff --git a/fg21sim/utils/grid.py b/fg21sim/utils/grid.py index cf97045..abca9ce 100644 --- a/fg21sim/utils/grid.py +++ b/fg21sim/utils/grid.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Weitian LI +# Copyright (c) 2016-2018 Weitian LI # MIT license """ @@ -7,14 +7,15 @@ Grid utilities. import numpy as np -import numba as nb +# import numba as nb +from scipy import ndimage from .draw import ellipse -from .transform import rotate_center +# from .transform import rotate_center from .healpix import ang2pix_ring -@nb.jit(nopython=True) +# @nb.jit(nopython=True) def _wrap_longitudes(lon): """Wrap the longitudes for values that beyond the valid range [0, 360)""" lon[lon < 0] += 360 @@ -22,7 +23,7 @@ def _wrap_longitudes(lon): return lon -@nb.jit(nopython=True) +# @nb.jit(nopython=True) def _wrap_latitudes(lat): """Wrap the latitudes for values that beyond the valid range [-90, 90]""" lat[lat < -90] = -lat[lat < -90] - 180 @@ -30,11 +31,11 @@ def _wrap_latitudes(lat): return lat -@nb.jit(nb.types.UniTuple(nb.float64[:, :], 2)( - nb.types.UniTuple(nb.float64, 2), - nb.types.UniTuple(nb.float64, 2), - nb.float64), - nopython=True) +# @nb.jit(nb.types.UniTuple(nb.float64[:, :], 2)( +# nb.types.UniTuple(nb.float64, 2), +# nb.types.UniTuple(nb.float64, 2), +# nb.float64), +# nopython=True) def make_coordinate_grid(center, size, resolution): """ Make a rectangular, Cartesian coordinate grid. @@ -116,8 +117,9 @@ def make_ellipse(center, radii, rotation): for ri, ci in zip(rr, cc): gridmap[ri, ci] = 1.0 # Rotate the ellipse about the grid center - gridmap = rotate_center(gridmap, angle=rotation, interp=True, - reshape=False, fill_value=0.0) + # gridmap = rotate_center(gridmap, angle=rotation, interp=True, + # reshape=False, fill_value=0.0) + gridmap = ndimage.rotate(gridmap, angle=rotation, reshape=False, order=1) return gridmap @@ -172,14 +174,15 @@ def make_grid_ellipse(center, size, resolution, rotation=0.0): for ri, ci in zip(rr, cc): gridmap[ri, ci] = 1.0 # Rotate the ellipse about the grid center - gridmap = rotate_center(gridmap, angle=rotation, interp=True, - reshape=False, fill_value=0.0) + # gridmap = rotate_center(gridmap, angle=rotation, interp=True, + # reshape=False, fill_value=0.0) + gridmap = ndimage.rotate(gridmap, angle=rotation, reshape=False, order=1) return (lon, lat, gridmap) -@nb.jit(nb.types.Tuple((nb.int64[:], nb.float64[:]))( - nb.types.UniTuple(nb.float64[:, :], 3), nb.int64), - nopython=True) +# @nb.jit(nb.types.Tuple((nb.int64[:], nb.float64[:]))( +# nb.types.UniTuple(nb.float64[:, :], 3), nb.int64), +# nopython=True) def map_grid_to_healpix(grid, nside): """ Map the filled coordinate grid to the HEALPix map (RING ordering). diff --git a/fg21sim/utils/transform.py b/fg21sim/utils/transform.py index 66f0d29..c59d660 100644 --- a/fg21sim/utils/transform.py +++ b/fg21sim/utils/transform.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2017 Weitian LI +# Copyright (c) 2016-2018 Weitian LI # MIT license """ @@ -17,15 +17,15 @@ References import numpy as np -import numba as nb +# import numba as nb from scipy import ndimage -@nb.jit([nb.float64[:, :](nb.int64[:, :], nb.float64, nb.boolean, - nb.boolean, nb.float64), - nb.float64[:, :](nb.float64[:, :], nb.float64, nb.boolean, - nb.boolean, nb.float64)], - nopython=True) +# @nb.jit([nb.float64[:, :](nb.int64[:, :], nb.float64, nb.boolean, +# nb.boolean, nb.float64), +# nb.float64[:, :](nb.float64[:, :], nb.float64, nb.boolean, +# nb.boolean, nb.float64)], +# nopython=True) def rotate_center(imgin, angle, interp=True, reshape=True, fill_value=0.0): """ Rotate the input image (only gray-scale image currently supported) diff --git a/fg21sim/webui/handlers/console.py b/fg21sim/webui/handlers/console.py index fece851..caf69e3 100644 --- a/fg21sim/webui/handlers/console.py +++ b/fg21sim/webui/handlers/console.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Weitian LI +# Copyright (c) 2016,2018 Weitian LI # MIT license """ @@ -174,7 +174,7 @@ class ConsoleAJAXHandler(BaseRequestHandler): logger.info("Checking the configurations ...") self.configs.check_all() # - logger.info("Importing modules + Numba JIT, waiting ...") + logger.info("Importing modules, waiting ...") from ...foregrounds import Foregrounds # fg = Foregrounds(self.configs) -- cgit v1.2.2