Skip to content

Commit

Permalink
Merge pull request #112 from astronomy-commons/delucchi/math
Browse files Browse the repository at this point in the history
Fix mismatched destination pixel map behavior
  • Loading branch information
delucchi-cmu authored Jul 12, 2023
2 parents 293a76d + 6796913 commit eb3a3db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies = [
"pyarrow",
"astropy",
"regions",
"typing-extensions"
"typing-extensions>=4.3.0",
]

# On a mac, install optional dependencies with `pip install '.[dev]'` (include the single quotes)
Expand All @@ -46,8 +46,6 @@ dev = [
"ipykernel", # Also used in building notebooks into Sphinx
"ipython", # Also used in building notebooks into Sphinx
"myst_parser", # Renders markdown alongside RST
"matplotlib", # Used in sample notebook intro_notebook.ipynb
"numpy", # Used in sample notebook intro_notebook.ipynb
]

[build-system]
Expand Down
6 changes: 3 additions & 3 deletions src/hipscat/pixel_math/partition_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def compute_pixel_map(histogram, highest_order=10, lowest_order=0, threshold=1_0
nested_sums.append(histogram.reshape(-1, explosion_factor).sum(axis=1))
nested_sums.append(histogram)

## Determine the highest order that does not exceed the threshold
orders_at_threshold = [0 if 0 < k <= threshold else None for k in nested_sums[0]]
for order in range(lowest_order, highest_order + 1):
## Determine the lowest order that does not exceed the threshold
orders_at_threshold = [lowest_order if 0 < k <= threshold else None for k in nested_sums[lowest_order]]
for order in range(lowest_order + 1, highest_order + 1):
new_orders_at_threshold = np.array(
[order if 0 < k <= threshold else None for k in nested_sums[order]]
)
Expand Down
26 changes: 26 additions & 0 deletions tests/hipscat/pixel_math/test_partition_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,29 @@ def test_generate_constant_pixel_map_invalid_inputs():
## Order doesn't match histogram length
with pytest.raises(ValueError, match="histogram is not the right size"):
hist.generate_constant_pixel_map(initial_histogram, constant_healpix_order=2)


def test_destination_map_matching_behavior():
"""Test that we get the same size destination pixel map, whether we compute
directly, or from an existing alignment."""
raw_histogram = hist.empty_histogram(2)
raw_histogram[0:6] = 22946
raw_histogram[64:79] = 185670

alignment = hist.generate_alignment(
raw_histogram,
highest_order=2,
threshold=1_000_000,
)
destination_pixel_map_a = hist.compute_pixel_map(
raw_histogram,
highest_order=2,
threshold=1_000_000,
)

destination_pixel_map_b = hist.generate_destination_pixel_map(
raw_histogram,
alignment,
)

assert len(destination_pixel_map_a) == len(destination_pixel_map_b)

0 comments on commit eb3a3db

Please sign in to comment.