eff_pattern.py
2.9 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
title = "Pattern"
tip = "calculates mean pattern from differnt maps and coordinate systems"
onein = False
import numpy as np
import nodastro
RAD = np.pi/180
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):
FacU = IntItem('FacU', default=1, max=1, min=-1)
FacQ = IntItem('FacQ', default=1, max=1, min=-1)
IAngle = FloatItem('IAngle', default=0.0)
Aver = BoolItem("Average I1 and I2", default=False)
name = title.replace(" ", "")
if args == {}:
param = FuncParam(_("Osmose"), "Reads in U and Q map and corrects for parallactic angle rotation.\nFacU: -1 or 1\nFacQ: -1 or 1\nIAngle: Instrumental Angle")
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, ms, p):
scans = []
data = []
for m in ms:
if hasattr(m, 'parmap'):
scan = m.header['SCANNUM']
if not scan in scans:
scans.append(scan)
data.append(self.create_parmaps(m))
#print "data ok", scan, np.min(data[-1]), np.max(data[-1]), data[-1][45][11], m.data[45][11], data[-1][0][0], data[-1][-1][-1]
else:
self.Error("parallactic angle map not found in FITS file")
return [], None
return [], p
def parmat(self, p):
return np.array([[np.cos(p), -np.sin(p)], [np.sin(p), np.cos(p)]])
def create_parmaps(self, m):
rows, cols = m.parmap.shape
na = nodastro.nodtrafo(m.header['DATE_OBS'])
#if 'CROTA2' in m.header: rot = m.header['CROTA2']
if 'CROTA2' in m.header: rot = m.header['CROTA2']
else: rot = 0.0
#if 'EPOCH' in m.header: equinox = m.header['EPOCH']
if 'EPOCH' in m.header: equinox = m.header['EPOCH']
else: equinox = None
coord = m.header['CTYPE1']
for row in range(rows):
b = m.header['CRVAL2'] + (row-m.header['CRPIX2'])*m.header['CDELT2']
for col in range(cols):
l = m.header['CRVAL1'] + (col-m.header['CRPIX1'])*m.header['CDELT1']
omega = na.getPosAng(l, b, rot, coord, equinox)
m.parmap[row][col] = -(m.parmap[row][col] + omega)
return m.parmap