From 10fd0a7bc92573e420033ef4c75dc657d7130510 Mon Sep 17 00:00:00 2001 From: ojeda-e Date: Sun, 25 Jul 2021 11:24:52 -0600 Subject: [PATCH] inverted original mask_nans in interpolation function --- membrane_curvature/surface.py | 30 +++++++++---------- .../tests/test_membrane_curvature.py | 8 ++--- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/membrane_curvature/surface.py b/membrane_curvature/surface.py index 3403b2d..36163c3 100644 --- a/membrane_curvature/surface.py +++ b/membrane_curvature/surface.py @@ -39,7 +39,7 @@ def derive_surface(atoms, n_cells_x, n_cells_y, max_width_x, max_width_y): Returns ------- - z_coordinates: numpy.ndarray + z_coordinates: np.ndarray Average z-coordinate values. Return Numpy array of floats of shape `(n_cells_x, n_cells_y)`. @@ -55,8 +55,8 @@ def get_z_surface(coordinates, n_x_bins=10, n_y_bins=10, x_range=(0, 100), y_ran Parameters ---------- - coordinates : numpy.ndarray - Coordinates of AtomGroup. Numpy array of shape=(n_atoms, 3). + coordinates : np.ndarray + Coordinates of AtomGroup. NumPy array of shape=(n_atoms, 3). n_x_bins : int. Number of bins in grid in the `x` dimension. n_y_bins : int. @@ -70,7 +70,7 @@ def get_z_surface(coordinates, n_x_bins=10, n_y_bins=10, x_range=(0, 100), y_ran ------- z_surface: np.ndarray Surface derived from set of coordinates in grid of `x_range, y_range` dimensions. - Returns Numpy array of floats of shape (`n_x_bins`, `n_y_bins`) + Returns NumPy array of floats of shape (`n_x_bins`, `n_y_bins`) """ @@ -135,53 +135,53 @@ def normalized_grid(grid_z_coordinates, grid_norm_unit): def interpolation_by_array(array_surface): """ - Interpolates values contained in array_surface over axi + Interpolates values contained in `array_surface` over axis Parameters ---------- - array_surface: numpy.ndarray - Numpy array of floats of shape (`n_x_bins`, `n_y_bins`) + array_surface: np.ndarray + Array of floats of shape (`n_x_bins`, `n_y_bins`) Returns ------- interpolated_array: np.ndarray Returns interpolated array. - Numpy array of shape (`n_x_bins` x `n_y_bins`,) + Array of shape (`n_x_bins` x `n_y_bins`,) """ # create mask for nans - mask_nans = np.isnan(array_surface) + mask_nans = ~np.isnan(array_surface) # index of array_surface index_array = np.arange(array_surface.shape[0]) # interpolate values in array interpolated_array = np.interp(index_array, - np.flatnonzero(~mask_nans), - array_surface[~mask_nans]) + np.flatnonzero(mask_nans), + array_surface[mask_nans]) return interpolated_array def surface_interpolation(array_surface): """ - Calculates interpolation + Calculates interpolation of arrays. Parameters ---------- array_surface: np.ndarray - Numpy array of floats of shape (`n_x_bins`, `n_y_bins`) + Array of floats of shape (`n_x_bins`, `n_y_bins`) Returns ------- - Returns interpolated surface + interpolated_surface: np.ndarray Interpolated surface derived from set of coordinates in grid of `x_range, y_range` dimensions. - Numpy array of floats of shape (`n_x_bins`, `n_y_bins`) + Array of floats of shape (`n_x_bins`, `n_y_bins`) """ diff --git a/membrane_curvature/tests/test_membrane_curvature.py b/membrane_curvature/tests/test_membrane_curvature.py index eabd3a6..602fe33 100644 --- a/membrane_curvature/tests/test_membrane_curvature.py +++ b/membrane_curvature/tests/test_membrane_curvature.py @@ -8,7 +8,7 @@ derive_surface, get_z_surface, surface_interpolation) from membrane_curvature.curvature import mean_curvature, gaussian_curvature import numpy as np -from numpy.testing import assert_almost_equal +from numpy.testing import assert_almost_equal, assert_allclose import MDAnalysis as mda from membrane_curvature.tests.datafiles import (GRO_PO4_SMALL, XTC_PO4_SMALL) from membrane_curvature.base import MembraneCurvature @@ -216,13 +216,11 @@ def test_get_z_surface(x_bin, y_bin, x_range, y_range, expected_surface): [150., np.nan, 150.], [150., 150., 150.])), np.full((3, 3), 150.)), - # array 4x3 with all 150 and two nans + # array 3x4 with all 150 and two nans (np.array([[150., 150, 150., 150.], [150., np.nan, np.nan, 150.], [150., 150., 150., 150.]]), - np.array([[150., 150, 150., 150.], - [150., 150., 150., 150.], - [150., 150., 150., 150.]])), + np.full((3,4), 150.)), # array 4x4 with all 150 and two nans (np.array([[150., 150, 150., 150.], [150., np.nan, np.nan, 150.],