1
1
from __future__ import annotations
2
2
import time
3
+ from dataclasses import dataclass
3
4
from enum import Enum
4
5
from typing import Optional , List , Tuple
5
6
import cv2
7
+ import logging
6
8
from PyQt5 import QtWidgets , QtCore , QtGui
7
9
import numpy as np
8
10
from PyQt5 .QtCore import pyqtSignal , pyqtSlot , QRunnable
11
+ from astropy .coordinates import SkyCoord
9
12
from astropy .io import fits
10
13
from astropy .wcs import WCS
11
14
import astropy .units as u
@@ -32,8 +35,19 @@ class CenterMarkStyle(Enum):
32
35
CIRCLE = "Circle"
33
36
34
37
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
+
35
49
class ProcessMouseHoverSignals (QtCore .QObject ):
36
- finished = pyqtSignal (float , float , str , str , np . ndarray , float , float , np . ndarray )
50
+ finished = pyqtSignal (ProcessMouseHoverResult )
37
51
38
52
39
53
class ProcessMouseHover (QRunnable ):
@@ -50,10 +64,9 @@ def run(self) -> None:
50
64
# convert to RA/Dec and show it
51
65
try :
52
66
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 )
55
67
except (ValueError , AttributeError ):
56
- ra , dec = "" , ""
68
+ logging .exception ("bla" )
69
+ coord = None
57
70
58
71
# value
59
72
iy , ix = int (self .y ), int (self .x )
@@ -78,7 +91,9 @@ def run(self) -> None:
78
91
cut_normed = self .fits_widget .normalize_data (cut )
79
92
80
93
# 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
+ )
82
97
83
98
# no idea why, but it's a good idea to sleep a little before we finish
84
99
time .sleep (0.01 )
@@ -545,9 +560,11 @@ def _mouse_moved(self, event):
545
560
t .signals .finished .connect (self ._update_mouse_over )
546
561
self .mouse_over_thread_pool .tryStart (t )
547
562
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 )
549
565
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 ,
551
568
) -> None :
552
569
# if cached image exists, show it
553
570
if self ._image_cache is not None :
@@ -556,11 +573,26 @@ def _update_mouse_over(
556
573
if self ._show_overlay :
557
574
if self ._text_overlay_visible :
558
575
# 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 ])
562
594
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 "
564
596
self ._draw_text_overlay (text )
565
597
566
598
if self ._center_mark_visible :
@@ -570,7 +602,7 @@ def _update_mouse_over(
570
602
self ._draw_directions ()
571
603
572
604
if self ._zoom_visible :
573
- self ._draw_zoom (cut_normed )
605
+ self ._draw_zoom (result . cut )
574
606
575
607
# draw it
576
608
self .canvas .blit (self .figure .bbox )
0 commit comments