
    HR-en                        d dl mZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ g dZ G d d	e          Z ed
d           edd           edd           edd           edd           edd           edd           edd           edd           edd           edd           edd           d!Ze                                ad"Ze	 d,d$eeef         d%ed&dfd'            Z G d( d)e
          Z G d* d+e          ZdS )-    )contextmanager)Dict
NamedTupleN)unbroadcast)	MixinInfo)ShapedLikeNDArray)StokesCoordcustom_stokes_symbol_mappingStokesSymbolc                   0    e Zd ZU dZdZeed<   dZeed<   dS )r   zSymbol for a Stokes coordinate. symboldescriptionN)__name__
__module____qualname____doc__r   str__annotations__r        @lib/python3.11/site-packages/astropy/coordinates/polarization.pyr   r      s8         ))FCKr   r   IzStandard Stokes unpolarizedQzStandard Stokes linearUVzStandard Stokes circularRRzRight-right circular: <RR*>LLzLeft-left circular: <LL*>RLz%Right-left cross-circular: Re(<RL*>))LRz.Left-right cross-circular: Re(<LR*>)=Im(<RL*>)XXzX parallel linear: <XX*>YYzY parallel linear: <YY*>XYzXY cross linear: Re(<XY*>)YXzYX cross linear: Im(<XY*>))            iiiiayFmappingreplacereturnc              #   ^   K   t                                           }|si || a n| a dV  |a dS )a  
    Add a custom set of mappings from values to Stokes symbols.

    Parameters
    ----------
    mappings
        A list of dictionaries with custom mappings between values (integers)
        and `.StokesSymbol` classes.
    replace
        Replace all mappings with this one.
    N)STOKES_VALUE_SYMBOL_MAPcopy)r.   r/   original_mappings      r   r
   r
   (   sQ      " /3355 *"A%5"A"A")	EEE.r   c                   l    e Zd ZdhZdZdZed             Zed             Ze	d             Z
d
dZd	 ZdS )StokesCoordInfovaluer7   c                     d S Nr   selfs    r   unitzStokesCoordInfo.unitN   s    tr   c                 $    | j         j        j        S r:   )_parent_datadtyper;   s    r   rA   zStokesCoordInfo.dtypeR   s    |!''r   c                     | j          S r:   r   )vals    r   default_formatzStokesCoordInfo.default_formatV   s    *r   warnNc                 `   |                      |||d          }|f|                    d          z   }t          j        ||                    d                    }|                     t          |                    }|                                D ]\  }	}
t          |j        |	|
           |S )a  
        Return a new StokesCoord instance which is consistent with the
        input ``cols`` and has ``length`` rows.

        This is intended for creating an empty column object whose elements can
        be set in-place for table operations like join or vstack.

        Parameters
        ----------
        cols : list
            List of input columns
        length : int
            Length of the output column object
        metadata_conflicts : str ('warn'|'error'|'silent')
            How to handle metadata conflicts
        name : str
            Output column name

        Returns
        -------
        col : `~astropy.coordinates.StokesCoord` (or subclass)
            Empty instance of this class consistent with ``cols``

        )metaformatr   shaperA   )rJ   rA   r8   )	merge_cols_attributespopnpzeros_construct_from_dictdictitemssetattrinfo)r<   colslengthmetadata_conflictsnameattrsrJ   dataoutattrr7   s              r   new_likezStokesCoordInfo.new_likeZ   s    4 **$d,M
 

 	EIIg...xe599W+=+=>>>''4(8(8(899 !;;== 	+ 	+KD%CHdE****
r   c                     | j         j        gS )z
        Return a list of arrays which can be lexically sorted to represent
        the order of the parent column.

        For StokesCoord this is just the underlying values.

        Returns
        -------
        arrays : list of ndarray
        )r?   r@   r;   s    r   get_sortable_arraysz#StokesCoordInfo.get_sortable_arrays   s     "##r   )rF   N)r   r   r   _represent_as_dict_attrs_represent_as_dict_primary_data_construct_from_dict_argspropertyr=   rA   staticmethodrE   r\   r^   r   r   r   r6   r6   D   s         'y '.# !+  X ( ( X(   \( ( ( (T$ $ $ $ $r   r6   c                       e Zd ZdZ e            ZddZed             Zed             Z	ed             Z
ddZd	 Zed
             Zed             Zd Zd Zd Zd ZdS )r	   z
    A representation of stokes coordinates with helpers for converting to profile names.

    Parameters
    ----------
    stokes : array-like
        The numeric values representing stokes coordinates.
    Fc                    t          |t          |                     r/|r|j                                        n|j        }|j        | _        nwt          j        |          }|j        j        dk    rd}t          |          |j        j        dk    r| 
                    |          }n|r||u r|                                n|}|| _        d S )NOz?StokesCoord objects cannot be initialised with an object array.r   )
isinstancetyper@   r3   rS   rM   
asanyarrayrA   kind
ValueError_from_symbols)r<   stokesr3   rY   msgs        r   __init__zStokesCoord.__init__   s    fd4jj)) 	H*.@6<$$&&&FLDDII=((Dz#%%W oo%z#%%))$//&*Gtv~~tyy{{{4


r   c                     | j         j        S r:   )r@   rJ   r;   s    r   rJ   zStokesCoord.shape       zr   c                     | j         S r:   )r@   r;   s    r   r7   zStokesCoord.value   s
    zr   c                     | j         j        S r:   )r@   rA   r;   s    r   rA   zStokesCoord.dtype   rq   r   Nc                 :    | j                             |d          S )NF)r3   )r@   astype)r<   rA   s     r   	__array__zStokesCoord.__array__   s    z  U 333r   c                     t          |           }t          |          r | || j        g|R i |          }n$ | t          | j        |          |i |          }d| j        v r| j        |_        |S )NrS   )rh   callabler@   getattr__dict__rS   )r<   methodargskwargsclsnews         r   _applyzStokesCoord._apply   s    4jjF 	D#ffTZ9$999&99::CC#1gdj&114B6BBCCC
 T]""yCH
r   c                 T   t          j        | t          t          d          }t                                          D ]\  }}||| |j        k    <   t          j        |t                    x}                                r*t          dt          j
        | |                              |S )zC
        Convert an array of symbols to an array of values
        F)rA   subokz3Unknown stokes symbols present in the input array: )rM   	full_likeUNKNOWN_STOKES_VALUEintr2   rQ   r   equalanyrk   unique)symbolsvalues_arraystokes_valuer   unknown_valuess        r   rl   zStokesCoord._from_symbols   s    
 |)E
 
 
 %<$A$A$C$C 	B 	B L&5ALFM122 h|5IJJJNOOQQ 	jbiPWXfPgFhFhjj   r   c                    t          dgd t                                          D             z             }t          j        d |D                       }t          j        t          | j                            }t          j        |j	        dd|           }t          
                                D ]\  }}|j        |||k    <   t          j        || j	                  S )z&The coordinate represented as strings.?c                     g | ]	}|j         
S r   rC   .0ss     r   
<listcomp>z&StokesCoord.symbol.<locals>.<listcomp>   s    HHH!QXHHHr   c                 ,    g | ]}t          |          S r   )lenr   s     r   r   z&StokesCoord.symbol.<locals>.<listcomp>   s    888Q#a&&888r   z<U)rA   )tupler2   valuesrM   maxroundr   r7   fullrJ   rQ   r   broadcast_to)r<   known_symbolsmax_lenunbroadcasted	symbolarrr7   r   s          r   r   zStokesCoord.symbol   s     EHH'>'E'E'G'GHHHH
 
 &88-88899 TZ!8!899GM/NNNKKK	4::<< 	> 	>ME606Imu,--y$*555r   c                 P     t          |           |          j        | j        |<   d S r:   )rh   r@   )r<   itemr7   s      r   __setitem__zStokesCoord.__setitem__   s'    %4::e,,2
4r   c                 ~    	 |                      |          }n# t          $ r
 t          cY S w xY w| j        |j        k    S r:   )	__class__	ExceptionNotImplementedr@   )r<   others     r   __eq__zStokesCoord.__eq__   sR    	"NN5))EE 	" 	" 	"!!!!	" zU[((s    ,,c                 n    t          j        | j        dd          }t          |           j         d| dS )Nz, z  )	separatorprefix())rM   array2stringr   rh   r   )r<   arrstrs     r   __str__zStokesCoord.__str__   s:    TJJJt**%111111r   c                 *    |                                  S r:   )r   r;   s    r   __repr__zStokesCoord.__repr__   s    ||~~r   Fr:   )r   r   r   r   r6   rS   ro   rb   rJ   r7   rA   rv   r   rc   rl   r   r   r   r   r   r   r   r   r	   r	      s'         ?D   "     X    X     X 4 4 4 4      \" 6 6 X6 3 3 3) ) )2 2 2    r   r	   r   )
contextlibr   typingr   r   numpyrM   astropy.utilsr   astropy.utils.data_infor   astropy.utils.shapesr   __all__r   FITS_STOKES_VALUE_SYMBOL_MAPr3   r2   r   r   boolr
   r6   r	   r   r   r   <module>r      sK   % % % % % % # # # # # # # #     % % % % % % - - - - - - 2 2 2 2 2 2
I
I
I    :    |C677|C122|C122|C344T899T677TBCCTKLLT566T566T788T788     7;;==   6;/ /#|#$//3/	/ / / /6K$ K$ K$ K$ K$i K$ K$ K$\o o o o o# o o o o or   