Loading Common/Servers/DewarPositioner/src/DewarPositioner/posgenerator.py +2 −3 Original line number Diff line number Diff line """This module implements the position generators""" import datetime import time from math import sin, cos, tan, atan, degrees from math import sin, cos, tan, atan2, degrees from IRAPy import logger from Acspy.Common.TimeHelper import getTimeStamp Loading Loading @@ -54,8 +54,7 @@ class PosGenerator(object): @staticmethod def getParallacticAngle(latitude, az, el): """Arguments in radians""" tan_p = - sin(az) / (tan(latitude)*cos(el) - sin(el)*cos(az)) p = atan(tan_p) p = atan2(-sin(az), tan(latitude)*cos(el) - sin(el)*cos(az)) return degrees(p) Loading Common/Servers/DewarPositioner/src/DewarPositioner/positioner.py +1 −1 Original line number Diff line number Diff line Loading @@ -536,7 +536,7 @@ class Positioner(object): def _start(self, posgen, *vargs): """Start a new process that computes and sets the position""" if self.isSetup(): self.stopUpdating() # Raise a PositionerError if the process stills alive # self.stopUpdating() # Raise a PositionerError if the process stills alive self.t = ContainerServices.ContainerServices().getThread( name=posgen.__name__, target=self._updatePosition, Loading Common/Servers/DewarPositioner/test/pyunit/posgen/test_parallactic.py +10 −20 Original line number Diff line number Diff line import unittest2 import mocker from math import sin, cos, tan, atan, radians, degrees, pi from math import sin, cos, tan, atan, radians, degrees, pi, atan2 from DewarPositioner.posgenerator import PosGenerator, PosGeneratorError Loading Loading @@ -31,20 +31,6 @@ class PosGeneratorParallacticTest(unittest2.TestCase): gen = self.posgen.parallactic(source, siteInfo={'latitude': 39}) self.assertRaises(PosGeneratorError, gen.next) def test_zero_division_timeout(self): """Raise a PosGeneratorError if case of countinuos zero division""" source = self.m.mock() mocker.expect( source.getRawCoordinates(mocker.ANY) ).result((90, 0)) self.m.count(1, None) self.m.count(1, None) self.m.count(1, None) self.m.count(1, None) self.m.replay() gen = self.posgen.parallactic(source, siteInfo={'latitude': 0}) self.assertRaises(PosGeneratorError, gen.next) def test_right_behavior(self): """Generate 3 positions and do not stop in case of isolated zero div""" azimuths = (45, 45, 90, 45) Loading @@ -62,13 +48,17 @@ class PosGeneratorParallacticTest(unittest2.TestCase): for azd, eld in zip(azimuths, elevations): az = radians(azd) el = radians(eld) try: tan_p = - sin(az) / (tan(latitude)*cos(el) - sin(el)*cos(az)) p = atan(tan_p) except ZeroDivisionError: continue p = atan2(-sin(az), (tan(latitude)*cos(el) - sin(el)*cos(az))) self.assertEqual(degrees(p), gen.next()) def test_parallactic_greater_than_90(self): """Verify the (abs) parallactic angle can be greater than 90 degrees""" lat = 0.68940505453776013 # 39.5 degrees az = 6.1086523819801535 # 350 degrees el = 1.2217304763960306 # 70 degrees # The related parallactic angle must be 165 degrees parallactic = PosGenerator.getParallacticAngle(lat, az, el) self.assertGreater(abs(parallactic), 90) if __name__ == '__main__': unittest2.main() Common/Servers/DewarPositioner/test/pyunit/positioner/test_getScanInfo.py +8 −6 Original line number Diff line number Diff line from __future__ import with_statement import unittest2 import random import math import time import Management Loading Loading @@ -33,12 +34,13 @@ class PositionerStartUpdatingTest(unittest2.TestCase): def test_updating(self): self.cdbconf.setup('KKG') self.cdbconf.setConfiguration('CUSTOM') site_info = {'latitude': 50} latitude = az = el = math.radians(50) site_info = {'latitude': latitude} self.p.setup(site_info, self.source, self.device) posgen = PosGenerator() gen = posgen.parallactic(self.source, site_info) self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_NO_AXIS) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, 60, 60) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, az, el) self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_TRACK) self.p.stopUpdating() self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_NO_AXIS) Loading @@ -53,10 +55,10 @@ class PositionerStartUpdatingTest(unittest2.TestCase): def test_Pip(self): self.cdbconf.setup('KKG') self.cdbconf.setConfiguration('BSC') latitude = 50 latitude = math.radians(50) site_info = {'latitude': latitude} self.p.setup(site_info, self.source, self.device) az, el = 60, 60 az = el = math.radians(60) Pip = PosGenerator.getParallacticAngle(latitude, az, el) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, az, el) self.assertEqual(self.p.getScanInfo()['iStaticPos'], -19.2) Loading @@ -65,12 +67,12 @@ class PositionerStartUpdatingTest(unittest2.TestCase): def test_Pdp(self): self.cdbconf.setup('KKG') self.cdbconf.setConfiguration('CUSTOM') latitude = 50 latitude = az = el = math.radians(50) site_info = {'latitude': latitude} self.p.setup(site_info, self.source, self.device) posgen = PosGenerator() gen = posgen.parallactic(self.source, site_info) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, 50, 50) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, az, el) self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_TRACK) self.p.stopUpdating() self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_NO_AXIS) Loading Common/Servers/DewarPositioner/test/pyunit/positioner/test_offset.py +1 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ class PositionerOffsetTest(unittest2.TestCase): max_limit = self.device.getMaxLimit() min_limit = self.device.getMinLimit() Pis = max_limit - offset/2 time.sleep(0.2) if self.using_mock else time.sleep(3) self.p.setPosition(Pis) time.sleep(0.2) # Wait a bit for the setup max_rewinding_steps = (max_limit - min_limit) // self.device.getStep() Loading Loading
Common/Servers/DewarPositioner/src/DewarPositioner/posgenerator.py +2 −3 Original line number Diff line number Diff line """This module implements the position generators""" import datetime import time from math import sin, cos, tan, atan, degrees from math import sin, cos, tan, atan2, degrees from IRAPy import logger from Acspy.Common.TimeHelper import getTimeStamp Loading Loading @@ -54,8 +54,7 @@ class PosGenerator(object): @staticmethod def getParallacticAngle(latitude, az, el): """Arguments in radians""" tan_p = - sin(az) / (tan(latitude)*cos(el) - sin(el)*cos(az)) p = atan(tan_p) p = atan2(-sin(az), tan(latitude)*cos(el) - sin(el)*cos(az)) return degrees(p) Loading
Common/Servers/DewarPositioner/src/DewarPositioner/positioner.py +1 −1 Original line number Diff line number Diff line Loading @@ -536,7 +536,7 @@ class Positioner(object): def _start(self, posgen, *vargs): """Start a new process that computes and sets the position""" if self.isSetup(): self.stopUpdating() # Raise a PositionerError if the process stills alive # self.stopUpdating() # Raise a PositionerError if the process stills alive self.t = ContainerServices.ContainerServices().getThread( name=posgen.__name__, target=self._updatePosition, Loading
Common/Servers/DewarPositioner/test/pyunit/posgen/test_parallactic.py +10 −20 Original line number Diff line number Diff line import unittest2 import mocker from math import sin, cos, tan, atan, radians, degrees, pi from math import sin, cos, tan, atan, radians, degrees, pi, atan2 from DewarPositioner.posgenerator import PosGenerator, PosGeneratorError Loading Loading @@ -31,20 +31,6 @@ class PosGeneratorParallacticTest(unittest2.TestCase): gen = self.posgen.parallactic(source, siteInfo={'latitude': 39}) self.assertRaises(PosGeneratorError, gen.next) def test_zero_division_timeout(self): """Raise a PosGeneratorError if case of countinuos zero division""" source = self.m.mock() mocker.expect( source.getRawCoordinates(mocker.ANY) ).result((90, 0)) self.m.count(1, None) self.m.count(1, None) self.m.count(1, None) self.m.count(1, None) self.m.replay() gen = self.posgen.parallactic(source, siteInfo={'latitude': 0}) self.assertRaises(PosGeneratorError, gen.next) def test_right_behavior(self): """Generate 3 positions and do not stop in case of isolated zero div""" azimuths = (45, 45, 90, 45) Loading @@ -62,13 +48,17 @@ class PosGeneratorParallacticTest(unittest2.TestCase): for azd, eld in zip(azimuths, elevations): az = radians(azd) el = radians(eld) try: tan_p = - sin(az) / (tan(latitude)*cos(el) - sin(el)*cos(az)) p = atan(tan_p) except ZeroDivisionError: continue p = atan2(-sin(az), (tan(latitude)*cos(el) - sin(el)*cos(az))) self.assertEqual(degrees(p), gen.next()) def test_parallactic_greater_than_90(self): """Verify the (abs) parallactic angle can be greater than 90 degrees""" lat = 0.68940505453776013 # 39.5 degrees az = 6.1086523819801535 # 350 degrees el = 1.2217304763960306 # 70 degrees # The related parallactic angle must be 165 degrees parallactic = PosGenerator.getParallacticAngle(lat, az, el) self.assertGreater(abs(parallactic), 90) if __name__ == '__main__': unittest2.main()
Common/Servers/DewarPositioner/test/pyunit/positioner/test_getScanInfo.py +8 −6 Original line number Diff line number Diff line from __future__ import with_statement import unittest2 import random import math import time import Management Loading Loading @@ -33,12 +34,13 @@ class PositionerStartUpdatingTest(unittest2.TestCase): def test_updating(self): self.cdbconf.setup('KKG') self.cdbconf.setConfiguration('CUSTOM') site_info = {'latitude': 50} latitude = az = el = math.radians(50) site_info = {'latitude': latitude} self.p.setup(site_info, self.source, self.device) posgen = PosGenerator() gen = posgen.parallactic(self.source, site_info) self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_NO_AXIS) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, 60, 60) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, az, el) self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_TRACK) self.p.stopUpdating() self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_NO_AXIS) Loading @@ -53,10 +55,10 @@ class PositionerStartUpdatingTest(unittest2.TestCase): def test_Pip(self): self.cdbconf.setup('KKG') self.cdbconf.setConfiguration('BSC') latitude = 50 latitude = math.radians(50) site_info = {'latitude': latitude} self.p.setup(site_info, self.source, self.device) az, el = 60, 60 az = el = math.radians(60) Pip = PosGenerator.getParallacticAngle(latitude, az, el) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, az, el) self.assertEqual(self.p.getScanInfo()['iStaticPos'], -19.2) Loading @@ -65,12 +67,12 @@ class PositionerStartUpdatingTest(unittest2.TestCase): def test_Pdp(self): self.cdbconf.setup('KKG') self.cdbconf.setConfiguration('CUSTOM') latitude = 50 latitude = az = el = math.radians(50) site_info = {'latitude': latitude} self.p.setup(site_info, self.source, self.device) posgen = PosGenerator() gen = posgen.parallactic(self.source, site_info) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, 50, 50) self.p.startUpdating(Management.MNG_TRACK, Antenna.ANT_NORTH, az, el) self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_TRACK) self.p.stopUpdating() self.assertEqual(self.p.getScanInfo()['axis'], Management.MNG_NO_AXIS) Loading
Common/Servers/DewarPositioner/test/pyunit/positioner/test_offset.py +1 −0 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ class PositionerOffsetTest(unittest2.TestCase): max_limit = self.device.getMaxLimit() min_limit = self.device.getMinLimit() Pis = max_limit - offset/2 time.sleep(0.2) if self.using_mock else time.sleep(3) self.p.setPosition(Pis) time.sleep(0.2) # Wait a bit for the setup max_rewinding_steps = (max_limit - min_limit) // self.device.getStep() Loading