maped_dummy.py
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
title = "RemoveDummyLines"
tip = "removes dummy rows or columns"
onein = True
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 Error(self, msg):
QMessageBox.critical(self.parent.parent(), title,
_(u"Error:")+"\n%s" % str(msg))
def compute_app(self, **args):
name = title.replace(" ", "")
# 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, m, p):
rows, cols = m.data.shape
r = []
for row in range(rows):
if False in np.isnan(m.data[row]): r.append(row)
c = []
for col in range(cols):
if False in np.isnan(m.data[:,col]): c.append(col)
j1 = r[0]
j2 = r[-1]+1
i1 = c[0]
i2 = c[-1]+1
m.header['CRPIX1'] -= i1
m.header['CRPIX2'] -= j1
m.data = m.data[j1:j2,i1:i2]
if hasattr(m, 'sidmap'): m.sidmap = m.sidmap[j1:j2,i1:i2]
if hasattr(m, 'parmap'): m.parmap = m.parmap[j1:j2,i1:i2]
newrows, newcols = m.data.shape
m.header['NAXIS1'] = newcols
m.header['NAXIS2'] = newrows
return m, p