eff_parsid.py 2.13 KB
title = "ParSid"
tip = "Shows parallactic angle and sidereal time maps"
onein = -1

import copy as cp
import numpy as np

from guidata.qt.QtGui import QMessageBox
from guidata.dataset.datatypes import DataSet
from guidata.dataset.dataitems import (IntItem, StringItem, ChoiceItem, FloatItem, BoolItem)
from guiqwt.config import _

class NOD3_App:

    def __init__(self, parent):
        self.parent = parent
        self.parent.activateWindow()

    def compute_app(self, **args):
        class FuncParam(DataSet):
            s = StringItem('s', default="string")
            i = IntItem('i', default=0, max=100, min=0)
            a = FloatItem('a', default=1.)
            b = BoolItem("bool", default=True)
            choice = ChoiceItem("Unit", ("Degree", "Arcmin", "Arcsec"), default=2)
        name = title.replace(" ", "")
        if args == {}:
           param = FuncParam(_("Title"), "description")
        else:
           param = self.parent.ScriptParameter(name, args)

        # if no parameter needed set param to None. activate next line
        param = None
        self.parent.compute_11(name, lambda m, p: self.function(m, p), param, onein) 

    def Error(self, msg):
        QMessageBox.critical(self.parent.parent(), title,
                              _(u"Error:")+"\n%s" % str(msg))

    def function(self, m, p):
        n = cp.copy(m)
        n.header = m.header.copy()
        maps = []
        try:
           parfound = False
           sidfound = False
           if hasattr(m, 'parmap'):
              parfound = True 
              n.data = m.parmap
              n.header["OBJECT"] = "Parallactic Angle Map"
              maps.append(n)
           if hasattr(m, 'sidmap'):
              sidfound = True
              m.data = m.sidmap
              m.header["OBJECT"] = "Sidereal Time Map"
              maps.append(m)
           if not sidfound and not parfound:
              self.Error("sorry, no parallactic angle or/and sidereal map available")
              return [], p
        except AttributeError:
           self.Error("sorry, no parallactic angle or/and sidereal map available")
           return [], p
        return maps, p