Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tribin error with 'remove accumulation bins with no data' #16

Open
G-kodes opened this issue Dec 6, 2024 · 1 comment
Open

tribin error with 'remove accumulation bins with no data' #16

G-kodes opened this issue Dec 6, 2024 · 1 comment

Comments

@G-kodes
Copy link

G-kodes commented Dec 6, 2024

I am attempting to plot some data using matplotlib sub-figures (About 64 graphs total), and also plot a tri-bin shading using the log scaling and a gridsize of 4. All of my graphs work except one. I keep getting an error: IndexError: boolean index did not match indexed array along axis 0; size of axis is 16 but size of corresponding boolean axis is 17

When I trace the error, it is comming from this line of code:

offsets = offsets[good_idxs, :]

In this snippet, the good_idxs boolean mask used to filter/keep the correct indices has one more entry than it should, causing a mismatch. In my use-case, I am able to trace the extra index item back to this line:

indices = tribin_helpers.ternary_to_serial(gridsize, it, il, ir) + 1

When I lookup the function however, I cant seem to make heads or tails of how the ternary -> serial conversion works under the hood (Spesifically the i0, i and shift parameters). This error seems like an edge-case that has something to do with assigning tri-bin polygon indices to each data-point, and appears to be unique to this dataset. Could you help me understand this chunk of code so I could maybe try and diagnose the issue further?

def ternary_to_serial(gridsize: int, it: int, il: int, ir: int) -> int:
"""Convert serial index of triangles from ternary indices.
Parameters
----------
gridsize : int
Grid size.
it : int
Index for the t axis.
il : int
Index for the l axis.
ir : int
Index for the r axis.
Returns
-------
i : int
Serial index of triangles from ``0`` to ``gridsize ** 2 - 1``.
If (``it``, ``il``, ``ir``) is out of the triangle with the grid size,
``i == -1``.
Upward triangles come first, followed by downward triangles.
Examples
--------
The following gives the correspondence between the ternary and the serial
indices when ``g == 3``.
+------------------+-------+
| ``(it, il, ir)`` | ``i`` |
+==================+=======+
| ``(2, 0, 0)`` | ``0`` |
| ``(1, 1, 0)`` | ``1`` |
| ``(1, 0, 1)`` | ``2`` |
| ``(0, 2, 0)`` | ``3`` |
| ``(0, 1, 1)`` | ``4`` |
| ``(0, 0, 2)`` | ``5`` |
| ``(1, 0, 0)`` | ``6`` |
| ``(0, 1, 0)`` | ``7`` |
| ``(0, 0, 1)`` | ``8`` |
+------------------+-------+
"""
tmpt = (0 <= it) & (it <= gridsize)
tmpl = (0 <= il) & (il <= gridsize)
tmpr = (0 <= ir) & (ir <= gridsize)
is_inside = tmpt & tmpl & tmpr
i0 = (gridsize - it - 1) * (gridsize - it) // 2 + ir
shift = gridsize * (gridsize + 1) // 2
i1 = (gridsize - it - 2) * (gridsize - it - 1) // 2 + ir
i = np.where(it + il + ir + 1 == gridsize, i0, i1 + shift)
return np.where(is_inside, i, -1)

@G-kodes
Copy link
Author

G-kodes commented Dec 6, 2024

I ended up getting around this by changing my binsize to 5 and changing my gridlines to match via MultipleLocator. Now, they all render nicely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant