From d40f1fd004ead6e765457cb84bdddec158234c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Thu, 9 Dec 2021 14:53:57 +0200 Subject: [PATCH] analysis.py: fix duplicities in position mapping due to rounding errors --- qpms/analysis.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/qpms/analysis.py b/qpms/analysis.py index 4d79e4b..2b85b37 100644 --- a/qpms/analysis.py +++ b/qpms/analysis.py @@ -4,7 +4,7 @@ the ../misc directory. This needs to be kept in sync with the scripts and qpms/argproc.py. ''' - +import math import numpy as np import qpms from qpms.qpms_c import Particle @@ -79,11 +79,13 @@ class FiniteRectLatModesAnalysis: y += 1 iris1.append(iri1) - # Mapping between ss particles and grid positions; - positions = self.ss.positions.astype(np.float32) # cast to eliminate rounding errors + # Mapping between ss particles and grid positions + positions = self.ss.positions.astype(np.float32) + # round to get rid of duplicities due to rounding errors + positions = positions.round(7-int(math.log(np.amax(abs(positions)),10))) xpositions = np.unique(positions[:,0]) - assert(len(xpositions) == Nx) ypositions = np.unique(positions[:,1]) + assert(len(xpositions) == Nx) assert(len(ypositions == Ny)) # particle positions as integer indices posmap = np.empty((positions.shape[0],2), dtype=int)