
    IR-e6                     N   d dl Zd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZ d dlmZ ddlmZmZmZ dd	lmZ g d
Z e
d          Zddgej        _        ddgej        _        ddgej        _        ddgej        _        ddZd Zd Z G d de          Z G d de          Z dS )    N)units)ICRSBaseCoordinateFrameSkyCoord)WCS)local_partial_pixel_derivatives)SlicedLowLevelWCS   )EllipticalFrameRectangularFrameRectangularFrame1D)CurvedTransform)transform_coord_meta_from_wcsWCSWorld2PixelTransformWCSPixel2WorldTransform   )naxisXYg        g      ?c                 j    |t          |          } j        dk    rP|t          d          t          |           j        k    r't          d                     j                            t           t                    p.t           t                    ot           j        t                    }i }g |d<   g |d<   g |d<   g |d<   g |d<   g |d	<   t           j
                  D ]} j        |         }t          j         j        |                   }d }|}	d
}
||                    d          }d|v rdt          j        z  }t          j        }	d}
nd|v rt          j        }	d}
nd|v rdt          j        z  }t          j        }	d}
nd|v rt          j        }	d}
nud|v rdt          j        z  }t          j        }	d}
nSd|v rt          j        }	d}
n@d|v r<d|v rd}
n5d|v rd}
n.d|v rd}
t          j        }	nd|v rd}
nd|v rd}
nd|v rd}
nd|v rd}
|d                             |
           |d                             |           |d	                             |	           |d                             |           |rg }t           t                    r|                     j        j        |                                                    |                     j        j        |         d d                             dd                                                      nt           t                    r|                     j        j        j         j        |                                                             |                     j        j        j         j        |                  d d                             dd                                                      |d!         |d"         k    r
|d!d"         }|r||vr|                    d!|            j        r< j        |         r/ j        |         |vr |                     j        |                    t          |          d"k    rt          |          n|d!         }n)|pd } j        r j        |         r| j        |         fn|}|d                             |           d g j
        z  |d#<   d g j
        z  |d$<   d g j
        z  |d%<   d& |d         D             } fd't7          |          D             |d(<   t9           |          \  }}}t;          ||)          }t          t          |d                             D ]}|d                             ||v             d*g j
        z  }|j                                        }|r%tA          j!        |d"+          }|d d d d d,f         }|tD          u rt7          d-          D ]\  }}tA          j#        |d d |dz  f                   d!         }||dz           r|d d d,         }t          |          d!k    r>||d!                  }||d#         |<   ||d$         |<   ||d%         |<   d!||d!         d d f<   t          |          dk    r|D ]}d-|d%         |<   n|tH          u rtA          j%        tM          |gd!g|j        z  R d.d*i          d d d!f         }t7          d/          D ]\  }}tA          j#        |d d d!f                   d!         }tA          j'        ||                   d d d,         }||         }t          |          d!k    r>||d!                  }||d#         |<   ||d$         |<   ||d%         |<   d!||d!         d d f<   t          |          d"k    r|D ]}d/|d%         |<   n|tP          u rd|d         v r<|d         )                    d          }d0|d#         |<   d0|d$         |<   d0|d%         |<   d|d         v r<|d         )                    d          }d1|d#         |<   d1|d$         |<   d1|d%         |<   nYt          t          |d                             D ]6}||v r0|j*        |d#         |<   |j*        |d$         |<   |j*        |d%         |<   7||fS )2Nr   z?WCS has more than 2 pixel dimensions, so 'slices' should be setzP'slices' should have as many elements as WCS has pixel dimensions (should be {})nametypewrapunitvisibleformat_unitscalar.zpos.helioprojective.long     f@	longitudezpos.helioprojective.latlatitudezpos.heliographic.stonyhurst.lonzpos.heliographic.stonyhurst.latzpos.heliographic.carrington.long     v@zpos.heliographic.carrington.latposlonlatradecaltazlong   - r   r
   default_axislabel_positiondefault_ticklabel_positiondefault_ticks_positionc                 Z    g | ](}t          |t          t          f          r|d          n|)S )r   )
isinstancelisttuple).0r   s     Dlib/python3.11/site-packages/astropy/visualization/wcsaxes/wcsapi.py
<listcomp>z1transform_coord_meta_from_wcs.<locals>.<listcomp>   sC        dT5M22<Q      c                 4    g | ]\  }}j         |         p|S  )world_axis_names)r3   ifallback_labelwcss      r4   r5   z1transform_coord_meta_from_wcs.<locals>.<listcomp>   s:     ( ( (A~ 	Q1>( ( (r6   default_axis_label	invert_xyF)axisbltrnormalize_by_worldbthc)+r2   pixel_n_dim
ValueErrorlenformatr0   r   r	   _wcsrangeworld_n_dimworld_axis_physical_typesuUnitworld_axis_unitssplitdegarcsec	hourangleappendr<   ctypelowerreplace_world_keepinsertr9   	enumerateapply_slicesr   axis_correlation_matrixcopynpallr   nonzeror   absr   argsortr   indexspine_names)r<   frame_classslicesis_fits_wcs
coord_metaidx	axis_type	axis_unit
coord_wrapr   
coord_typeaxis_type_splitr   fallback_labelstransform_wcsr?   	world_map	transformr:   inv_all_corrm
spine_namer!   re   derivsorderlon_idxlat_idxs   `                           r4   r   r      s7
   v
>Q   [[CO++66<fS_6M6M  
 S#&& 3)**Hz#(C/H/H  JJvJvJvJvJy "J}S_%% V( V(1#6	F3/455	

 'ooc22O(I55"QU]
h(

*i77h'

2i??"QU]
e(

2i??e'

2i??"QU]
e(

2i??e'

/))O++!,JJo--!+JJ_,,!,J"#+KKo--!+JJo--!,JJ_,,!+JJ..!,J6!!*---6!!*---=!((5556!!),,,  	D#s## 	CGM#.4466777CGM#.rr2::3CCIIKKLLLLC!233 CHL.ss/CDJJLLMMMHL&ss';<RaR@WS"%%UWW  
 Aw$q'!!AaCy .D((KK9---# ;(<S(A ;',D88KK 4S 9:::"%d))a--5;;;T!WDD?D#  +C0T3/455  	6!!$''''02tco/EJ+,02tco/EJ+,,.4#/+AJ'( v&  O( ( ( (!*?!;!;( ( (J#$
 +7sF*C*C'M9i'KKKI3z&)**++ 5 59$$Q)^44447S_,L-2244A vaa(((aaa2gJ&&&&v.. 	! 	!MAz*Qqqq!a%x[))!,C AE"  $$B$i3xx!||!#a&)BL
78?BL
78?>H
34U; #a&!!!)
 y>>Q" E E>D
34U;;	*	*	*+}00   $) 
 
 !!Q$ 't__ 	! 	!MAz *Qqqq!tW%%a(CJvc{++DDbD1Ee*C3xx!||!#a&)BL
78?BL
78?>H
34U; #a&!!!)
 y>>Q" C C>B
34U;;		'	'*V,,, (..{;;G@CJ34W=@CJ34W=<?J/09F+++ (..z::G@CJ34W=@CJ34W=<?J/09 3z&12233 	V 	VE	!!  + 78
  + 78 ?J>U
34U;j  r6   c                 v   t          | t                    rt          | j                  n!t          t	          | j                            t          t	          | j                            }| }d}|t          |          }t          d          ||                    d          <   d|v rQt          d          ||                    d          <   |                    d          |                    d          k    }t          | |ddd                   }t          fd|j        D                       }|||fS )z
    Take the input WCS and slices and return a sliced WCS for the transform and
    a mapping of world axes in the sliced WCS to the input WCS.
    FNxyrA   c              3   B   K   | ]}                     |          V  d S N)re   )r3   r:   
world_keeps     r4   	<genexpr>zapply_slices.<locals>.<genexpr>  s1      QQ!***1--QQQQQQr6   )	r0   r	   r1   rZ   rL   rM   slicere   r2   )r<   rh   rs   rr   r?   	wcs_slicer   s         @r4   r]   r]      s"   
 #()) 2#/**

%0011
 U3?++,,IMILL	*/++	)//#&&'&==.3DkkIiooc**+S))FLL,=,==I)#y2??QQQQ}7PQQQQQ	)Y..r6   c                     | j                                         D ]^^}}}}t          |t                    r$|                    dt                                c S t          |t                    r
 |di |c S _d S )Nframer8   )world_axis_object_classesvalues
issubclassr   getr   r   )r<   cls_kwargss       r4   wcsapi_to_celestial_framer     s    !;BBDD ! !Qc8$$ 	!::gtvv.....011 	!3====   	!! !r6   c                   X     e Zd ZdZdZdZd
 fd	Zd Zed             Z	d Z
e
Zd	 Z xZS )r   z=
    WCS transformation from world to pixel coordinates.
    TNFc                     t                                                       |j        dk    rt          d          || _        || _        t          |          | _        d S Nr   z"Only pixel_n_dim =< 2 is supported)super__init__rG   rH   r<   r?   r   frame_inselfr<   r?   	__class__s      r4   r   z WCSWorld2PixelTransform.__init__#  sV    ?QABBB"1#66r6   c                 x    t          |t          |                     o| j        |j        u o| j        |j        k    S r   r0   r   r<   r?   r   others     r4   __eq__zWCSWorld2PixelTransform.__eq__.  <    ud4jj)) 2EI%2%/1	
r6   c                     | j         j        S r   r<   rM   r   s    r4   
input_dimsz"WCSWorld2PixelTransform.input_dims5      x##r6   c                    t          |j                  }t          |          | j        j        k    r-t          d| j        j         dt          |           d          t          |d                   dk    rt          j        d          }n | j        j        | }| j	        r|d d d         }t          j
        |          j        }|S )N	Expected  world coordinates, got  r   )r   r   rA   )r1   TrI   r<   rM   rH   r`   zerosworld_to_pixel_valuesr?   array)r   worldpixels      r4   rt   z!WCSWorld2PixelTransform.transform9  s    UWu::---WDH0WW#e**WWW   uQx==AHV$$EE2DH2E:E> 	 $$B$KE!r6   c                 8    t          | j        | j                  S z6
        Return the inverse of the transform.
        r>   )r   r<   r?   r   s    r4   invertedz WCSWorld2PixelTransform.invertedP       'tx4>JJJJr6   F)__name__
__module____qualname____doc__has_inverser   r   r   propertyr   rt   transform_non_affiner   __classcell__r   s   @r4   r   r     s          KH	7 	7 	7 	7 	7 	7
 
 
 $ $ X$  * %K K K K K K Kr6   r   c                   T     e Zd ZdZdZd	 fd	Zd Zed             Zd Z	e	Z
d Z xZS )
r   z=
    WCS transformation from pixel to world coordinates.
    TFc                     t                                                       |j        dk    rt          d          || _        || _        t          |          | _        d S r   )r   r   rG   rH   r<   r?   r   	frame_outr   s      r4   r   z WCSPixel2WorldTransform.__init__^  sV    ?QABBB"2377r6   c                 x    t          |t          |                     o| j        |j        u o| j        |j        k    S r   r   r   s     r4   r   zWCSPixel2WorldTransform.__eq__i  r   r6   c                     | j         j        S r   r   r   s    r4   output_dimsz#WCSPixel2WorldTransform.output_dimsp  r   r6   c                    t          |j                  }t          |          | j        j        k    r-t          d| j        j         dt          |           d          | j        r|d d d         }t          |d                   dk    r!t          j        d| j        j	        f          }n | j        j
        | }| j        j	        dk    r|g}t          j        |          j        }|S )Nr   r   r   rA   r   r
   )r1   r   rI   r<   rG   rH   r?   r`   r   rM   pixel_to_world_valuesr   )r   r   r   s      r4   rt   z!WCSPixel2WorldTransform.transformt  s    UWu::---WDH0WW#e**WWW   > 	 $$B$KEuQx==AHa!5677EE2DH2E:E81$$GE!r6   c                 8    t          | j        | j                  S r   )r   r<   r?   r   s    r4   r   z WCSPixel2WorldTransform.inverted  r   r6   r   )r   r   r   r   r   r   r   r   r   rt   r   r   r   r   s   @r4   r   r   W  s          K	8 	8 	8 	8 	8 	8
 
 
 $ $ X$  0 %K K K K K K Kr6   r   r   )!numpyr`   astropyr   rO   astropy.coordinatesr   r   r   astropy.wcsr   astropy.wcs.utilsr   astropy.wcs.wcsapir	   r   r   r   r   
transformsr   __all__IDENTITYr<   rW   crvalcrpixcdeltr   r]   r   r   r   r8   r6   r4   <module>r      s             C C C C C C C C C C       = = = = = = 0 0 0 0 0 0 H H H H H H H H H H ' ' ' ' ' '   3Q<<<3Z 3Z 3Z 3Z Y! Y! Y! Y!x/ / /8! ! !9K 9K 9K 9K 9Ko 9K 9K 9Kx;K ;K ;K ;K ;Ko ;K ;K ;K ;K ;Kr6   