__init__.py 4.01 KB
Newer Older
marc's avatar
marc committed
1
2
3
4
5
6
7
from PyQt5 import QtCore, QtGui
from PyQt5.QtWidgets import QWidget, QApplication
from ui_createpointings import Ui_FormCreatePoinings
from astropy import units as u
from astropy.coordinates import SkyCoord
import sys
import logging
marc's avatar
marc committed
8
import math
marc's avatar
marc committed
9
10
11
12
13

'''
Setup logging
'''
logger = logging.getLogger('root')
marc's avatar
marc committed
14
FORMAT = "[%(asctime)s%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s,filename='createpointings.log',filemode='w'"
marc's avatar
marc committed
15
16
17
18
19
logging.basicConfig(format=FORMAT)
logger.setLevel(logging.DEBUG)

class CreatePointings(Ui_FormCreatePoinings):
    def __init__(self, formCreatePointings):
marc's avatar
marc committed
20
        logger.info('CreatePointings Intialized')
marc's avatar
marc committed
21
22
        Ui_FormCreatePoinings.__init__(self)
        self.setupUi(formCreatePointings)
marc's avatar
marc committed
23
24
        self.target = SkyCoord(0 * u.radian,0 * u.radian)
        try:
marc's avatar
marc committed
25
            self.target = SkyCoord.from_name(self.comboBox.currentText())
marc's avatar
marc committed
26
27
28
29
30
31
32
33
            (self.raStr, self.decStr)  = self.target.to_string('hmsdms').split()
            self.lineEditRA.setText(self.raStr)
            self.lineEditDec.setText(self.decStr)
        except socket.gaierror as e:
            raise URLError("Could not connect to Internet" + str(e))
            raise NameError("Could not connect to Internet" + str(e))
            self.target = Null
                    
marc's avatar
marc committed
34
35
36
37
        '''
        Define slot and connections for GUI
        '''
        self.comboBox.currentIndexChanged.connect(self.updateRADEC)
marc's avatar
marc committed
38
39
        self.buttonBoxCreatePointings.accepted.connect(self.createPointings)
        #self.buttonBoxCreatePointings.rejected.connect(sys.exit(app.exec_()))
marc's avatar
marc committed
40
41
42
43
44
45
    
    def updateRADEC(self):
        self.target = SkyCoord.from_name(self.comboBox.currentText())
        (self.raStr, self.decStr)  = self.target.to_string('hmsdms').split()
        self.lineEditRA.setText(self.raStr)
        self.lineEditDec.setText(self.decStr)
marc's avatar
marc committed
46
        logger.info('New target is: {}'.format(self.target))
marc's avatar
marc committed
47
    
marc's avatar
marc committed
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
76
77
78
79
80
81
82
83
84
85
86
87
    def createPointings(self):
        logger.debug('Start createPointings')
        n = int(self.spinBoxStepsRA.text())
        m = int(self.spinBoxStepsDec.text())
        stepSize = float(self.doubleSpinBoxDistanceDec.text())
        measList = []
        centrePoint = SkyCoord.from_name(self.comboBox.currentText())
        raCentrePoint=centrePoint.ra.degree
        decCentrePoint=centrePoint.dec.degree
        logger.debug('centrePoint is: {}:{} and RADec steps are: {}:{}'.format(raCentrePoint,decCentrePoint, n, m))
        pointings=0
        raSign=-1
        # m x n matrix of pointings with stepsSize steps
        for decStep in range (-m,m): 
            decOffset=decCentrePoint+decStep*stepSize
            raSign=-raSign
            for raStep in range(-n,n):
                if raSign==1:
                    raOffset=raCentrePoint+((stepSize*raStep*raSign)/math.cos(math.radians(decOffset)))
                else:
                    #raOffset=raCentrePoint+((stepSize*raStep+stepSize/2)*raSign)/math.cos(math.radians(decOffset))
                    raOffset=raCentrePoint+((stepSize*(raStep+1))*raSign)/math.cos(math.radians(decOffset))
                logger.debug('raOffset: {0} raSign {1}'.format(raOffset,raSign))
                measList.append(SkyCoord(ra=raOffset*u.degree,dec=decOffset*u.degree,frame='icrs'))
                pointings+=1
        return (measList)
    
    def writePointings(self, measList):
        logger.debug('Start writePointings')
        index=0
        with open('pointings.dat','w') as f:
            for pointing in measList:
                f.write('{}\t{}\t{}\n'.format(index, measList[index].ra.deg, measList[index].dec.deg) )
                logger.debug('{}\t{}\t{}\n'.format(index, measList[index].ra.deg, measList[index].dec.deg) )
                index+=1
                f.flush()
        logger.debug('End createPointings')
        f.close()
        
        
marc's avatar
marc committed
88
89
90
91
92
if __name__ == '__main__':
    app = QApplication(sys.argv)
    formCreatePointings = QWidget()
    myForm = CreatePointings(formCreatePointings)
    formCreatePointings.show()
marc's avatar
marc committed
93
94
    myList = myForm.createPointings()
    myForm.writePointings(myList)
marc's avatar
marc committed
95
    sys.exit(app.exec_())