Skip to content

Commit cf47050

Browse files
authored
v0.9.7
version 0.9.7
2 parents a396bfe + a6cef3b commit cf47050

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "qfitswidget"
33
packages = [{ include = "qfitswidget" }]
4-
version = "0.9.6"
4+
version = "0.9.7"
55
description = "PyQt widget for displaying FITS files"
66
authors = ["Tim-Oliver Husser <[email protected]>"]
77
license = "MIT"

qfitswidget/qfitswidget.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22
import time
3+
from dataclasses import dataclass
34
from enum import Enum
45
from typing import Optional, List, Tuple
56
import cv2
7+
import logging
68
from PyQt5 import QtWidgets, QtCore, QtGui
79
import numpy as np
810
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QRunnable
11+
from astropy.coordinates import SkyCoord
912
from astropy.io import fits
1013
from astropy.wcs import WCS
1114
import astropy.units as u
@@ -32,8 +35,19 @@ class CenterMarkStyle(Enum):
3235
CIRCLE = "Circle"
3336

3437

38+
@dataclass
39+
class ProcessMouseHoverResult:
40+
x: float
41+
y: float
42+
coord: SkyCoord
43+
value: np.nparray
44+
mean: float
45+
maxi: float
46+
cut: np.ndarray
47+
48+
3549
class ProcessMouseHoverSignals(QtCore.QObject):
36-
finished = pyqtSignal(float, float, str, str, np.ndarray, float, float, np.ndarray)
50+
finished = pyqtSignal(ProcessMouseHoverResult)
3751

3852

3953
class ProcessMouseHover(QRunnable):
@@ -50,10 +64,9 @@ def run(self) -> None:
5064
# convert to RA/Dec and show it
5165
try:
5266
coord = pixel_to_skycoord(self.x, self.y, self.wcs)
53-
ra = coord.ra.to_string(u.hour, precision=1)
54-
dec = coord.dec.to_string(precision=1)
5567
except (ValueError, AttributeError):
56-
ra, dec = "", ""
68+
logging.exception("bla")
69+
coord = None
5770

5871
# value
5972
iy, ix = int(self.y), int(self.x)
@@ -78,7 +91,9 @@ def run(self) -> None:
7891
cut_normed = self.fits_widget.normalize_data(cut)
7992

8093
# emit
81-
self.signals.finished.emit(self.x, self.y, ra, dec, value, mean, maxi, cut_normed)
94+
self.signals.finished.emit(
95+
ProcessMouseHoverResult(x=self.x, y=self.y, coord=coord, value=value, mean=mean, maxi=maxi, cut=cut_normed)
96+
)
8297

8398
# no idea why, but it's a good idea to sleep a little before we finish
8499
time.sleep(0.01)
@@ -545,9 +560,11 @@ def _mouse_moved(self, event):
545560
t.signals.finished.connect(self._update_mouse_over)
546561
self.mouse_over_thread_pool.tryStart(t)
547562

548-
@pyqtSlot(float, float, str, str, np.ndarray, float, float, np.ndarray)
563+
@pyqtSlot(ProcessMouseHoverResult)
564+
@pyqtSlot(float, float, np.ndarray, float, float, np.ndarray)
549565
def _update_mouse_over(
550-
self, x: float, y: float, ra: str, dec: str, value: float, mean: float, maxi: float, cut_normed: np.ndarray
566+
self,
567+
result: ProcessMouseHoverResult,
551568
) -> None:
552569
# if cached image exists, show it
553570
if self._image_cache is not None:
@@ -556,11 +573,26 @@ def _update_mouse_over(
556573
if self._show_overlay:
557574
if self._text_overlay_visible:
558575
# update text overlay
559-
text = f"X/Y: {x:.1f} / {y:.1f}\n"
560-
text += f"RA/Dec: {ra} / {dec}\n"
561-
val = ", ".join([f"{v:.1f}" for v in value])
576+
text = f"X/Y: {result.x:.1f} / {result.y:.1f}\n"
577+
578+
# WCS?
579+
if "RA---TAN" in self.hdu.header["CTYPE1"]:
580+
text += (
581+
f"RA/Dec: {result.coord.ra.to_string(u.hour, precision=1)} / "
582+
f"{result.coord.dec.to_string(precision=1)}\n"
583+
)
584+
pass
585+
elif "HPLN-TAN" in self.hdu.header["CTYPE1"]:
586+
text += (
587+
f"Tx/Ty: {result.coord.Tx.to_string(precision=1)} / "
588+
f"{result.coord.Ty.to_string(precision=1)}\n"
589+
)
590+
pass
591+
592+
# more
593+
val = ", ".join([f"{v:.1f}" for v in result.value])
562594
text += f"Pixel value: {val}\n"
563-
text += f"Area mean/max: {mean:.1f} / {maxi:.1f}\n"
595+
text += f"Area mean/max: {result.mean:.1f} / {result.maxi:.1f}\n"
564596
self._draw_text_overlay(text)
565597

566598
if self._center_mark_visible:
@@ -570,7 +602,7 @@ def _update_mouse_over(
570602
self._draw_directions()
571603

572604
if self._zoom_visible:
573-
self._draw_zoom(cut_normed)
605+
self._draw_zoom(result.cut)
574606

575607
# draw it
576608
self.canvas.blit(self.figure.bbox)

0 commit comments

Comments
 (0)