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 dd0ee9e2d4
commit d40f1fd004
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. This needs to be kept in sync with the scripts and qpms/argproc.py.
''' '''
import math
import numpy as np import numpy as np
import qpms import qpms
from qpms.qpms_c import Particle from qpms.qpms_c import Particle
@ -79,11 +79,13 @@ class FiniteRectLatModesAnalysis:
y += 1 y += 1
iris1.append(iri1) iris1.append(iri1)
# Mapping between ss particles and grid positions; # Mapping between ss particles and grid positions
positions = self.ss.positions.astype(np.float32) # cast to eliminate rounding errors 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]) xpositions = np.unique(positions[:,0])
assert(len(xpositions) == Nx)
ypositions = np.unique(positions[:,1]) ypositions = np.unique(positions[:,1])
assert(len(xpositions) == Nx)
assert(len(ypositions == Ny)) assert(len(ypositions == Ny))
# particle positions as integer indices # particle positions as integer indices
posmap = np.empty((positions.shape[0],2), dtype=int) posmap = np.empty((positions.shape[0],2), dtype=int)