Skip to content

Commit

Permalink
Minor.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabaldini committed Apr 16, 2024
1 parent e406e34 commit 37a95db
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
43 changes: 43 additions & 0 deletions hexsample/hexagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,48 @@ def neighbors_even_q(col: int, row: int) -> tuple:
}


_ADC_SEQUENCE_SHORT = (0, 1, 5, 6, 2, 3, 4)
_ADC_SEQUENCE_SHORT_LENGTH = len(_ADC_SEQUENCE_SHORT)
_ADC_SEQUENCE_LONG = (0, 2, 5, 4, 2, 1, 4, 6, 1, 3, 6, 0, 3, 5)
_ADC_SEQUENCE_LONG_LENGTH = len(_ADC_SEQUENCE_LONG)


def adc_channel_odd_r(col: int, row: int) -> int:
"""
"""
return -1

def adc_channel_even_r(col: int, row: int) -> int:
"""
"""
start = _ADC_SEQUENCE_SHORT.index(_ADC_SEQUENCE_LONG[row % _ADC_SEQUENCE_LONG_LENGTH])
index = (col + start) % _ADC_SEQUENCE_SHORT_LENGTH
return _ADC_SEQUENCE_SHORT[index]

def adc_channel_odd_q(col: int, row: int) -> int:
"""
"""
return -1

def adc_channel_even_q(col: int, row: int) -> int:
"""
"""
start = _ADC_SEQUENCE_SHORT.index(_ADC_SEQUENCE_LONG[col % _ADC_SEQUENCE_LONG_LENGTH])
index = (row + start) % _ADC_SEQUENCE_SHORT_LENGTH
return _ADC_SEQUENCE_SHORT[index]


# Lookup table for .
_ADC_PROXY_DICT = {
HexagonalLayout.ODD_R: adc_channel_odd_r,
HexagonalLayout.EVEN_R: adc_channel_even_r,
HexagonalLayout.ODD_Q: adc_channel_odd_q,
HexagonalLayout.EVEN_Q: adc_channel_even_q,
}




class HexagonalGrid:

# pylint: disable = too-many-instance-attributes
Expand Down Expand Up @@ -161,6 +203,7 @@ def __init__(self, layout: HexagonalLayout, num_cols: int, num_rows: int,
# Cache the proper function to retrieve the neighbor pixels from the
# lookup table---this is used, e.g., for the clustering.
self.neighbors = _NEIGHBORS_PROXY_DICT[self.layout]
self.adc_channel = _ADC_PROXY_DICT[self.layout]

def pointy_topped(self) -> bool:
"""Return True if the layout is pointy-topped.
Expand Down
5 changes: 3 additions & 2 deletions tests/test_hexagon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from hexsample.hexagon import HexagonalLayout, HexagonalGrid
from hexsample.hexagon import HexagonalLayout, HexagonalGrid, adc_channel_even_r
from hexsample.display import HexagonalGridDisplay
from hexsample.plot import plt

Expand Down Expand Up @@ -108,7 +108,8 @@ def test_routing_7(nside: int = 10, pitch: float = 0.1) -> None:
display.draw(pixel_labels=False)
col, row, x, y = grid.pixel_physical_coordinates()
for (_col, _row, _x, _y) in zip(col, row, x, y):
plt.text(_x, _y, f'{_col + _row}', **fmt)
adc = grid.adc_channel(_col, _row)
plt.text(_x, _y, f'{adc}', **fmt)
display.setup_gca()


Expand Down

0 comments on commit 37a95db

Please sign in to comment.