From f6d047742afdf3cc15e9da59efcf7fdb452742a2 Mon Sep 17 00:00:00 2001 From: Shelbe Timothy Date: Fri, 2 Aug 2019 13:32:23 -0700 Subject: [PATCH 1/4] frame timestamps for both SJI and raster --- glue_solar/__init__.py | 3 ++- glue_solar/instruments/__init__.py | 1 + glue_solar/instruments/iris.py | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/glue_solar/__init__.py b/glue_solar/__init__.py index 46ee99d..475c254 100644 --- a/glue_solar/__init__.py +++ b/glue_solar/__init__.py @@ -4,7 +4,7 @@ from glue_solar.pixel_extraction import PixelExtractionTool # noqa from glue.config import colormaps from glue_solar.instruments import * - + try: __version__ = get_distribution(__name__).version except DistributionNotFound: @@ -12,5 +12,6 @@ def setup(): ImageViewer.tools.append('solar:pixel_extraction') + ImageViewer.tools.append('timestamp_button') for name, ctable in sorted(cmlist.items()): colormaps.add(ctable.name, ctable) diff --git a/glue_solar/instruments/__init__.py b/glue_solar/instruments/__init__.py index 7deae2d..01a556e 100644 --- a/glue_solar/instruments/__init__.py +++ b/glue_solar/instruments/__init__.py @@ -1 +1,2 @@ from .iris import * +from .timestamp_button import * diff --git a/glue_solar/instruments/iris.py b/glue_solar/instruments/iris.py index 83ec5c4..bd601d6 100644 --- a/glue_solar/instruments/iris.py +++ b/glue_solar/instruments/iris.py @@ -1,7 +1,7 @@ """ A reader for IRIS data. """ -from glue.config import qglue_parser +from glue.config import qglue_parser, data_factory from glue.core import Data, Component from glue.core.coordinates import WCSCoordinates from irispy.spectrograph import (IRISSpectrograph, @@ -18,6 +18,7 @@ def _parse_iris_raster(data, label): w_data.add_component(Component(scan_data.data), f"{window}-scan-{i}") w_data.meta = scan_data.meta + print(scan_data.data) result.append(w_data) return result From fc48dc047534b55b383ae3781c8d8d8bc769732a Mon Sep 17 00:00:00 2001 From: Shelbe Timothy Date: Fri, 2 Aug 2019 13:33:57 -0700 Subject: [PATCH 2/4] frame timestamps for both SJI and raster --- glue_solar/instruments/timestamp_button.py | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 glue_solar/instruments/timestamp_button.py diff --git a/glue_solar/instruments/timestamp_button.py b/glue_solar/instruments/timestamp_button.py new file mode 100644 index 0000000..54d706e --- /dev/null +++ b/glue_solar/instruments/timestamp_button.py @@ -0,0 +1,42 @@ +from glue.config import viewer_tool +from glue.viewers.common.tool import CheckableTool +import datetime + +@viewer_tool +class TimestampButton(CheckableTool): + + icon = 'app_icon' + tool_id = 'timestamp_button' + action_text = '' + tool_tip = 'Activate Timestamp' + status_tip = 'Timestamp Active' + shortcut = '' + + def __init__(self, viewer): + super(TimestampButton, self).__init__(viewer) + self.activate() + + def activate(self): + self.viewer.state.add_callback('slices', self.update_label) + + def deactivate(self): + pass + + def update_label(self, slices): + data = self.viewer.state.reference_data + world = data.coords.pixel2world(*slices[::-1]) + + + if isinstance(data.meta['DATE_OBS'], str): + date_obs = datetime.datetime.strptime(data.meta['DATE_OBS'], '%Y-%m-%dT%H:%M:%S.%f') + else: + date_obs = data.meta['DATE_OBS'] + if 'CUNIT3' in data.meta.keys(): + if data.meta['CUNIT3'] == 'seconds': + timestamp = datetime.timedelta(0, float(world[2]))+date_obs + else: + print(data.__dict__) + date_obs = data.meta['STARTOBS'] + obs_delt = data.meta['ENDOBS'] - date_obs + timestamp = date_obs + obs_delt*float(world[2]) + self.viewer.set_status(timestamp.strftime('%Y-%m-%dT%H:%M:%S.%f')) \ No newline at end of file From e8ba4ea25701be75a28e6e2ea2f43a0bb75a206c Mon Sep 17 00:00:00 2001 From: Shelbe Timothy Date: Fri, 2 Aug 2019 13:35:28 -0700 Subject: [PATCH 3/4] remove print statment --- glue_solar/instruments/iris.py | 1 - 1 file changed, 1 deletion(-) diff --git a/glue_solar/instruments/iris.py b/glue_solar/instruments/iris.py index bd601d6..49dcf47 100644 --- a/glue_solar/instruments/iris.py +++ b/glue_solar/instruments/iris.py @@ -18,7 +18,6 @@ def _parse_iris_raster(data, label): w_data.add_component(Component(scan_data.data), f"{window}-scan-{i}") w_data.meta = scan_data.meta - print(scan_data.data) result.append(w_data) return result From d822bac8eca3a5ebf52e4815fe22046a6aa3b134 Mon Sep 17 00:00:00 2001 From: Stuart Mumford Date: Tue, 24 Dec 2019 16:30:27 +0000 Subject: [PATCH 4/4] Refactor a little to be more tolerant of different headers --- glue_solar/instruments/timestamp_button.py | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/glue_solar/instruments/timestamp_button.py b/glue_solar/instruments/timestamp_button.py index 54d706e..05542c0 100644 --- a/glue_solar/instruments/timestamp_button.py +++ b/glue_solar/instruments/timestamp_button.py @@ -24,19 +24,25 @@ def deactivate(self): def update_label(self, slices): data = self.viewer.state.reference_data - world = data.coords.pixel2world(*slices[::-1]) + meta = data.meta + base_time = meta.get("DATE-OBS", meta.get("DATE_OBS", None)) + world = data.coords.pixel2world(*slices[::-1]) - if isinstance(data.meta['DATE_OBS'], str): - date_obs = datetime.datetime.strptime(data.meta['DATE_OBS'], '%Y-%m-%dT%H:%M:%S.%f') + if isinstance(base_time, str): + timestamp = datetime.datetime.strptime(base_time, '%Y-%m-%dT%H:%M:%S.%f') + elif isinstance(base_time, datetime.datetime): + timestamp = base_time else: - date_obs = data.meta['DATE_OBS'] - if 'CUNIT3' in data.meta.keys(): + return + + if 'CUNIT3' in meta.keys(): if data.meta['CUNIT3'] == 'seconds': - timestamp = datetime.timedelta(0, float(world[2]))+date_obs - else: - print(data.__dict__) - date_obs = data.meta['STARTOBS'] - obs_delt = data.meta['ENDOBS'] - date_obs - timestamp = date_obs + obs_delt*float(world[2]) - self.viewer.set_status(timestamp.strftime('%Y-%m-%dT%H:%M:%S.%f')) \ No newline at end of file + timestamp = datetime.timedelta(0, float(world[2])) + timestamp + + elif ('STARTOBS' in meta and 'ENDOBS' in meta): + date_obs = meta['STARTOBS'] + obs_delt = meta['ENDOBS'] - date_obs + timestamp = timestamp + obs_delt*float(world[2]) + + self.viewer.set_status(timestamp.strftime('%Y-%m-%dT%H:%M:%S.%f'))