From 9d0078663f3270d0ec5524add46c3c6cb90133f7 Mon Sep 17 00:00:00 2001 From: Karamaz0V1 Date: Fri, 1 Mar 2019 17:16:08 +0100 Subject: [PATCH] Add bbox in utils --- doc/conf.py | 1 - idefix/__init__.py | 30 ++++++++++-------------------- idefix/utils.py | 41 ++++++++++++++++++++++++++++++++++++----- test/test_utils.py | 28 +++++++++++++++++++--------- 4 files changed, 65 insertions(+), 35 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 1cb32f9..26de83d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -52,7 +52,6 @@ extensions = [ 'sphinx.ext.mathjax', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', - 'recommonmark', ] # Add any paths that contain templates here, relative to this directory. diff --git a/idefix/__init__.py b/idefix/__init__.py index 4ce2be9..1f9c0d3 100644 --- a/idefix/__init__.py +++ b/idefix/__init__.py @@ -1,22 +1,12 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# \file __init__.py -# \brief TODO -# \author Florent Guiotte -# \version 0.1 -# \date 27 févr. 2019 -# -# TODO details +#!/usr/bin/env python +# file __init__.py +# author Florent Guiotte +# version 0.0 +# date 28 févr. 2019 +"""Idefix Module + +Utils and production pipelines for processing LiDAR point clouds. + +""" __all__ = ['utils'] - -__author__ = 'Florent Guiotte' -__copyright__ = 'Copyright 2019, CAMLOT doctoral project' -__credit__ = ['Florent Guiotte'] - -__license__ = 'GPL' -__version__ = 0.0 -__maintainer__ = 'Florent Guiotte' -__email__ = 'florent.guiotte@uhb.fr' -__status__ = 'Development' - diff --git a/idefix/utils.py b/idefix/utils.py index 6dda1b7..1f0fca9 100644 --- a/idefix/utils.py +++ b/idefix/utils.py @@ -1,11 +1,21 @@ -""" -General utils functions. +#!/usr/bin/env python +# file utils.py +# author Florent Guiotte +# version 0.0 +# date 28 févr. 2019 +"""General utils functions. + +This module contains common utils for basic point cloud management and dataviz. + +Notes +----- + +Everything should be highly tested there. -Author: Florent Guiotte -Date: 2019-02-27 -Description: Utilities for idefix package and more. """ +import numpy as np + def first(a): """Returns the inverse of the parameter. @@ -22,3 +32,24 @@ def first(a): Inverse of a. """ return -a + +def bbox(data): + """Returns bounding box of data. + + This function returns the lower and the upper points describing the + bounding box of the points contained in data. + + Parameters + ---------- + data : ndarray (N, 3) + Point cloud data of shape (N, 3), i.e. (x,y,z). + + Returns + ------- + bbox : ndarray + Lower and upper points describing the bounding box such as:: + + [[xmin, ymin, zmin], + [xmax, ymax, zmax]] + """ + return np.array((np.min(data, axis=0), np.max(data, axis=0))) diff --git a/test/test_utils.py b/test/test_utils.py index 02e7436..c3ad792 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,15 +1,25 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# \file %filename%.py -# \brief TODO -# \author Florent Guiotte -# \version 0.1 -# \date 27 févr. 2019 -# -# TODO details +#!/usr/bin/env python +# file test_utils.py +# author Florent Guiotte +# version 0.0 +# date 28 févr. 2019 +"""General utils functions unitary tests. +""" + +import numpy as np +import pytest from idefix import utils def test_first(): assert utils.first(1) == -1 assert utils.first(-4) == 4 + +@pytest.fixture +def fix_data(): + np.random.seed(0) + return np.random.random((10,3)) + +def test_bbox(fix_data): + res = np.array([fix_data.min(axis=0), fix_data.max(axis=0)]) + assert (utils.bbox(fix_data) == res).all()