analysis.py: fix duplicities in position mapping due to rounding errors

This commit is contained in:
Marek Nečada 2021-12-09 14:53:57 +02:00
parent 679ee72bee
commit fed391b20c
1 changed files with 6 additions and 4 deletions

View File

@ -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)