maped_samesize.py 1.44 KB
# -*- coding: utf-8 -*-
title = "SameSize"
tip = "set maps to reference size"
onein = False

import numpy as np
from nodmath import extract, same_size

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

def nint(x):
    if x > 0: return int(x+0.5000001)
    else: return int(x-0.4999999)

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):
            ref = BoolItem('Reference (1. Map) [else biggest]')
        name = title.replace(" ", "")
        if args == {}:
           param = FuncParam(_(title), "Select the reference map:\n")
        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):
        out, ms_new = same_size(ms, p.ref)
        if out > 0:
           self.Error("one or more maps have different scales or coordinate systems")
           return [], p
        return ms_new, p