Skip to content
Snippets Groups Projects
Select Git revision
  • 97f713ab4d48866e14a28d02f85ccc56214ca72e
  • master default protected
  • fix-issue-901
  • fix-issue-928
  • fix-issue-896-zmq-publish
  • fix-issue-885
  • fix-issue-921
  • fix-910
  • fix-issue-804
  • srt-bandQ-receiver
  • fix-issue-855
  • stable
  • srt-bandW-receiver
  • fix-issue-805
  • feature-med-c-band-srv
  • fix-issue-760
  • fix-issue-628
  • fix-issue-588
  • fix-issue-derotator-328
  • OffsetReview
  • DerotatorAndMinorServo
  • discos1.0.6h
  • discos1.0.6f
  • discos1.0.6e
  • discos1.0.6d
  • discos1.0.6c
  • discos1.0.6b
  • discos1.0.6a
  • discos1.0.6
  • discos1.0.5
  • discos1.0.4
  • discos1.0.3
  • discos1.0.2
  • discos1.0.1
  • discos1.0.0
  • discos1.0-rc02
  • discos1.0-rc01
  • escs-0.5
  • escs-0.4
  • nuraghe-0.6
  • noto-0.1
41 results

posgenerator.py

Blame
    • Giuseppe Carboni's avatar
      97f713ab
      Integration of new SRT LDO derotators into centos_7_compatibility branch (#925) · 97f713ab
      Giuseppe Carboni authored
      * Moved some method from GenericDerotator to SRTKBandDerotator
      
      The methods were not generic, they were specific methods of the old SRTKBandDerotator decommissioned interface.
      These methods are not even called by the DewarPositioner component, therefore it was safe to remove them from the GenericDerotator interface.
      
      * Moved another unused method
      
      * Updated GenericDerotator interface
      
      * Fix #865, fix #869, updated SRTMinorServo component
      
      The component now handles correctly a SETUP command.
      The component is also capable of commanding the gregorian air blade with the 'setGregorianAirBladeStatus' command.
      A few bugs were fixed here and there.
      This branch MUST be tested with the real hardware before merging it onto the centos_7_compatibility branch.
      
      * Fixed small bug
      
      * Removed redundant script
      
      * Uploading files in order to test a clean repository
      
      * Updated PyDewarPositioner for Python 3
      
      * First LDO Derotators working implementation
      
      This commit also brings some clean up inside the SRT test CDB.
      All the stuff that is not used in the production environment has been moved out of the production and test environment and into the Outdated CDB.
      
      * KBand derotator updates
      
      * Moved SRTDerotators out of SRTMinorServoBossCore
      
      Each derotator now has its thread for updating its status
      Integration of new SRT LDO derotators into centos_7_compatibility branch (#925)
      Giuseppe Carboni authored
      * Moved some method from GenericDerotator to SRTKBandDerotator
      
      The methods were not generic, they were specific methods of the old SRTKBandDerotator decommissioned interface.
      These methods are not even called by the DewarPositioner component, therefore it was safe to remove them from the GenericDerotator interface.
      
      * Moved another unused method
      
      * Updated GenericDerotator interface
      
      * Fix #865, fix #869, updated SRTMinorServo component
      
      The component now handles correctly a SETUP command.
      The component is also capable of commanding the gregorian air blade with the 'setGregorianAirBladeStatus' command.
      A few bugs were fixed here and there.
      This branch MUST be tested with the real hardware before merging it onto the centos_7_compatibility branch.
      
      * Fixed small bug
      
      * Removed redundant script
      
      * Uploading files in order to test a clean repository
      
      * Updated PyDewarPositioner for Python 3
      
      * First LDO Derotators working implementation
      
      This commit also brings some clean up inside the SRT test CDB.
      All the stuff that is not used in the production environment has been moved out of the production and test environment and into the Outdated CDB.
      
      * KBand derotator updates
      
      * Moved SRTDerotators out of SRTMinorServoBossCore
      
      Each derotator now has its thread for updating its status
    posgenerator.py 3.78 KiB
    """This module implements the position calculation functions"""
    import datetime
    import time
    from math import sin, cos, tan, atan2, degrees, isclose
    from IRAPy import logger
    from Acspy.Common.TimeHelper import getTimeStamp
    
    
    class PosGenerator(object):
    
        def __init__(self, updatingTime, trackingLeadTime):
            self.updatingTime = updatingTime
            self.trackingLeadTime = trackingLeadTime
            self.mapping = {
                    'parallactic': {
                        'getAngleFunction': PosGenerator.getParallacticAngle,
                        'coordinateFrame': 'horizontal'
                    },
                    'galacticParallactic': {
                        'getAngleFunction': PosGenerator.getGalacticParallacticAngle,
                        'coordinateFrame': 'equatorial'
                    },
            }
    
        def goto(self, iStaticPos):
            yield iStaticPos
    
        def parallactic(self, source, siteInfo, t):
            """Return the parallactic angle"""
            latitude = PosGenerator.getLatitude(siteInfo)
    
            try:
                coordinates = source.getApparentCoordinates(t) # Values in radians
                az, el = coordinates[:2] # The first two elements are (az, el)
                position = PosGenerator.getParallacticAngle(latitude, az, el)
                return position
            except Exception as ex:
                raeson = 'cannot get the %s (az, el)  values' %source._get_name()
                logger.logNotice('%s: %s' %(raeson, ex))
                raise PosGeneratorError(raeson)
    
        def galacticParallactic(self, source, siteInfo, t):
            """Return the galactic parallactic angle"""
            latitude = PosGenerator.getLatitude(siteInfo)
    
            try:
                coordinates = source.getApparentCoordinates(t) # Values in radians
                az, el, ra, dec = coordinates[:4]
                position = PosGenerator.getGalacticParallacticAngle(latitude, az, el, ra, dec)
                return position
            except Exception as ex:
                raeson = 'cannot get the %s (az, el)  values' %source._get_name()
                logger.logNotice('%s: %s' %(raeson, ex))
                raise PosGeneratorError(raeson)
    
        @staticmethod
        def getLatitude(siteInfo):
            """Return the site latitude"""
            try:
                return siteInfo['latitude']
            except (KeyError, TypeError) as ex:
                raise PosGeneratorError('cannot get the latitude: %s' %ex)
            except Exception as ex:
                raeson = 'unexpected exception getting the site latitude'
                logger.logNotice(raeson)
                raise PosGeneratorError(raeson)
    
        @staticmethod
        def getParallacticAngle(latitude, az, el):
            """Arguments in radians"""
            denominator = tan(latitude) * cos(el) - sin(el) * cos(az)
    
            # Avoid division by zero and keep continuity
            if isclose(denominator, 0, abs_tol=1e-10):
                return -90.0 if sin(az) > 0 else 90.0
    
            return degrees(atan2(-sin(az), denominator))
    
        @staticmethod
        def getGalacticAngle(ra, dec):
            """Arguments in radians"""
            # North celestial pole coordinates in equatorial celestial frame (j2000)
            # ncp = ('12 51 26.28', '27 07 41.7')
            # ra0 = ephem.hours(ncp[0])
            # dec0 = ephem.degrees(ncp[1])
            ra0 = 3.3660332687500043
            dec0 = 0.47347728280415174
    
            denominator = cos(dec) * tan(dec0) - sin(dec) * cos(ra-ra0)
    
            # Avoid division by zero and keep continuity
            if isclose(denominator, 0, abs_tol=1e-10):
                return 90.0 if sin(ra-ra0) > 0 else -90.0
    
            return degrees(atan2(sin(ra-ra0), denominator))
    
        @staticmethod
        def getGalacticParallacticAngle(latitude, az, el, ra, dec):
            """Arguments in radians"""
            p = PosGenerator.getParallacticAngle(latitude, az, el)
            g = PosGenerator.getGalacticAngle(ra, dec)
            return p + g
    
    
    class PosGeneratorError(Exception):
        pass