Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywong94 committed Dec 29, 2024
2 parents 92b7b09 + 50adabb commit 1dee9ce
Show file tree
Hide file tree
Showing 14 changed files with 301 additions and 152 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: "weekly"
groups:
actions:
patterns:
- "*"
17 changes: 17 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
changelog:
exclude:
authors:
- pre-commit-ci
categories:
- title: Bug Fixes
labels:
- bug
- title: New Features
labels:
- enhancement
- title: Documentation
labels:
- Documentation
- title: Other Changes
labels:
- "*"
15 changes: 13 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ on:
pull_request:

jobs:

test:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
with:
envs: |
- linux: codestyle
pytest: false
- linux: py38-test-oldestdeps
- macos: py39-test
- windows: py39-test
- linux: py310-test
- linux: py311-test-devdeps
- macos: py311-test-viewer
- windows: py312-test
- linux: py313-test-devdeps
coverage: 'codecov'

publish:
needs: test
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
with:
test_extras: test
test_command: pytest --pyargs astrodendro
secrets:
pypi_token: ${{ secrets.pypi_token }}
33 changes: 33 additions & 0 deletions .github/workflows/update-changelog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow takes the GitHub release notes an updates the changelog on the
# main branch with the body of the release notes, thereby keeping a log in
# the git repo of the changes.

name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@a938690fad7edf25368f37e43a1ed1b34303eb36 # v1.12.0
with:
release-notes: ${{ github.event.release.body }}
latest-version: ${{ github.event.release.name }}
path-to-changelog: CHANGES.md

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGES.md
42 changes: 0 additions & 42 deletions CHANGES

This file was deleted.

77 changes: 77 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
## v0.3.1 - 2024-11-15

<!-- Release notes generated using configuration in .github/release.yml at main -->
### What's Changed

#### Bug Fixes

* Fix compatibility of interactive viewer with recent versions of Matplotlib by @astrofrog in https://github.com/dendrograms/astrodendro/pull/202

#### Other Changes

* Bump actions/checkout from 4.2.0 to 4.2.2 in /.github/workflows in the actions group by @dependabot in https://github.com/dendrograms/astrodendro/pull/201

### New Contributors

* @dependabot made their first contribution in https://github.com/dendrograms/astrodendro/pull/201

**Full Changelog**: https://github.com/dendrograms/astrodendro/compare/v0.3.0...v0.3.1

## v0.3.0 - 2024-11-15

<!-- Release notes generated using configuration in .github/release.yml at main -->
### What's Changed

* update "Iterable" import for Python versions > 3.9 by @nbrunett in https://github.com/dendrograms/astrodendro/pull/184
* Fix viewer in Python 3 by @indebetouw in https://github.com/dendrograms/astrodendro/pull/181
* Remove np.int by @keflavich in https://github.com/dendrograms/astrodendro/pull/179
* h5py removed .value after v3 by @indebetouw in https://github.com/dendrograms/astrodendro/pull/182
* Update package infrastructure by @astrofrog in https://github.com/dendrograms/astrodendro/pull/186
* Update plot.py to pass subtree to get_lines by @tonywong94 in https://github.com/dendrograms/astrodendro/pull/168
* Fix for changes between astropy 5.2.2 and 5.3.1 by @ajrigby in https://github.com/dendrograms/astrodendro/pull/192
* Fix tests/continuous integration by @astrofrog in https://github.com/dendrograms/astrodendro/pull/193
* WCSAxes import fix by @Parkerwise in https://github.com/dendrograms/astrodendro/pull/198
* Update infrastructure and fix compatibility with Numpy 2.0 by @astrofrog in https://github.com/dendrograms/astrodendro/pull/200

### New Contributors

* @nbrunett made their first contribution in https://github.com/dendrograms/astrodendro/pull/184
* @indebetouw made their first contribution in https://github.com/dendrograms/astrodendro/pull/181
* @tonywong94 made their first contribution in https://github.com/dendrograms/astrodendro/pull/168
* @ajrigby made their first contribution in https://github.com/dendrograms/astrodendro/pull/192
* @Parkerwise made their first contribution in https://github.com/dendrograms/astrodendro/pull/198

**Full Changelog**: https://github.com/dendrograms/astrodendro/compare/v0.2.0...v0.3.0

## 0.2.0 (2016-09-29)

- Make sure that calling structure_at with an array, list, or tuple all behave the same. [#98]

- Added support for linked scatter plots and multiple selections. [#104, #105, #109, #136]

- Added support for custom functions to define what a 'neighbor' is. [#108]

- Fixed a bug that caused the interactive viewer when showing a dendrogram loaded from a file. [#106, #110]

- Added a 'prune' method to prune dendrograms after computing them. [#111]

- Added support for brightness temperatures in Kelvin. [#112]

- Cache/memoize catalog statistics. [#115]

- Make sure that periodic boundaries (e.g. longitude) are properly supported. [#121]

- Added progress bar for catalog computation. [#127]

- Better support for image WCS. [#126, #137]

- Improve the performance of dendrogram loading. [#131]

- Include dendrogram parameters in HDF5 files. [#142, #145]

- Give HDUs names in FITS output. [#144]


## 0.1.0 (2013-11-09)

Initial release
2 changes: 1 addition & 1 deletion astrodendro/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def _make_catalog(structures, fields, metadata, statistic, verbose=False):
for index_array, shape in zip(indices, shape_tuple):
# catch simple cases where a structure wraps around the image boundary
i2 = np.where(index_array < shape/2, index_array+shape, index_array)
if i2.ptp() < index_array.ptp(): # more compact with wrapping. Use this
if np.ptp(i2) < np.ptp(index_array): # more compact with wrapping. Use this
index_array[:] = i2

stat = ScalarStatistic(values, indices)
Expand Down
4 changes: 4 additions & 0 deletions astrodendro/dendrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ def __init__(self, dendrogram):
uniq, bins = np.unique(index_map, return_inverse=True)
packed = dict((u, i) for i, u in enumerate(uniq))

# starting with numpy 2.0 or later, bins is no longer 1-dimensional,
# so we always ravel the array to make it 1-d
bins = bins.ravel()

flat_idx = index_map.ravel()
ri = np.argsort(bins)
idx_ct = np.bincount(bins)
Expand Down
41 changes: 41 additions & 0 deletions astrodendro/tests/test_viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest
import numpy as np

import matplotlib.pyplot as plt
from ..dendrogram import Dendrogram
from matplotlib.backend_bases import MouseEvent


DATA = np.array([[1, 3, 4, 4, 1, 4],
[1, 2, 3, 2, 1, 3],
[2, 1, 1, 3, 1, 2],
[1, 1, 1, 1, 1, 1],
[2, 3, 2, 1, 1, 2],
[2, 3, 5, 3, 1, 1]])


def test_viewer(capsys):

original_backend = plt.get_backend()

try:
plt.switch_backend('qtagg')
except ImportError:
pytest.skip("This test requires Qt to be installed")

d = Dendrogram.compute(DATA)
viewer = d.viewer()

plt.show(block=False)

cb = viewer.fig.canvas.callbacks

cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 660, 520, 1))
cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 890, 800, 1))
cb.process('button_press_event', MouseEvent('button_press_event', viewer.fig.canvas, 700, 700, 1))

plt.switch_backend(original_backend)

captured = capsys.readouterr()
assert captured.out == ""
assert captured.err == ""
22 changes: 5 additions & 17 deletions astrodendro/viewer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Licensed under an MIT open source license - see LICENSE

from collections import defaultdict
import warnings
from functools import reduce

import numpy as np
Expand Down Expand Up @@ -87,23 +86,14 @@ def __init__(self, dendrogram):

ax_image_limits = [0.1, 0.1, 0.4, 0.7]

try:
from wcsaxes import WCSAxes
__wcaxes_imported = True
except ImportError:
__wcaxes_imported = False
if self.dendrogram.wcs is not None:
warnings.warn("`WCSAxes` package required for wcs coordinate display.")

if self.dendrogram.wcs is not None and __wcaxes_imported:
if self.dendrogram.wcs is not None:

if self.array.ndim == 2:
slices = ('x', 'y')
else:
slices = ('x', 'y', 1)

ax_image = WCSAxes(self.fig, ax_image_limits, wcs=self.dendrogram.wcs, slices=slices)
self.ax_image = self.fig.add_axes(ax_image)
self.ax_image = self.fig.add_axes(ax_image_limits, projection=self.dendrogram.wcs, slices=slices)

else:
self.ax_image = self.fig.add_axes(ax_image_limits)
Expand Down Expand Up @@ -287,7 +277,7 @@ def _update_lines(self, selection_id):

# Remove previously selected collection
if selection_id in self.selected_lines:
self.ax_dendrogram.collections.remove(self.selected_lines[selection_id])
self.selected_lines[selection_id].remove()
del self.selected_lines[selection_id]

if structure is None:
Expand Down Expand Up @@ -318,15 +308,13 @@ def _update_lines(self, selection_id):
self.ax_dendrogram.add_collection(self.selected_lines[selection_id])

def remove_contour(self, selection_id):

if selection_id in self.selected_contour:
for collection in self.selected_contour[selection_id].collections:
self.ax_image.collections.remove(collection)
self.selected_contour[selection_id].remove()
del self.selected_contour[selection_id]

def remove_all_contours(self):
""" Remove all selected contours. """
for key in self.selected_contour.keys():
for key in list(self.selected_contour):
self.remove_contour(key)

def update_contours(self):
Expand Down
Loading

0 comments on commit 1dee9ce

Please sign in to comment.