eff_select.py 2.43 KB
title = "Select"
tip = "selects all different map types"
onein = False

import numpy as np
from nod3fits import array_to_fits, ParSid_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):
            outfile = StringItem('Outfile')
            #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 function(self, ms, p):
        mtypes = []
        sidmap = []
        parmap = []
        scans = []
        for m in ms:
            mtype = m.header['MAPTYPE']
            outfile = str("%s_%s" % (p.outfile, mtype))
            if not mtype in mtypes:
               mtypes.append(mtype)
               array_to_fits(m.data, m.header, outfile, 0)
            else:
               array_to_fits(m.data, m.header, outfile, 1)
            if mtype == mtypes[0]:
               if hasattr(m, 'sidmap'): scans.append(m.header['SCANNUM'])
               if hasattr(m, 'sidmap'): sidmap.append(m.sidmap)
               if hasattr(m, 'parmap'): parmap.append(m.parmap)
        for mtype in mtypes:
            outfile = str("%s_%s" % (p.outfile, mtype))
            #if hasattr(m, 'sidmap'): ParSid_to_fits(m.sidmap, m.header, outfile, name='sidmap')
            #if hasattr(m, 'parmap'): ParSid_to_fits(m.parmap, m.header, outfile, name='parmap')
            if sidmap != []: ParSid_to_fits(sidmap, m.header, outfile, scans, name='sidmap')
            if parmap != []: ParSid_to_fits(parmap, m.header, outfile, scans, name='parmap')
        return [], p