eff_select1.py 2.34 KB
title = "Select1"
tip = "selects all different map types"
onein = False

import numpy as np
from nod3fits import array_to_fits

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 Error(self, msg):
        QMessageBox.critical(self.parent.parent(), title,
                              _(u"Error:")+"\n%s" % str(msg))

    def compute_app(self, **args):
        class FuncParam(DataSet):
            #mtype = StringItem('Map-Type')
            #i = IntItem('i', default=0, max=100, min=0)
            #a = FloatItem('a', default=1.)
            #b = BoolItem("bool", default=True)
            mtype = ChoiceItem("Map-Type", (("I1", "I1"), ("I2", "I2"), ("U", "U"), ("Q", "Q"),
                                            ("I1,I2", "I1,I2"), ("U,Q", "U,Q"),
                                            ("Lon", "Lon"), ("Lat", "Lat")),
                                           default = "I1")
        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 function(self, ms, p):
        mtypes = []
        rows = self.parent._get_selected_rows()
        i = -1
        for m in ms:
            if 'SCANDIR' in m.header and m.header['SCANDIR'] in ("LON", "ALON", "ULON", "GLON", "RA", "HA"):
               scandir = "Lon"
            elif 'SCANDIR' in m.header and m.header['SCANDIR'] in ("LAT", "ALAT", "ULAT", "GLAT", "DEC"):
               scandir = "Lat"
            else:
               scandir = "None"
            i += 1
            if p.mtype in ("Lon", "Lat"):
               mtype = scandir
            else:
               mtype = m.header['MAPTYPE']
            row = rows[i] 
            if not mtype in p.mtype:
               self.parent.listwidget.item(row).setSelected(False)
            else:
               self.parent.listwidget.item(row).setSelected(True)

        return [], p