#NEWLINE# def get_xy_rotation_and_scale( header ) : #NEWLINE# #INDENT# '\n    CREDIT: See IDL code at\n    http://www.astro.washington.edu/docs/idl/cgi-bin/getpro/library32.html?GETROT\n    ' #NEWLINE# def calc_from_cd( cd1_1 , cd1_2 , cd2_1 , cd2_2 ) : #NEWLINE# #INDENT# det = ( ( cd1_1 * cd2_2 ) - ( cd1_2 * cd2_1 ) ) #NEWLINE# if ( det < 0 ) : #NEWLINE# #INDENT# sgn = ( - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sgn = 1 #NEWLINE# #UNINDENT# if ( ( cd2_1 == 0.0 ) or ( cd1_2 == 0.0 ) ) : #NEWLINE# #INDENT# xrot = 0.0 #NEWLINE# yrot = 0.0 #NEWLINE# cdelt1 = cd1_1 #NEWLINE# cdelt2 = cd2_2 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# xrot = math . atan2 ( ( sgn * cd1_2 ) , ( sgn * cd1_1 ) ) #NEWLINE# yrot = math . atan2 ( ( - cd2_1 ) , cd2_2 ) #NEWLINE# cdelt1 = ( sgn * math . sqrt ( ( ( cd1_1 ** 2 ) + ( cd1_2 ** 2 ) ) ) ) #NEWLINE# cdelt2 = math . sqrt ( ( ( cd1_1 ** 2 ) + ( cd2_1 ** 2 ) ) ) #NEWLINE# #UNINDENT# return ( xrot , yrot , cdelt1 , cdelt2 ) #NEWLINE# #UNINDENT# def calc_from_crota( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# crota1 = float ( header [ 'CROTA1' ] ) #NEWLINE# xrot = crota1 #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# xrot = None #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# crota2 = float ( header [ 'CROTA2' ] ) #NEWLINE# yrot = crota2 #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# yrot = 0.0 #NEWLINE# #UNINDENT# if ( xrot is None ) : #NEWLINE# #INDENT# xrot = yrot #NEWLINE# #UNINDENT# cdelt1 = float ( header . get ( 'CDELT1' , 1.0 ) ) #NEWLINE# cdelt2 = float ( header . get ( 'CDELT2' , 1.0 ) ) #NEWLINE# return ( xrot , yrot , cdelt1 , cdelt2 ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# pc1_1 = header [ 'PC1_1' ] #NEWLINE# pc1_2 = calc_from_crota [ 'PC1_2' ] #NEWLINE# pc2_1 = header [ 'PC2_1' ] #NEWLINE# pc2_2 = header [ 'PC2_2' ] #NEWLINE# cdelt1 = float ( header [ 'CDELT1' ] ) #NEWLINE# cdelt2 = float ( header [ 'CDELT2' ] ) #NEWLINE# ( cd1_1 , cd1_2 ) = ( ( pc1_1 * cdelt1 ) , ( pc1_2 * cdelt1 ) ) #NEWLINE# ( cd2_1 , cd2_2 ) = ( ( pc2_1 * cdelt2 ) , ( pc2_2 * cdelt2 ) ) #NEWLINE# ( xrot , yrot , cdelt1p , cdelt2p ) = calc_from_cd ( pc1_1 , pc1_2 , pc2_1 , pc2_2 ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cd1_1 = header [ 'CD1_1' ] #NEWLINE# cd1_2 = header [ 'CD1_2' ] #NEWLINE# cd2_1 = header [ 'CD2_1' ] #NEWLINE# cd2_2 = header [ 'CD2_2' ] #NEWLINE# ( xrot , yrot , cdelt1 , cdelt2 ) = calc_from_cd ( cd1_1 , cd1_2 , cd2_1 , cd2_2 ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# ( xrot , yrot , cdelt1 , cdelt2 ) = calc_from_crota ( ) #NEWLINE# #UNINDENT# #UNINDENT# ( xrot , yrot ) = ( math . degrees ( xrot ) , math . degrees ( yrot ) ) #NEWLINE# return ( ( xrot , yrot ) , ( cdelt1 , cdelt2 ) )