Exemplo n.º 1
0
def getEclipseTotality( body1, body2, location, date ):
    '''Returns the angular size of an astronomical object in radians.'''
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( body1, RPNAstronomicalObject ) or not isinstance( body2, RPNAstronomicalObject ) and \
       not isinstance( location, RPNLocation ) or not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected two astronomical objects, a location and a date-time' )

    separation = body1.getAngularSeparation( body2, location, date ).value

    radius1 = body1.getAngularSize( ).value
    radius2 = body2.getAngularSize( ).value

    if separation > fadd( radius1, radius2 ):
        return 0

    distance1 = body1.getDistanceFromEarth( date )
    distance2 = body2.getDistanceFromEarth( date )

    area1 = fmul( pi, power( radius1, 2 ) )
    area2 = fmul( pi, power( radius2, 2 ) )

    area_of_intersection = fadd( getCircleIntersectionTerm( radius1, radius2, separation ),
                                 getCircleIntersectionTerm( radius2, radius1, separation ) )

    if distance1 > distance2:
        result = fdiv( area_of_intersection, area1 )
    else:
        result = fdiv( area_of_intersection, area2 )

    if result > 1:
        return 1
    else:
        return result
Exemplo n.º 2
0
    def getAstronomicalEvent( self, location, date, func, horizon=None, useCenter=False, matchUSNO=False ):
        if isinstance( location, str ):
            location = getLocation( location )

        if horizon is None:
            horizon = float( location.observer.horizon )

        if matchUSNO:
            location.pressure = 0
            horizon -= 34 / 60        # 34 arcminutes

        oldHorizon = location.observer.horizon

        location.observer.date = date.to( 'utc' ).format( )
        location.observer.horizon = str( horizon )

        #print( 'date', date )
        #print( 'utc date', location.observer.date )

        if useCenter:
            result = RPNDateTime.convertFromEphemDate( func( location.observer, self.object, \
                                                             use_center=useCenter ) ).getLocalTime( )
        else:
            result = RPNDateTime.convertFromEphemDate( func( location.observer, self.object ) ).getLocalTime( )

        location.observer.horizon = oldHorizon

        return result
Exemplo n.º 3
0
def getNextDusk( location, date, horizon = -6 ):
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( location, RPNLocation ) or not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected location and date-time arguments' )

    result = RPNAstronomicalObject( ephem.Sun( ) ).getNextSetting( location, date, horizon=horizon )
    return result.getLocalTime( timezone( getTimeZone( location ) ) )
Exemplo n.º 4
0
def getAntitransitTime( body, location, date ):
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( body, RPNAstronomicalObject ) or not isinstance( location, RPNLocation ) or \
       not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected an astronomical object, a location and a date-time' )

    return body.getAntitransitTime( location, date )
Exemplo n.º 5
0
def getAngularSize( body, location, date ):
    '''Returns the angular size of an astronomical object in radians.'''
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( body, RPNAstronomicalObject ) or not isinstance( location, RPNLocation ) or not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected an astronomical object, a location and a date-time' )

    return body.getAngularSize( location, date )
Exemplo n.º 6
0
    def getAzimuthAndAltitude( self, location=None, date=None ):
        if location and date:
            if isinstance( location, str ):
                location = getLocation( location )

            location.observer.date = date.to( 'utc' ).format( )
            self.object.compute( location.observer )

        return RPNMeasurement( mpmathify( self.object.az ), 'radians' ), \
               RPNMeasurement( mpmathify( self.object.alt ), 'radians' )
Exemplo n.º 7
0
def getPreviousAntitransit( body, location, date ):
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( body, RPNAstronomicalObject ) or not isinstance( location, RPNLocation ) or \
       not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected an astronomical object, a location and a date-time' )

    result = body.getPreviousAntitransit( location, date )
    return result.getLocalTime( timezone( getTimeZone( location ) ) )
Exemplo n.º 8
0
def getNextRising( body, location, date ):
    '''Returns the next rising time for an astronomical object.'''
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( body, RPNAstronomicalObject ) or not isinstance( location, RPNLocation ) or not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected an astronomical object, a location and a date-time' )

    result = body.getNextRising( location, date )
    return result.getLocalTime( timezone( getTimeZone( location ) ) )
Exemplo n.º 9
0
    def getAngularSeparation( self, other, location, date ):
        if isinstance( location, str ):
            location = getLocation( location )

        location.observer.date = date.to( 'utc' ).format( )

        self.object.compute( location.observer )
        other.object.compute( location.observer )

        return RPNMeasurement( mpmathify( ephem.separation( ( self.object.az, self.object.alt ),
                                                            ( other.object.az, other.object.alt ) ) ), 'radian' )
Exemplo n.º 10
0
    def getAngularSize( self, location=None, date=None ):
        if location and date:
            if isinstance( location, str ):
                location = getLocation( location )

            location.observer.date = date.to( 'utc' ).format( )
            self.object.compute( location.observer )

        # I have no idea why size seems to return the value in arcseconds... that
        # goes against the pyephem documentation that it always uses radians for angles.
        return RPNMeasurement( mpmathify( fdiv( fmul( fdiv( self.object.size, 3600 ), pi ), 180 ) ), 'radian' )
Exemplo n.º 11
0
    def getAngularSeparation( self, other, location, date ):
        if isinstance( location, str ):
            location = getLocation( location )

        location.observer.date = date.to( 'utc' ).format( )

        self.object.compute( location.observer )
        other.object.compute( location.observer )

        return RPNMeasurement( mpmathify( ephem.separation( ( self.object.az, self.object.alt ),
                                                            ( other.object.az, other.object.alt ) ) ), 'radian' )
Exemplo n.º 12
0
    def getAngularSize( self, location=None, date=None ):
        if location and date:
            if isinstance( location, str ):
                location = getLocation( location )

            location.observer.date = date.to( 'utc' ).format( )
            self.object.compute( location.observer )

        # I have no idea why size seems to return the value in arcseconds... that
        # goes against the pyephem documentation that it always uses radians for angles.
        return RPNMeasurement( mpmathify( fdiv( fmul( fdiv( self.object.size, 3600 ), pi ), 180 ) ), 'radian' )
Exemplo n.º 13
0
def getSkyLocation( body, location, date ):
    '''Returns the location of an astronomical object in the sky in terms of azimuth and altitude.'''
    if isinstance( location, str ):
        location = getLocation( location )

    if not isinstance( body, RPNAstronomicalObject ) or not isinstance( location, RPNLocation ) or not isinstance( date, RPNDateTime ):
        raise ValueError( 'expected an astronomical object, a location and a date-time' )

    az, alt = body.getAzimuthAndAltitude( location, date )

    return [ az.convert( 'degree' ), alt.convert( 'degree' ) ]
Exemplo n.º 14
0
    def getAzimuthAndAltitude( self, location=None, date=None ):
        if location and date:
            if isinstance( location, str ):
                location = getLocation( location )

            location.observer.date = date.to( 'utc' ).format( )
            self.object.compute( location.observer )

        return RPNMeasurement( mpmathify( self.object.az ), 'radians' ), \
               RPNMeasurement( mpmathify( self.object.alt ), 'radians' )

        return self.getAzimuthAndAltitude( )
Exemplo n.º 15
0
    def getAstronomicalEvent( self, location, date, func, horizon=None, useCenter=False, matchUSNO=False ):
        if isinstance( location, str ):
            location = getLocation( location )

        if horizon is None:
            horizon = float( location.observer.horizon )

        if matchUSNO:
            location.pressure = 0
            horizon -= 34/60        # 34 arcminutes

        old_horizon = location.observer.horizon

        location.observer.date = date.to( 'utc' ).format( )
        location.observer.horizon = str( horizon )

        if useCenter:
            result = RPNDateTime.convertFromEphemDate( func( location.observer, self.object, use_center=useCenter ) )
        else:
            result = RPNDateTime.convertFromEphemDate( func( location.observer, self.object ) )

        location.observer.horizon = old_horizon

        return result
Exemplo n.º 16
0
def matchUnitTypes(args, validUnitTypes):
    # imported here to avoid circular dependencies
    from rpn.rpnAstronomy import RPNAstronomicalObject
    from rpn.rpnDateTime import RPNDateTime
    from rpn.rpnLocation import getLocation, RPNLocation

    result = {}

    for unitTypeList in validUnitTypes:
        unitTypes = list(unitTypeList)

        if len(args) != len(unitTypes):
            raise ValueError('argument count mismatch in matchUnitTypes( )')

        for arg in args:
            if isinstance(arg, mpf):
                if 'constant' in unitTypes:
                    result['constant'] = arg
                    continue

                result = {}
                break

            if isinstance(arg, RPNDateTime):
                if 'datetime' in unitTypes:
                    result['datetime'] = arg
                    continue

                result = {}
                break

            if isinstance(arg, str):
                if 'location' in unitTypes:
                    result['location'] = getLocation(arg)
                    continue

                result = {}
                break

            if isinstance(arg, RPNLocation):
                if 'location' in unitTypes:
                    result['location'] = arg
                    continue

                result = {}
                break

            if isinstance(arg, RPNAstronomicalObject):
                if 'body' in unitTypes:
                    result['body'] = arg
                    continue

                result = {}
                break

            unitType = getWhichUnitType(arg, unitTypes)
            #print( 'found unit type', unitType )

            if unitType:
                #print( 'setting unitType', unitType )
                result[unitType] = arg
            else:
                result = {}
                #print( 'breaking...' )
                #print( )
                break

            unitTypes.remove(unitType)
        else:
            return result

    return None