CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
maxwell.cpython-310.pyc905 linesDownload Raw Back to __pycache__
1o

2'�Yi#��@svddlmZddlmZddlmZddlmZddl	m3Z4ddlZddl
mZddlmZd	d5lmZd	dlmZd	dlmZmZd	d
lmZmZd	dlmZmZd	dlmZd	dl m!Z!d	dl"m#Z#m$Z$d	dl%m&Z&m'Z'd	dl(m)Z)m*Z*m+Z+d	dl,m-Z-d	dl.m/Z/d	dl0m1Z1m2Z2d	dl3m4Z4m5Z5m6Z6d	dl7m8Z8m9Z9m:Z:d	dl;m<Z<m=Z=d	dl>m?Z?d	dl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOd	dlPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[eZdddddd �d!d"��Z\eZ	#	$	%				&	'		(		)		*		+	,	-	*	.	d�d/d0��Z]eZ	#	$	%				&	'		(		)		*		+	,	-	(	*	.	d�d1d2��Z^dd(d*d3�d4d5�Z_Gd6d7�d7�Z`d8d9�Zad:d;�Zbd<d=�Zcd>d?�Zdd@dA�ZeeZd�dBddC�dDdE��ZfdFdG�ZgdHdI�ZhdJdK�ZidLdM�ZjdNdO�ZkdPdQ�ZleZ	d�dRdS��ZmeZd�dTdU��ZndVdW�ZodXdY�ZpdZd[�Zqd\d]�Zrd^d_�Zsd`da�ZtdbejuZvdcdd�Zwd�dfdg�Zxdhdi�Zydjdk�Zzdldm�Z{dndo�Z|dpdq�Z}drds�Z~dtdu�Zdvdw�Z�d�dxdy�Z�dzd{�Z�d|d}�Z�e�dd~�Z�dd��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d�d��Z�eZ	�	�	�		#	$	%			'	(		)		+	,	�	-	.	d�d�d���Z�d�d��Z�eZ	#	$	%		'	(	*	)	+	-	d�d�d���Z�dS)��)�Counter)�partial)�	factorial)�path)�PathN)�linalg)�lpmv�)�__version__)�make_compensator)�FIFF�FWD)�Info�_simplify_info)�	pick_info�6pick_types)�	_read_ctc)�7Projection)�_coil_trans_to_loc�_loc_to_coil_trans)�	DATE_NONE�_generate_meas_id)�_COLA�_Interp2�_Storer)�_annotations_starts_stops)�
_check_origin)�_get_T1T2_mag_inds�fix_mag_coil_types)�	_safe_svd�bincount�8sph_harm_y)�_concatenate_coils�_create_meg_coils�_prep_meg_channels)�BaseRaw�RawArray)�_normalize_vectors)�	Transform�_average_quats�_cart_to_sph�_deg_ord_idx�_find_vector_rotation�_get_n_moments�9_get_trans�_sh_complex_to_real�10_sh_negate�_sh_real_to_complex�_sph_to_cart_partials�
_str_to_frame�apply_trans�quat_to_rot�rot_to_quat)�
_check_option�_clean_names�_ensure_int�_pl�11_time_mask�_validate_type�_verbose_safe_false�logger�
use_log_level�verbose�warn�from_raw�keepF)�bads�annotations�	meas_date�emit_warningr@c	s�t|tdd�t|tdd�t|tdd�td|gd�d�t|tdd�td|gd�d�t|tdd�td|d	d12gd�|���~|d	krM|jd}n|dkr`tt|jd�jd��}n	|d13kri�jd}�fdd
�t�jdgd�D���fdd
�|D�}|�jd<|jd�jd<|�	�}��14|��jj|j
�j
7_��|j
����_|d15kr�j}|d	kr�|�t�t|���|�|jj|jj|jj|jj��jddur�|j�j
8_��||�|d	kr��|jd��S)a�Prepare an empty-room recording for Maxwell filtering.16 17    Empty-room data by default lacks certain properties that are required to18    ensure running :func:`~mne.preprocessing.maxwell_filter` will process the19    empty-room recording the same way as the experimental data. This function20    preconditions an empty-room raw data instance accordingly so it can be used21    for Maxwell filtering. Please see the ``Notes`` section for details.22 23    Parameters24    ----------25    raw_er : instance of Raw26        The empty-room recording. It will not be modified.27    raw : instance of Raw28        The experimental recording, typically this will be the reference run29        used for Maxwell filtering.30    bads : 'from_raw' | 'union' | 'keep'31        How to populate the list of bad channel names to be injected into32        the empty-room recording. If ``'from_raw'`` (default) the list of bad33        channels will be overwritten with that of ``raw``. If ``'union'``, will34        use the union of bad channels in ``raw`` and ``raw_er``. Note that35        this may lead to additional bad channels in the empty-room in36        comparison to the experimental recording. If ``'keep'``, don't alter37        the existing list of bad channels.38 39        .. note::40           Non-MEG channels are silently dropped from the list of bads.41    annotations : 'from_raw' | 'union' | 'keep'42        Whether to copy the annotations over from ``raw`` (default),43        use the union of the annotations, or to keep them unchanged.44    meas_date : 'keep' | 'from_raw'45        Whether to transfer the measurement date from ``raw`` or to keep46        it as is (default). If you intend to manually transfer annotations47        from ``raw`` **after** running this function, you should set this to48        ``'from_raw'``.49    %(emit_warning)s50        Unlike :meth:`raw.set_annotations <mne.io.Raw.set_annotations>`, the51        default here is ``False``, as empty-room recordings are often shorter52        than raw.53    %(verbose)s54 55    Returns56    -------57    raw_er_prepared : instance of Raw58        A copy of the passed empty-room recording, ready for Maxwell filtering.59 60    Notes61    -----62    This function will:63 64    * Compile the list of bad channels according to the ``bads`` parameter.65    * Inject the device-to-head transformation matrix from the experimental66      recording into the empty-room recording.67    * Set the following properties of the empty-room recording to match the68      experimental recording:69 70      * Montage (required for the fiducials defining the head coordinate frame)71      * ``raw.first_time`` and ``raw.first_samp``72 73    * Adjust annotations according to the ``annotations`` parameter.74    * Adjust the measurement date according to the ``meas_date`` parameter.75 76    .. note::77 78        Note that in case of dual MEG/EEG acquisition, EEG channels should not be79        included in the empty room recording. If provided, they will be ignored.80 81    .. versionadded:: 1.182    �raw_er)�item�typesZ	item_name�rawrD)rB�unionrC)Z	parameter�valueZallowed_valuesrErFrBrCrLc�g|]}�j|�qS���ch_names��.0�pick)�raw_er_preparedrO��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/preprocessing/maxwell.py�83<listcomp>�s��z4maxwell_filter_prepare_emptyroom.<locals>.<listcomp>T��meg�excludecsg|]}|�vr|�qSrOrO)rS�ch_name)�meg_ch_namesrOrVrW���84dev_head_tN)r<r%�strr7�copy�info�sorted�setrZget_montageZset_montagerE�onsetZ85first_time�
time_as_indexrIZ
_cropped_samp�delete�np�arange�len�append�duration�descriptionrQZset_annotationsZ
set_meas_date)	rHrKrDrErFrGr@ZmontageZer_annotrO)r\rUrV� maxwell_filter_prepare_emptyroomDsdO86��87�8889�9091�rm�auto���\���(\�?�head�in�errorT�Y@��edgeZbad_acq_skiprO�hanncCs�t�d�tdid|�d|�d|�d|�d|�d|�d|�d	|�d92|�d|	�d|93�d
|�d|�d|
�d|�d|�d|�d|�d|�d|�d|��}t|fi|��}t|fi|d��t�d�|S)u�"Maxwell filter data using multipole moments.94 95    Parameters96    ----------97    raw : instance of Raw98        Data to be filtered.99 100        .. warning:: It is critical to mark bad channels in101                     ``raw.info['bads']`` prior to processing in order to102                     prevent artifact spreading. Manual inspection and use103                     of :func:`~find_bad_channels_maxwell` is recommended.104    %(origin_maxwell)s105    %(int_order_maxwell)s106    %(ext_order_maxwell)s107    %(calibration_maxwell_cal)s108    %(cross_talk_maxwell)s109    st_duration : float | None110        If not None, apply spatiotemporal SSS with specified buffer duration111        (in seconds). MaxFilter™'s default is 10.0 seconds in v2.2.112        Spatiotemporal SSS acts as implicitly as a high-pass filter where the113        cut-off frequency is 1/st_duration Hz. For this (and other) reasons,114        longer buffers are generally better as long as your system can handle115        the higher memory usage. To ensure that each window is processed116        identically, choose a buffer length that divides evenly into your data.117        Any data at the trailing edge that doesn't fit evenly into a whole118        buffer window will be lumped into the previous buffer.119    st_correlation : float120        Correlation limit between inner and outer subspaces used to reject121        overlapping intersecting inner/outer signals during spatiotemporal SSS.122    %(coord_frame_maxwell)s123    %(destination_maxwell_dest)s124    %(regularize_maxwell_reg)s125    %(ignore_ref_maxwell)s126    %(bad_condition_maxwell_cond)s127    %(head_pos_maxwell)s128 129        .. versionadded:: 0.12130    %(st_fixed_maxwell_only)s131    %(mag_scale_maxwell)s132 133        .. versionadded:: 0.13134    %(skip_by_annotation_maxwell)s135 136        .. versionadded:: 0.17137    %(extended_proj_maxwell)s138    st_overlap : bool139        If True (default in 1.11), tSSS processing will use a constant140        overlap-add method. If False, then non-overlapping windows will be used.141 142        .. versionadded:: 1.10143    %(maxwell_mc_interp)s144    %(verbose)s145 146    Returns147    -------148    raw_sss : instance of Raw149        The raw data with Maxwell filtering applied.150 151    See Also152    --------153    mne.preprocessing.annotate_amplitude154    mne.preprocessing.find_bad_channels_maxwell155    mne.chpi.filter_chpi156    mne.chpi.read_head_pos157    mne.epochs.average_movements158 159    Notes160    -----161    .. versionadded:: 0.11162 163    Some of this code was adapted and relicensed (with BSD form) with164    permission from Jussi Nurminen. These algorithms are based on work165    from :footcite:`TauluKajola2005` and :footcite:`TauluSimola2006`.166    It will likely use multiple CPU cores, see the :ref:`FAQ <faq_cpu>`167    for more information.168 169    .. warning:: Maxwell filtering in MNE is not designed or certified170                 for clinical use.171 172    Compared to the MEGIN MaxFilter™ 2.2.11 software, the MNE Maxwell filtering173    routines currently provide the following features:174 175    .. table::176       :widths: auto177 178       +-----------------------------------------------------------------------------+-----+-----------+179       | Feature                                                                     | MNE | MaxFilter |180       +=============================================================================+=====+===========+181       | Maxwell filtering software shielding                                        | ✓   | ✓         |182       +-----------------------------------------------------------------------------+-----+-----------+183       | Bad channel reconstruction                                                  | ✓   | ✓         |184       +-----------------------------------------------------------------------------+-----+-----------+185       | Cross-talk cancellation                                                     | ✓   | ✓         |186       +-----------------------------------------------------------------------------+-----+-----------+187       | Fine calibration correction (1D)                                            | ✓   | ✓         |188       +-----------------------------------------------------------------------------+-----+-----------+189       | Fine calibration correction (3D)                                            | ✓   |           |190       +-----------------------------------------------------------------------------+-----+-----------+191       | Spatio-temporal SSS (tSSS)                                                  | ✓   | ✓         |192       +-----------------------------------------------------------------------------+-----+-----------+193       | Coordinate frame translation                                                | ✓   | ✓         |194       +-----------------------------------------------------------------------------+-----+-----------+195       | Regularization using information theory                                     | ✓   | ✓         |196       +-----------------------------------------------------------------------------+-----+-----------+197       | Movement compensation (raw)                                                 | ✓   | ✓         |198       +-----------------------------------------------------------------------------+-----+-----------+199       | Movement compensation (:func:`epochs <mne.epochs.average_movements>`)       | ✓   |           |200       +-----------------------------------------------------------------------------+-----+-----------+201       | :func:`cHPI subtraction <mne.chpi.filter_chpi>`                             | ✓   | ✓         |202       +-----------------------------------------------------------------------------+-----+-----------+203       | Double floating point precision                                             | ✓   |           |204       +-----------------------------------------------------------------------------+-----+-----------+205       | Seamless processing of split (``-1.fif``) and concatenated files            | ✓   |           |206       +-----------------------------------------------------------------------------+-----+-----------+207       | Automatic bad channel detection (:func:`~find_bad_channels_maxwell`)        | ✓   | ✓         |208       +-----------------------------------------------------------------------------+-----+-----------+209       | Head position estimation (:func:`~mne.chpi.compute_head_pos`)               | ✓   | ✓         |210       +-----------------------------------------------------------------------------+-----+-----------+211       | Overlap-add processing for spatio-temporal projections                      | ✓   |           |212       +-----------------------------------------------------------------------------+-----+-----------+213       | Smooth interpolation in movement compensation                               | ✓   |           |214       +-----------------------------------------------------------------------------+-----+-----------+215       | Certified for clinical use                                                  |     | ✓         |216       +-----------------------------------------------------------------------------+-----+-----------+217       | Extended external basis (eSSS)                                              | ✓   |           |218       +-----------------------------------------------------------------------------+-----+-----------+219 220    Epoch-based movement compensation is described in :footcite:`TauluKajola2005`.221 222    Use of Maxwell filtering routines with non-Neuromag systems is currently223    **experimental**. Worse results for non-Neuromag systems are expected due224    to (at least):225 226    * Missing fine-calibration and cross-talk cancellation data for227      other systems.228    * Processing with reference sensors has not been vetted.229    * Regularization of components may not work well for all systems.230    * Coil integration has not been optimized using Abramowitz/Stegun231      definitions.232 233    .. note:: Various Maxwell filtering algorithm components are covered by234              patents owned by MEGIN. These patents include, but may not be235              limited to:236 237              - US2006031038 (Signal Space Separation)238              - US6876196 (Head position determination)239              - WO2005067789 (DC fields)240              - WO2005078467 (MaxShield)241              - WO2006114473 (Temporal Signal Space Separation)242 243              These patents likely preclude the use of Maxwell filtering code244              in commercial applications. Consult a lawyer if necessary.245 246    Currently, in order to perform Maxwell filtering, the raw data must not247    have any projectors applied. During Maxwell filtering, the spatial248    structure of the data is modified, so projectors are discarded (unless249    in ``st_only=True`` mode).250 251    References252    ----------253    .. footbibliography::254    zMaxwell filtering raw datarK�origin�	int_order�	ext_order�calibration�255cross_talk�st_duration�st_correlation�coord_frame�destination�256regularize�257ignore_ref�
bad_condition�head_pos�st_fixed�st_only�	mag_scale�skip_by_annotation�
extended_proj�258st_overlap�	mc_interp�
update_kwargs�[done]NrO)r>ra�_prep_maxwell_filter�_run_maxwell_filter�_update_sss_info)rKryrzr{r|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r@�params�raw_sssrOrOrV�maxwell_filter�sb259<��������	�260���
���������261r�c;s�t|td�t||�t|262�t|�}|dks|dkr"td|����td|ddg�t|	|j|�}|durZt|�}t|�}t	t263||jd��}d|krUd	ksZtd264��td265��td|gd��|jd
durq|dkrqtd��|r{|dur{td��|
dur�|r�d}|
duo�|}t|
|||�}
t
|
||||�}t|j||du|o�|du|o�|dud�|j���t�|||�\}}}}}t||||��\}}t|ttfd��fdd�||D�} t|�dk�rAt�}!t|�D]G\}"}#d|"�d�}$t|#t|$�|#dd�tt| �t���}%|%�rt|$�dd�|%������fdd�| D�}&|!�|#dddd�|&f�q�t�|!�}t�dt|��t�}'|du�r[���}(t�||�\}}'|� d�n�}(t!|�|dd�}|dk�ry�d
du�ryt"�d
|�})n|})t|||'|||d �}*~~~'|)j#d!d"��fd#d�|D�}+t$||+�\},}-|-|*d$<~-t|)|dd%�}.t%�|�}/t%|(|�}0t&|.|0||�}1||.d&<||.d<~|du�rd'�d
d(dd)�d)f|d(dd)�d)f}2t�'t�(t)|2���}3|3d*k�rt*d+d�d,d-�|2D���d.|3d/�d0��t�}4|du�r4|�rt+j,}5nt+j-}5|4j.|5||�dd1�t�d2|4d3���|�r1d4nd5}6nt/t0t	t266d6�d��d	�t|j1��}d}d7}6|4|*d8<~4�d
du�r�|
ddu�r�t�t2�d
d(dd)�dd)�f��d
d(dd)�d)ft�3d)�g�}7nd}7t4||�}8|8du�r�|8|1}1|1|}1t5t6|/||267|.|||||||||8d9�}9|*j.|�(�||d:�tdPid;|�d<|�d=|�d>|�d?|6�d@|,�dA|�dB|7�dC|�dD|�dE|�dF|
�dG��dH|9�dI|1�dJ|*�dK|�dL|�dM|�dN|�dO|��}:|:S)QNrK���?z#Need 0 < st_correlation <= 1., got r�rrrY�sfreq�z(st_correlation must be between 0. and 1.r�)rt�warning�ignorerar^z�coord_frame cannot be "head" because info["dev_head_t"] is None; if this is an empty room recording, consider using coord_frame="meg"z/st_duration must not be None if st_only is True�zero)�sss�tsssr|�ctcr�c�g|]}�d|�qSrPrO�rS�c�rarOrVrWr]z(_prep_maxwell_filter.<locals>.<listcomp>rzextended_proj[�]�data�	col_namesz9 channel names were missing some good MEG channel names:268z, c�g|]}��|��qSrO��index�rS�name)�	got_namesrOrVrW�z<    Extending external SSS basis using %d projection vectorsT)Zdisp)ryr��sss_calrzr{r�F)�writecr�rPrO�rS�pr�rOrVrWBr]�sss_ctc)ryrzr{r{���transrpg9@z$Head position change is over 25 mm (css�|]}|d�VqdS)�0.1fNrO)rS�xrOrOrV�	<genexpr>Y��z'_prep_maxwell_filter.<locals>.<genexpr>z) = r�� mm)�jobZ	subspcorr�buflenz0    Processing data using tSSS with st_duration=r��before�afterg$@�never�max_st)
�	all_coils�calr��expr��269coil_scale�270grad_picks�	mag_picks�	good_mask�mag_or_finer�r��mult)�nchanr��recon_transr�r~rr��st_whenr�r��
this_pos_quat�	meg_picksr�r�r�ra�_get_this_decomp_trans�S_reconr�r��add_channelsr�r��mcrO)7r<r%�
_check_usable�_check_regularize�float�271ValueErrorr7�_check_destinationra�int�round�RuntimeError�272_check_pos�	_MoveComp�_check_infor`�_get_mf_picks_fix_mags�_get_coil_scale�list�tupleri�	enumeraterrbrc�joinrjrg�concatenater>�dict�_update_sensor_geometry�fillrr4Zsetflags�_read_cross_talk�_prep_mf_coils�_trans_sss_basis�sqrt�sum�_sqrArZFIFFV_SSS_JOB_TPROJZFIFFV_SSS_JOB_ST�update�min�max�timesr6�zeros�_get_sensor_operatorr�_get_decomp);rKryrzr{r|r}r~rr�r�r�r�r�r�r�r�r�r�r��reconstructr�r�r@r�r�r�r�r�r�r�r�r�Z273good_namesZextended_proj_�pi�projrI�missing�idxr�Z274info_reconZorigin_headr�r\r�r�r�r�Zall_coils_reconr��diff�distr�r�r�r�r�r�r�rO)r�rarVr��s�"275�276���277	�278��� 279�280�2812822830284���285��&��286287�288���������	�289���
���������r�)r�r�r`c2CsR|dur||290dd�|291f}|o|}t||||
�\}}|
d}~|s't||�|r0|s0|	|292}n|	}t||dd�\}}||��}d|krM|dksYntd||d�d���|�||
d	|�|j|jd293�t||�D�]7\}} | |}!|!dks}J�|!|k}"|r�|"r�|dur�|d}#d
}$nd}#d}$|r�|dur�t	t294|d�}%nt}%tt	|%||"|d�t
|jdd�|| �f|d�|!t||!�|#||$dd�}&tt|j|jd��}'tt|| |'��| g}(t|(�dks�J�|(d|kr�|(d| ks�J�t|(dd�|(dd��D]L\})}*|)|*k�r	q�|j|	|295|)|*�f}+|du�r|�|+�}+|�r@|du�r@|�r3|j|	|)|*�f},n|+},|&j|,|+|
dd�q�|+|j|	|296|)|*�f<q�t|(dd�|(dd��D]L\})}*|�|j|	|)|*�f|297|�\}-}.}/}0}1|-|j|	|)|*�f<t|�dk�r�|0|j||)|*�f<|�s�|du�r�|&j|j|	|)|*�f|.|/|1|
dd��qYqn|S)Nr�T��invertr�r�z
st_duration (r�zas) must be between 0 and the longest contiguous duration of the data ({max_samps / sfreq:0.1f}s).r^)�reg_momentsrr	rxZboxcar)r�)r�298tsss_validr�)Zpicksz	tSSS-COLA)r������r�)r�)�n_positionsr�)�_copy_preload_add_channels�_remove_meg_projs_compsrr�r��299initializer��
reg_moments_0�zipr�_do_tSSS_on_avg_trans�_do_tSSSrr�_datar�r�r�Zbuffer_size_secrar��rangeri�dot�feed)2rKr�r~rr�r�r�r�r�r�r�r�r�rar�r�r�r�r�r`r�r�r�r�r��	pos_picksr��these_picks�onsets�endsZ	max_sampsrd�end�nr�Z	n_overlapZwindowZfunr�Zuse_nZ	read_lims�start�stopZctc_data�procr��orig_in_data�resid�pos_datar�rOrOrVr��s� 300301���"302303304�"����r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd305d�ZdS)
r�zPerform movement compensation.cCs.||_|jd|_||_|dvsJ�||_dS)Nr�)�origrs)�posrar��interpr�)�selfr�306head_framerKrr�rOrOrV�__init__Hs307308z_MoveComp.__init__cCst�|jd|k�dd}|jd|}||j}|j||d�\}}}}}	|jj|d|	�dd�}309|jdkr>t�||�}n|jdksEJ�t�|310|d|	��}|j	d|j311ksYJ�t�|dd�d|	�f|d|	��}t�|j	d�|}
|
t�|dd�|	d�f||	d��8}
|||
fS)Nr�r��t�Zaxisrrs)rg�whererr��312get_decompr��taker�r	�shape�n_good�eye)r�offsetr�r^r�S_decomp�
S_decomp_full�	pS_decompr��n_use_inZS_recon_regZop_sss�op_in�op_residrOrOrV�get_decomp_by_offsetOs 313�314$(315z_MoveComp.get_decomp_by_offsetcCsht|jd|j|jdd�|_||dd�\}}}|_}|jd|_||_d|_	||_316tjt�
d�|_dS)	zSecondary initialization.r�ZMC)rr�r�rr�N)rrr-r�smoothrr#r$r�r&r!rg�nan�ones�
last_avg_quat)rr!r^r��_r)rOrOrVrbs�z_MoveComp.initializec317Cst|j||�dd�\}}tj||jdd�sy||_t�t�t|dd��|dd�dd�tjfg�gd�gg�}|j	|||j318d�\}}}}}	t�|dd�d|	�f|d|	��|_t�
t|j��|jt�|dd�|	d�f||	d��|_|j|j|fS)z7Apply an average transformation over the next interval.r�NgH�����z>)Zatolrp)r�r�r�r�r)�_trans_limsrrgZallcloser2ZvstackZhstackr5�newaxisr!r�r	Z	op_in_avgr%riZop_resid_avg)319rrrr��avg_quatZ	avg_transZS_decomp_str3ZpS_decomp_stZn_use_in_strOrOrV�320get_avg_oprs*.��321���"��z_MoveComp.get_avg_opc	Cs|jd}t|j|j|j|jd�dd�\}}|j|jd7_d}}|j�|�D]�\}	}322}}|||	f}
|323\}}}|jd|
jdksJJ�|durht�|jd|jdf�}t�|jd|jdf�}|durpd|nd}|s�t�||
�|dd�|	f<|dur�|dd�|	f|9<|dd�|	f|t�|d|
�7<t�||
�|dd�|	f<t�||
�|dd�|	f<|du�r|dd�|	f|9<|dd�|	f|9<|dd�|	f|t�|d|
�7<|dd�|	f|t�|d|
�7<q-|||||fS)Nr�r�r	rr�)	r#r4rr&r/Zfeed_generatorrg�emptyr	)rr�r�r�Zn_samprZn_posZin_dataZ324resid_data�sl�left�rightZl_interpZ	good_dataZl_sssZl_inZl_residZr_interprOrOrVr325�s<326��327(328((�z_MoveComp.feedN)	�__name__�329__module__�__qualname__�__doc__rr-rr7r330rOrOrOrVr�Esr�c
Cs�tjt�|d||g��}t�||t�}t�d||f�}t|�}tdt|��D]�}|dkrbd}t|�dkr?|d|dn|}	|	|}	||	krJq)|dtt|�rX|ddndd�}331|d7}n+|d|||}|t|�dkry||}	n|d||d|}	|d||}332|333dd�tj	f|dd�||	�f<d|ks�J�||	ks�J�|	||ks�J�|||	��334�r�J�d|||	�<q)|��s�J�t�|�}t
|dd�j�}tj|dd	�dd335�}t�||g�}|||fS)z!Get all trans and limits we need.r��	r�rr	NTrpr.r)rgrh�searchsortedr��boolr8rirr�r5�any�all�arrayr)�T�meanr�)
rrrZpos_idx�usedZquatsr��tiZ	rel_startZrel_stopZ	this_quatr6Zavg_trOrOrVr4�s< &336337"338339r4cst|t�rn|dkrtd|�d���t|�dt|�fvr(d}t�d|d�d��nFt�fd	d340�|D�d���fdd
�|D�}t|�dksKt|�ddkrTtdt|�����t|�d}d|}t�d|d�dd|d�d��t	|�}t341�t|�df�}|||<||fS)z"Get the magnetometer scale factor.rnz*mag_scale must be a float or "auto", got "�"rruz    Setting mag_scale=z0.2fz& because only one coil type is presentcr�)�chsrOrRr�rOrVrW�r]z#_get_coil_scale.<locals>.<listcomp>�accuratecsh|]}�|d�qS)�baserOrR��coilsrOrV�	<setcomp>�r]z"_get_coil_scale.<locals>.<setcomp>r�zbCould not automatically determine mag_scale, could not find one proper gradiometer distance from: r�z based on gradiometer distance r�r�)�342isinstancer_r�rir>rar#r�r�r�rgr1)r�r�r�r�raZ	grad_baser�rO)rOrarVr��s:343����344��r�cCsv|j}|dvr7t|jd|�}t�d|���|jd|jdkr*t|j�ks-J�J�|t�||�}|Sd}|S)N�rNrz&    Accounting for compensation grade r�)	�compensation_graderrar>r#rirQrgZix_)rKr��compr�rOrOrVr��s.�r�cs�t�jdgd�}�fdd�|D��t�}�jdD]}t�fdd�|dd	D��s/|�|�q�j|dd345d�|rc�jdre�jd
vsFJ��j���g�jd<Wd�dS1s\wYdSdSdS)z:Remove inplace existing MEG projectors (assumes inactive).TrXcrNrOrP)rSr�)�instrOrVrWr�z+_remove_meg_projs_comps.<locals>.<listcomp>Zprojsc3s�|]}|�vVqdS�NrOr�)�meg_channelsrOrVr�r�z*_remove_meg_projs_comps.<locals>.<genexpr>r�r�F)Zremove_existingr@�comps)NrN)rrar�rCrjZadd_projrS�_unlock)rUr�r�Znon_meg_projr�rO)rUrWrVrs346�"��rcCs�|dur|dS|dkrtd��t|ttB�r t|dd�d}n*t|t�r(|}n"t�|t�}|j	dkr7t347d��t�d	�}||dd348�d349f<tdd|�}|jdksT|j
dkr`td|j
�d
|j����|S)z Triage our reconstruction trans.Nr^rrz>destination can only be set if using the head coordinate framerYr�rpz4destination must be a 3-element vector, str, or None�rpz350MEG devicez5Destination transform is not MEG device -> head, got z -> )r�rQr_rr.r(rgrEr�r#r�r%Zto_strZfrom_str)r�rar�r�rOrOrVr�s2�351352353���r�rL)�accuracyr@cCs�t|d||dd�}|d}t|�}t|�}t�dd�|D��}t�dd�|D��}	t�dd�|D��}354|	|355dd�tjf9}	~356t�d	d�|D��}t�t�t|��|�}t�d357gt�	|�f�}
dd�t358t|
dd
�|
dd���D�}||	||||fS)z7Get all coil integration information loaded and sorted.F)rr�r\r@ZdefscS�g|]}|d�qS��rmagrO�rSZcoilrOrOrVrW7�z"_prep_mf_coils.<locals>.<listcomp>cSr])ZcosmagrOr`rOrOrVrW8racSr]��wrOr`rOrOrVrW9raNcS�g|]}t|d��qSr^�rir`rOrOrVrW<r]rcSs i|]\}\}}|t||��qSrO)�slice)rS�iirrrOrOrV�359<dictcomp>?s�z"_prep_mf_coils.<locals>.<dictcomp>r�r�)r$�
_get_mag_maskrirgr�r5rE�repeatrhZcumsumr�r)rar�r\r@Zmeg_sensorsrOZmag_mask�n_coils�rmags�cosmags�ws�n_int�binsZbdZ	slice_maprOrOrVr�,s$360��r�c
Cs>|j||d�\}}	}361||}|	|}t|||||362||||d�	S)N)rr)rr�r�rrr�)r7r)
�363clean_data�	orig_datarr�r�rrr�r+r,r�rrrOrOrVrEs�rcCs�|s
t�|jddf�}	nt�|�t|||�}	|||d|}}|d�d|d�d�}364d|	jdd�dt|	jdd	��d365|366��}|dkrU|d|d�dt|d	��d
�7}t�|�|t�t�||	�|	j	�fS)z@Compute and apply SSP-like projection vectors based on min corr.r�r�8.3f� - z sz        Projecting �2dz intersecting tSSS component� z for z	 (across z	 position�))367rgr8r#Zasarray_chkfinite�_overlap_projectorr:r>rar	rF)rqrrrr�r�rrr�Zt_proj�t_str�msgrOrOrVras 
368���369rc		s|r|��}|j���|d|jd<Wd�n1swY|r�tjtjtjtjtjtj	tj370tjtjg	�t
|j�t
��t
|j�f}t�|tj�}d}|jrgt�|d�|j|dt
|j��<||_n+t�|d�tt���|�|dt
|j���Wd�n1s�wY||_|jdus�J�t
|j����fdd�tt
���D�}|jd�|�|j��|j��|jj|jd	t
|j�fks�J�t�t
|j�t
|�t
|j��}||fS|r�|js�t�d371�|jdd�nt�d
�|t� gt!�fS)z;Load data for processing and (maybe) add cHPI pos channels.rKNz0    Appending head position result channels and zcopying original raw datazloading raw data from diskTcsLg|]"}td|d��|d�|dddd�|tjdtjt�d�d��qS)ZCHPIZ03dr�r�r��-C��6?�)r[ZlognoZscannoZunit_mulr�unit�kindr�r��	coil_type�loc)r�rZFIFFV_COORD_UNKNOWNr
ZCOIL_UNKNOWNrgr��rSrg��kinds�offrOrVrW�s �372373��z._copy_preload_add_channels.<locals>.<listcomp>r�z    Loading raw data from diskF�r@z    Using loaded raw data)"r`rarYrZFIFFV_QUAT_1ZFIFFV_QUAT_2ZFIFFV_QUAT_3ZFIFFV_QUAT_4ZFIFFV_QUAT_5ZFIFFV_QUAT_6ZFIFFV_HPI_GZ
FIFFV_HPI_ERRZ
FIFFV_HPI_MOVrirQr�rgr��float64Zpreloadr>rr?r=Z
_preload_datar�extendZ_update_redundantZ_check_consistencyr#rh�	load_datarEr�)	rKr�r`raZ	out_shapeZout_datarzZchpi_chsrrOr�rVr�sZ���374375�376377  378379rc	s�t�tjdfd��durt�d��n|dkrtd��|s!td�t�tjd��jdks4�jdd	kr8td380���dd�df}t�|t�	|��sMtd��t381��dkrrt||jd
d|j
dd���srtd|dd�d|jd����||j}t382|�dks�|dd|j
dkr�t�dg|g�}|j
d}|dur�t�d�n|d}t�|dgt|dd�dd�f�|dd�dfgd�g�}t�|tj�g��d|d<t�tj�dd�dd�fddd����}|dkr�td|d�d��d|d<t�t383|�ddf�}d|dd�ddf<�dd�dd�f|dd�dd�df<t�dd�dd�f�|dd�dd�dd�f<|j|d d!�}||�dd�dd�fg�t�fd"d#��D���sTJ��S)$zCCheck for a valid pos array and transform it to a more usable form.Nr�)r�384rrz0positions can only be used if coord_frame="head"z-st_fixed=False is untested, use with caution!r	r�r�z%pos must be an array of shape (N, 10)rz.Time points must unique and in ascending orderg����MbP?r�)ZtminZtmaxr�zNHead position time points must be greater than first sample offset, but found z0.4fz < ��?r�r^r[r�rp)rrr�rr�z#Found a distance greater than 1 m (z0.3gzU m) from the device origin, positions may be invalid and Maxwell filtering could failT)Zuse_roundingc3s$�|]
}t|�t�d�kVqdSrRrer��rrOrVr��s�"z_check_pos.<locals>.<genexpr>)r<rg�ndarrayr8r�rA�ndimr#Zarray_equal�uniquerir;Z_first_timerarDr�r%r6r5r�r�r�r�r5re)	rr�rKr�rr�Zdev_head_posZmax_distZdev_head_tsrOr�rVr��sd�����385"3864�,�&.r�c 387Cs�t|||||||||
�	}|dur||}||	}|�dd�}t|�dkr�d}d}|j||	}|tjj|dd�}t|d�}|jd|kr�|dd�|d�f�	�}|tjj|dd�}tj388||d	�}|jd|jdksoJ�|t�|t�|j|��8}t�tjj||d�dd��}nt�tjj|d|�dd��}tjj|dd�|k}t
t�|�d|jd�}t�d389|jd|���|tjj|dd�|}tj||gdd�}|jdr�t�|dd|jdffd
�}|||	|jdd�f<nt
�}~t||||390||d�\}}}|j|dd�}t|�	��\}}|d|d}|dk�rF|dk�rFd|d�d�}|dk�r7t|��|dk�rAt|�nt�|�|||	j9}|||	}||}|jd|jdk�rl|	��k�soJ�J�|||||fS)z6Get a decomposition matrix and pseudoinverse matrices.Nr�rOrr{rrzr�)�rcondz    Reducing %d -> %dr�)rrZconstantrr��@�@zMatrix is badly conditioned: z0.0fz >= 1000rtr�)�
_get_s_decomp�getrirFrgr�normr-r#r`Zorthr	rGr�r r>�debugr�r��pad�_regularizer"�_col_norm_pinvr�rAra) r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r(r'r�r�ZthreshroZS_extZ391S_ext_orth�scale�mask�extended_remover�r*r)ZsingZcondrzrOrOrVr��sx� 392���3933943953960r�c	Csvt||||�}	|dur9t|||||�}397t|�dkr%|	|dd�f|3987<t|�dkr9|	|dd�f|d<|	S)z
Get S_decomp.Nr�mag_cals)r��_sss_basis_pointri)r�r�r�r�r�r�r�r�r�r'Z	grad_calsrOrOrVr�[sr�cCs|d|d}}t|�}	|jd|	}399|d�}|dur't|||||�\}}
n	g}t||||�}
t�t�|	�|�}t�t�|	|jd�|
�}t|�}t|�}t�||f�}|j	|dd�}|dusd||400kr�t401�d||�d|	|402�d	|�d403|�d|	�d|�d|404�d��|||fS)
z"Regularize a decomposition matrix.rzr{r�rsNrz        Using �/z harmonic components for z  (z in, z out))r-r#�_regularize_in�_regularize_outrg�	setdiff1drhrir�r"r>ra)r�r�r'r�r�rr@rzr{�n_in�n_outry�405in_removes�out_removesZreg_in_momentsZreg_out_momentsr*Z	n_use_outr�rOrOrVr�msB406407��������408r�cCs�t|dd�}t|�dkrt|dd�|}t|d|gd�}tt|�|�}~t�t|�t�}	d|	t|d|dd�<t	||g��409�}410|411|	�412�krRtd|413�d|	�414��d	���d415d�|dD�}t|�dkrgd|��}nd
}t�
|�|rrdnd}
t|d|
gd�}|r�dnd}
t|d|
gd�}t|�t|�t|d�ks�J�t�t|�t�}d||<t�dd�|dD��}d||d@tjk<tjtjtjg}d|t�||�<dt|��dt|��d�}t|�|�416�}|dkr�|d|�d�7}t�
|�||||	|fS)z7Pick types for Maxwell filtering and fix magnetometers.T)Zuse_calr)rY�ref_megrZr�rDzNumber of requested bases (z") exceeds number of good sensors (rwcSsg|]}|�qSrOrO�rS�chrOrOrVrW�sz*_get_mf_picks_fix_mags.<locals>.<listcomp>z*    Bad MEG channels being reconstructed: z    No bad MEG channelsF�mag�gradrQcSr])rrOr�rOrOrVrW�rarKi��z    Processing z gradiometers and z magnetometersz (of which z are actually KIT gradiometers))rrirrrrrgr�rBr-r�r�r>rarErZFIFFV_COIL_KIT_GRADZFIFFV_COIL_CTF_GRADZFIFFV_COIL_CTF_REF_GRADZFIFFV_COIL_CTF_OFFDIAG_REF_GRAD�isin)rarzr{r�r@Z
mag_inds_T1T2�refr�Zmeg_infor�Zn_basesZreconsrzr�r�r�r�Z417coil_typesZ	ctf_gradsZn_kitrOrOrVr��sb����418 ���419r�cCs*|dust|t�r
|dvstd��dSdS)zEnsure regularize is valid.N)rszregularize must be None or "in")rQr_r�)r�rOrOrVr��s�r�cCs0|jrtd��|j}|dvr|rtd��dSdS)zEnsure our data are clean.z>Projectors cannot be applied to data during Maxwell filtering.rRz�Maxwell filter cannot be done on compensated channels (data have been compensated with grade {current_comp}) when ignore_ref=TrueN)r�r�rS)rUr�Zcurrent_comprOrOrVr��s���r�cCs^t�tj||dd��}||}t|fddit��\}}}||}t�|jd||j�|fS)zmCompute the pinv with column-normalization to stabilize calculation.420 421    Note: will modify/overwrite x.422    rr�
full_matricesFr�)rgr�r�r�
check_disabler	rF)r�r��u�s�vrOrOrVr��s423r�cCs||S)zSquare quickly.rO�r�rOrOrVr��sr�cCsNt�d|ddtj�}|dkr%|t�t||�tt||���9}|S)z5Compute normalization factor for spherical harmonics.r	r�r[r)rgr�r�rr�)�order�degreer�rOrOrV�_sph_harm_norm�s&r�cCsht�dd�|D��}t�dd�|D��}t�dd�|D��}t�t�t|��dd�|D��}||||fS)z7Concatenate MEG coil parameters for spherical harmoncs.cSr])Zr0_exeyrOr`rOrOrVrWraz*_concatenate_sph_coils.<locals>.<listcomp>cSr]rbrOr`rOrOrVrWracSs6g|]}t�|dtjdd�ft|d�df��qS)ZezNr_r�)rgZtiler5rir`rOrOrVrWs6cSrdr^rer`rOrOrVrWr])rgr�rjrhri)rO�rs�wcoils�ezsrprOrOrV�_concatenate_sph_coilss� r�gH����ך>cCst�dd�|D��S)z)Get the coil_scale for Maxwell filtering.cSsg|]	}|dtjk�qS)Z424coil_class)r
Z	COILC_MAGr`rOrOrVrWsz!_get_mag_mask.<locals>.<listcomp>)rgrErNrOrOrVrisri�standardc-Cs�|d|d}}|d}d|vsJ�|dkr<t|�\}}}	}425||8}t|�j\}}}
||	dd�tjf9}~~	tj}n$t|�\}}}}426||8}t|�j\}}}
||dd�tjf9}~~tj}~t||g�\}}t�	t427|�||f|�}|dd�d|�f}|dd�|d�f}t�t428|�df�}||t|�<t
dt||�d�D�]8}t
|d�D�].}t�}t�}t|||
|�}t||�}d||t�t�|
d	��}|t�|
�t�d||�t||t�|
��}||k�r|�|�t||d429} | |d|}!| |}"| |}#|�t||
|!|"|#��||k�rC|�|�t||d}$|$||}!|$|}"|$|}#|�t||
|!|"|#��t||�D]�\}%}&|dk�r�t|&|�g}'|g}(|dk�rq|'�tt|&|�|��|(�|�t|'|(�D]!\})}*t�d
|)|�})t�|430|)t431|��}+|+|%dd�t||*�f<�qv�qHt�d
|&|�}&t�|432|&j t433|��dt�|434|&j!t435|��},|,|%dd�t||�f<|dk�r�t|,|�|%dd�t||�f<�qHq�q�||9}|dk�r�t"|||�}|S)zECompute SSS basis using non-optimized (but more readable) algorithms.rzr{ryr�r�Nr�y�?缉ؗ�Ҝ<r	r�rzij,ij->i)#r"r*rFrgr5r�r��436complex128r-r8rir1rirr�r�r!r��sin�maximumr��_alegendre_deriv�cosrj�_mu_0r2rr/r0Zeinsumr r+�real�imag�_bases_complex_to_real)-r�rOr��methodrzr{ryrlrmrnrpZrad�azZpolZout_typer�r�r�r�r��S_tot�S_in�S_outr�r�r�ZS_in_outZgrads_in_outZsphZsph_normZ	az_factorZ437pol_factorZin_normZg_radZg_azZg_polZout_normZspc�gradsZ
grads_pos_negZorders_pos_neg�grZoo�valsr�rOrOrV�_sss_basis_basics�438����439440441442443444���445 ���<446r�c(
Cs�|dd�\}}}}|d|d}}t||g�\}}	||d}t||�}447t||448�}t�|dd�df|dd�df�}t�tj||dd��}
t�|dd�df|dd�df|dd�df|dd�df�}|dd�d	f|
}t�d449||�}|dk}|��}d450||<d451||<|dd�df|}d452||<|dd�df|}d||<|
��}d453|
|
}t�|||	ftj	�}|dd�d|�f}|dd�|d�f}t454|455d�D�]�}||kr�||
9}||kr�||
9}d
t�d	|dtj�}|dk�rft|d�}||k�r6||d||d|}|||d|}t
|||||d||||�456|dd�|f<||k�rf||||d|}|||d|}t
|||||d||||�457|dd�|f<t458d|d�D�]Y}||} t�| �}!t�| �}"|t�||d||�}|t�d	�}#t||�}|#||||"}$|#||!|||}%|#|||d||||d|||d|"}&||k�r�|d|$|}|%||}'d|'|<|&d	|}t
||||||'||||�459|dd�|f<||k�r-||$|}|%||}'d|'|<|&|d}t
||||||'||||�460|dd�|f<t||�}|#||||!}$|#||"|||}%|#|||d||||d|||d|!}&||k�r�|d|$|}|%||}'d|'|<|&d	|}t
||||||'||||�461|dd�|f<||k�r�||$|}|%||}'d|'|<|&|d}t
||||||'||||�462|dd�|f<�qmq�|S)a�Compute SSS basis for given conditions.463 464    Parameters465    ----------466    exp : dict467        Must contain the following keys:468 469            origin : ndarray, shape (3,)470                Origin of the multipolar moment space in meters471            int_order : int472                Order of the internal multipolar moment space473            ext_order : int474                Order of the external multipolar moment space475 476    coils : list477        List of MEG coils. Each should contain coil information dict specifying478        position, normals, weights, number of integration points and channel479        type. All coil geometry must be in the same coordinate frame480        as ``origin`` (``head`` or ``meg``).481 482    Returns483    -------484    bases : ndarray, shape (n_coils, n_mult_moments)485        Internal and external basis sets as a single ndarray.486 487    Notes488    -----489    Does not incorporate magnetometer scaling factor or normalize spaces.490 491    Adapted from code provided by Jukka Nenonen.492    Nr[rzr{ryr�rrr	r�r�r�gH����׊>�@)r-r��_tabular_legendrergZarctan2r�r�r`r8r�rr�r+�_integrate_pointsr�r�)(r�r�rlrmrprkrzr{r�r�Z	max_order�L�phi�r_nZr_xy�cos_pol�sin_polZz_onlyZ493sin_pol_nz�cos_az�sin_azZr_nn2Zr_nn1r�r�r�r�r�r��b_r�b_polr�Zord_phiZ	sin_orderZ	cos_order�factorZr_factZaz_factZpol_fact�b_azrOrOrV�494_sss_basis{sB 495496$F497498499�500
�501502503"����504	�505
�"����506	�507
���hr�c508Cs2t|||||||�j}509|510|jdd�}511t||512|	�S)z%Integrate points in spherical coords.r�r)�_sp_to_cartrFr�r )r�r�r�r�r�r�r�rmrprkr�rOrOrVr�Msr�c513Cs`t�tj||dd��}|dd�df|}t�}t|d�D]}|�t�|dt|�f��qd|dd<t�|j	�}d}t�d|d|�}t|d�D]^}||||<|||9}|d7}||krz|d|d|||||d|<|dkr�t|d�D](}	|d|d||d|	||	d||d|	||	|||	<q�qO|S)z(Compute associated Legendre polynomials.r�rNr	r�rr�)514rgr�r�r�rrjr�rir1r#)515�rZnindr�r�r�r�ZpnnZfactZsx2r�rOrOrVr�Vs0(���r�cCspt�d|j�}|||||||||d<|||||||||d<|||||d<|S)z&Convert spherical coords to cartesian.rZrr�r	)rgr8r#)r�r�r�r�r�r�r��outrOrOrVr�ps516$$r�cCs�t�t|�t�}t�|�}td|d�D]'}t|d�D]}t||�}|||<|||<t||�}|||<|||<qq||fS)z3Get the set of degrees used in our basis functions.r�)rgr�r-r�Z517zeros_likerr+)r��degrees�ordersr�rgrOrOrV�_get_degrees_ordersys518519�r�cCsb|dksJ�||t|||�||||dt�d||�t|d||�d||S)a�Compute the derivative of the associated Legendre polynomial at a value.520 521    Parameters522    ----------523    order : int524        Order of spherical harmonic. (Usually) corresponds to 'm'.525    degree : int526        Degree of spherical harmonic. (Usually) corresponds to 'l'.527    val : float528        Value to evaluate the derivative at.529 530    Returns531    -------532    dPlm : float533        Associated Legendre function derivative534    rr�r�)rrgr�)r�r��valrOrOrVr��s535����536�r�cCs:t||g�\}}|dd�d|�f}|dd�|d�f}t�|jtj�}|dd�d|�f}|dd�|d�f}	t||g||	g||g�D]V\}537}}td|d�D]I}
t|
d�D]@}t|
|�}t|
|�}t|538dd�|f|�|dd�|f<|dkr�|ddkr�dnd}|t|539dd�|f|�|dd�|f<qXqPqD|S)z,Convert complex spherical harmonics to real.Nr�rr	r�)	r-rgr8r#r�rrr+r/)Zcomplex_totrzr{r�r�Z540complex_inZcomplex_out�real_tot�real_in�real_outrTr��	exp_order�degr��idx_pos�idx_negr�rOrOrVr��s.�541"����r�cCs t||g�\}}|dd�d|�f}|dd�|d�f}t�|jtj�}|dd�d|�f}|dd�|d�f}	t||g||	g||g�D]I\}542}}td|d�D]<}
t|
d�D]3}t|
|�}t|
|�}t|543dd�|f|544dd�|fg|�}||dd�|f<t	||�|dd�|f<qXqPqD|S)z,Convert real spherical harmonics to complex.Nr�)545r-rgr8r#r�rrr+r1r0)r�rzr{r�r�r�r�Zcomp_totZcomp_inZcomp_outr�rTr�r�r�r�r�Z	this_comprOrOrV�_bases_real_to_complex�s*�546 ���547r�c	Csl|dD]/}dd|fdd|fdd|fdd	|ffD]\}}}|s qt|d548|�dkr2td|�d
���qqdS)z7Ensure that Maxwell filtering has not been applied yet.�proc_historyZSSS�sss_infoZtSSSr�zfine calibrationr�zcross-talk cancellationr��max_inforzMaxwell filtering z. step has already been applied, cannot reapplyN)rir�)	rar�r�r|r�Zentrz�keyZdoingrOrOrVr��s�549����r�c
Csjt||g�\}
}|j���
d|jd<Wd�n1swYt�|
|t|���d�}d||	<t||||�d�tj	t�550|d|
��t||d�}t|d�}|551r`|jt�t�t�d	�n'|j|||d	�t
|j�|j���
||jd552<Wd�n1s�wYt�}|j���|jd�dt||td
t��dd��Wd�dS1s�wYdS)a}Update info inplace after Maxwell filtering.553 554    Parameters555    ----------556    raw : instance of Raw557        Data to be filtered558    origin : array-like, shape (3,)559        Origin of internal and external multipolar moment space in head coords560        (in meters)561    int_order : int562        Order of internal component of spherical expansion563    ext_order : int564        Order of external component of spherical expansion565    nchan : int566        Number of sensors567    sss_ctc : dict568        The cross talk information.569    sss_cal : dict570        The calibration information.571    max_st : dict572        The tSSS information.573    reg_moments : ndarray | slice574        The moments that were used.575    st_only : bool576        Whether tSSS only was performed.577    recon_trans : instance of Transform578        The reconstruction trans.579    extended_proj : ndarray580        Extended external bases.581    FZ	maxshieldNZint32r�Zfloat32)Zin_orderZ	out_orderr�ryr�Znfree�frame�582components)r�)r�r�r�r^r�rzmne-python v�)r��block_id�dateZcreatorZexperimenter)r-rarYrgr�riZastyper�rZFIFFV_SSS_JOB_FILTERr�r3r��_reset_meg_badsr�insertrr583)rKryrzr{r�r�r�r�r�r�r�r�r�r�r�r�Z
sss_info_dictZ
max_info_dictr�rOrOrVr��sJ-��584 585586�587��"�r�cs.t�dgd����fdd��dD��d<dS)zReset MEG bads.TrXcs"g|]
}�d�|��vr|�qSrPr�)rS�bad�rar�rOrVrW@sz#_reset_meg_bads.<locals>.<listcomp>rDN)rr�rOr�rVr�=s�r�)Zcheck_finitecCstt|fddit��dd�\}}|j\}}t�t�j}t||�t�|�|}tj	||kt588d�}|dd�d|�fS)z(Create a slightly more efficient 'orth'.r�FNr	)Zdtype)rr�r#rgZfinfor��epsr�Zamaxr�r�)�Ar�r��M�Nr�Ztol�numrOrOrV�_orth_overwriteHs 589r�cCstj�|�}|dkrdn|}t||j�}tj�|�}|dkr!dn|}t||j�}|jddks8|jddkrBt�|jddf�Stj|fddd�t��dj}tj|fddd�t��d}t�	||�}~t590|fddit��dd	�\}}~||k}	~||	j}t�	||�}591|592S)593zACalculate projector for removal of subspace intersection in tSSS.rr�r�TZeconomic)Zoverwrite_a�moder�FN)rgrr�r�rFr#r8Zqrr�r	r)Zdata_intZdata_resZcorrrZQ_intZQ_resZC_matZS_intersectZVh_intersectZintersect_maskZV_principalrOrOrVrxSs*�594rxcs:ddlm}t|tdf�t|t�st�t|��}||�}nd}t�	d|���t595|ddd��t�}t�}t596|ddd�}tt
|d|��D]\}\}	}597|598�vrW|�|	�qG��|599�}|||<qGt|dg|d	�}t|�t|�kr�t�fd600d�|D�t|��}
td|
����t|�r�td
t|��d|���||�fS)Nr�)�read_fine_calibrationz	path-liker�z    Using fine calibration rQT�Zremove_whitespace�rYrZr�csh|]}�|�qSrOrOrRrPrOrVrP�raz!_prep_fine_cal.<locals>.<setcomp>z>Not all MEG channels found in fine calibration file, missing:601zFound cal channelz not in data: )Z	_fine_calrr<r�rQ�op�basenamer_r>rar8r�r�rrjr�rrirbrcr�rAr:)ra�fine_calr�r�extra�info_to_calr�Znames_clean�cir�Z602name_clean�oir�r�rOrPrV�_prep_fine_cal�s2603604605606�607r608cs�t|�|d�\��}t|dd|d�}t|dd|d�}t���fdd�|D��j}|jdd	vr<td609|jd�d���t���fdd�|D��}t|t|�|d
�}t	|||d�}	t610�}611t�t|d�t�}t612�}t613�}
d}��
�D]�\}}||r|J�d||<|d|}zt�d|�d��d��}Wnty�|}Ynw|
�||dg�t|d�dd�dd�f}�d|��}t|�dd�dd�f�t��fdd�td�D��dk�r|s�t�d�d}t|dd�df�dd�df�}t�||�j��|dd�<t|�dd�dd�f}t|�t|d�dd�dd�f}t|�|614�tj||dd��||v�rCd�d |dg}n615�d |dd!g}|�t�||g��|dd�|ddd�<|d"tjk�smJ�qrt|dd|d�}||���s�J�|t� t�!t|��|��"��r�J�t	t�|�t�|
�d#�}t�|616�}617t�#|618d$d|619�t�$t�%|620�|621�t�d%t�&|622�d&�d't�'|623�d&�d(t�t�(|624��d&�d)��|	|fS)*z8Replace sensor geometry information and reorder cal_chs.)r�r�rOrr�c�g|]625}�d�|�qS��imb_calsrO)rS�gi�rrrOrVrW��z+_update_sensor_geometry.<locals>.<listcomp>r)rr�rpzHMust have 1 (x) or 3 (x, y, z) point-like magnetometers. Currently have �.crrrO)rS�mirrOrVrW�r)�n_typesr�)�grad_imbalances�
grad_coilsetsr�rKFTrQZMEG�0rr�NrpZlocsc626s6g|]}t�t��dd�|f�dd�df���qS)Nr	)rg�absr	r�)�cal_coil_rotrOrVrW�s(��r	g�����ư>z*        Adjusting non-orthogonal EX and EYrr�r
r�r�)�	cal_corrs�	cal_chansg�u2        Adjusted coil orientations by (μ ± σ): r�u° ± u	° (max: u°)))r627rrgrErFr#r��_get_grad_point_coilsetsrir�r�r�rB�itemsr��lstriprjrr`r�rr>rar,r	Zravelr'r�r�rZFIFFV_COORD_DEVICErDr�rhrCZclipZrad2degZarccosrG�stdr)rarr�r3r�r�rr�rr|Z	ang_shiftrHrrZ
adjust_loggedr	rZinfo_chZch_numZch_coil_rotZcal_locZ628this_transZv1Zv2rr�r�rO)rrrrVr��s�����629�� �630���631"632$633634�635���r�c	Cstt�gd�gd�gd�gd�g�t�gd�gd�gd�gd�g�t�d�d�}t�}t|dgd�}t|�d	kr:|Stt|�|�}|d636D]}t	j637|d<qEdd
�|d638D�}dd|�D]-}	t|d639�D]\}640}tt�
t||641�||	��dd�|ddd�<qd|�t||��q\|S)z)Get point-type coilsets for gradiometers.)rrr�r)rr�rr)r�rrr)rrrr�r[)r��y�zr�rXrrKrcSsg|]}|d���qS)r�)r`r�rOrOrVrW	r]z,_get_grad_point_coilsets.<locals>.<listcomp>ZxyzNrpr�)r�rgrEr%r�rrirrrZFIFFV_COIL_POINT_MAGNETOMETERr�rr	rrjr�)rarr�Z642_rotationsrr�Z	grad_infor�Z	orig_locsZrotrrOrOrVr	s,  ���rc643Cs^d}t�|gt�}t|d|d�D]\}}t||||�}	|	|dd�tjf9}	||	7}q|S)z=Compute multipolar moments for point-like mags (in fine cal).r�rrN)rgrEr�rr�r5)644r�r�r�r�r�r�Zthis_csZimbrOZS_addrOrOrVr�	s645r�cCs4t|�}|dko|��}tt||d|��|S)z(Regularize out components based on norm.rrp)r-rCr�r)rzr{r�r�r�Zremove_homogrOrOrVr�,	sr�cCst||g�\}}tt�|d��\}}t|�\}	}646||	}t�|�}tt|��}t||||�}
tt�	t�||j647d�|
��}g}|��}t�tj
||dd��}||}t�|df�}d}||9}t|�D]�}|j||dd�}t|fddit��\}}}~|ddg||<|jd	t|��}|||d	d	�tjf}t�|d648||j�}~~~||9}|j
dd�}||9}||649|dkd9<|d9}|||}dt�|d650��
�||<|�|t�|��|�|�|d��|d
k�r	||d|d�d|��k���r	nqe|�rzt�|�}t�|d|k�dd}|d	|�}t|�D]2\}}||}t�d|dd�d|dd�d|d|dd�d|�d|	|�d|651|d����q)t�d||d�dd|||d�d|d�d��||
fS|d	d�}||
fS)z1Regularize basis set using idealized SNR measure.r�rrr	g�-���a=r�Fr�Nr�g{�G�zd?r�r�gffffff�?rqz            Condition �0.3fz / z = z03.1fz, Removing in component z: l=z, m=z+0.0fz        Resulting information: r�z bits/sample (�dz652% of peak rw) r-�_compute_sphere_activation_inrgrhr�r�r�rr�r�r#r`r�r�r"rr�rFrir5r	�log2rjZargmin�popr�r�rDr r�r>r�)rzr{r'r�r�r�r�Za_lm_sq�rho_ir�r�ZI_totsZ653in_keepersr�Zout_keepersZremove_orderZuse_normZeigsZ	noise_levrgZthis_Sr�r�r�Z	eta_lm_sqZsnrr�Zlim_idxr��riZeigrOrOrVr�3	s~6540�655���������r�cCsDd}d}t|�||d|dtd|d�|d}||fS)a�Compute the "in" power from random currents in a sphere.656 657    Parameters658    ----------659    degrees : ndarray660        The degrees to evaluate.661 662    Returns663    -------664    a_power : ndarray665        The a_lm associated for the associated degrees (see666        :footcite:`KnuutilaEtAl1993`).667    rho_i : float668        The current density.669 670    References671    ----------672    .. footbibliography::673    g{�G�z�?g4;�ݒգ>r	r[r�r�)r�)r�Zr_inr&Za_powerrOrOrVr#�	s���r#cCs�|dur0t|t�stdd|�}t�|d���rJ�t||d�t||ddd�f|d	d�}t|tj�sG|}t�|d674df�}|||d<t||�}||9}|S)z8Compute SSS basis (optionally) using a dev<->head trans.NrYrrr�rr�F)�mover	rpr[)	rQr(rg�isnanrCr4r�r1r�)r�r�r�r��csr�rOrOrVr��	s 675�676�677r��@�@��D@c?s@|durE�j�d�r1�jd|kr1�jd|krdnd}d�jd�d|�d|�d�}t�|�nt�d	|�d678�������jd|d��t|�}t�|dd
�\}}~t�}t�}t	t679�jd|��}t||�D]'\}}|||kr�t�
|||d|�}|�|�||}||d<|�|�qitt�d�t|���t�dt|�t|�|�jd�t�g|||||	|680|||
|||dd���ddus�J�~~~~~	~681~~~
~~�d�d�t�d�t�d�ks�J�t�d�t�d�ks�J�t�}t�} tddd��t���fdd��D��}!tdt	d�jdd ��}"t�}#t�t|�d!f�}$t��j�}%t�����}&t�t|%�t|�ftj�}'tj|'tjd"�}(t�t|%�dftj�})tj|)tjd"�}*tt||��D�]�\}+\},}-d#}.�j d|,|-d$d%�}/t!|/�d&�j"|,d'd$d(���j#d#dg|,�jd}0t�d)|+dd*�d+|0d#d,�d-|0dd,���|-|,}1|1|1|"}2�� �d#|2�}3|3j$d#d|"f|3_$tj%|3dd.��d�}4|0d#|0df|$|+dd�f<|4|'�|+f<|!�&dd�|)�<|4|!k�t�'��d#���fd/d��D��| �(��|#t��O}#t)|#����fd0d��D�}5t|5�d#k�r8t�d1t��d2�d3��t*d4|0d#d5�d6��n�t��t	t682�j#d�jd���d7<t+dd8�D]�}.t�jd9�t��@t�k�scJ�����fd:d��dD��ddd�<|/�j,dd�<�� |5�}4t-t.���t/�fd;d$i���Wd�n	1�s�wY|.dk�r�t���r�t�d<t��d=�0���|4�� |5�8}4tj1|4dd.�}6t�2�d|5�}7|6�d|7d#f9}6t�3|6�t�%|6�}8}9|6|8|9}:t�4|:�};|:|;}<|:|(|5|+f<||*|5<|<|k�rn�j|5|;}=t�5d>|=�d=|<d?���|5�6|;���7|=��qP|�(���qet)�fd@dA�|�8�D��fdBdC�dD�}t)�fdEdA�| �8�D��fdFdC�dD�} |%�d}%|&�d}&|'�d}'|)�d})|(�d}(|*�d}*t�dG|���t�dH| ���t�dI�|�r�t|%|&|$|'|)|(|*dJ�}>|| |>fS|| fS)Ka�Find bad channels using Maxwell filtering.683 684    Parameters685    ----------686    raw : instance of Raw687        Raw data to process.688    limit : float689        Detection limit for noisy segments (default is 7.). Smaller values will690        find more bad channels at increased risk of including good ones. This691        value can be interpreted as the standard score of differences between692        the original and Maxwell-filtered data. See the ``Notes`` section for693        details.694 695        .. note:: This setting only concerns *noisy* channel detection.696                  The limit for *flat* channel detection currently cannot be697                  controlled by the user. Flat channel detection is always run698                  before noisy channel detection.699    duration : float700        Duration of the segments into which to slice the data for processing,701        in seconds. Default is 5.702    min_count : int703        Minimum number of times a channel must show up as bad in a chunk.704        Default is 5.705    return_scores : bool706        If ``True``, return a dictionary with scoring information for each707        evaluated segment of the data. Default is ``False``.708 709        .. warning:: This feature is experimental and may change in a future710                     version of MNE-Python without prior notice. Please711                     report any problems and enhancement proposals to the712                     developers.713 714        .. versionadded:: 0.21715    %(origin_maxwell)s716    %(int_order_maxwell)s717    %(ext_order_maxwell)s718    %(calibration_maxwell_cal)s719    %(cross_talk_maxwell)s720    %(coord_frame_maxwell)s721    %(regularize_maxwell_reg)s722    %(ignore_ref_maxwell)s723    %(bad_condition_maxwell_cond)s724    %(head_pos_maxwell)s725    %(mag_scale_maxwell)s726    %(skip_by_annotation_maxwell)s727    h_freq : float | None728        The cutoff frequency (in Hz) of the low-pass filter that will be729        applied before processing the data. This defaults to ``40.``, which730        should provide similar results to MaxFilter. If you do not wish to731        apply a filter, set this to ``None``.732    %(extended_proj_maxwell)s733    %(maxwell_mc_interp)s734    %(verbose)s735 736    Returns737    -------738    noisy_chs : list739        List of bad MEG channels that were automatically detected as being740        noisy among the good MEG channels.741    flat_chs : list742        List of MEG channels that were detected as being flat in at least743        ``min_count`` segments.744    scores : dict745        A dictionary with information produced by the scoring algorithms.746        Only returned when ``return_scores`` is ``True``. It contains the747        following keys:748 749        - ``ch_names`` : ndarray, shape (n_meg,)750            The names of the MEG channels. Their order corresponds to the751            order of rows in the ``scores`` and ``limits`` arrays.752        - ``ch_types`` : ndarray, shape (n_meg,)753            The types of the MEG channels in ``ch_names`` (``'mag'``,754            ``'grad'``).755        - ``bins`` : ndarray, shape (n_windows, 2)756            The inclusive window boundaries (start and stop; in seconds) used757            to calculate the scores.758        - ``scores_flat`` : ndarray, shape (n_meg, n_windows)759            The scores for testing whether MEG channels are flat. These values760            correspond to the standard deviation of a segment.761            See the ``Notes`` section for details.762        - ``limits_flat`` : ndarray, shape (n_meg, 1)763            The score thresholds (in standard deviation) above which a segment764            was classified as "flat".765        - ``scores_noisy`` : ndarray, shape (n_meg, n_windows)766            The scores for testing whether MEG channels are noisy. These values767            correspond to the standard score of a segment.768            See the ``Notes`` section for details.769        - ``limits_noisy`` : ndarray, shape (n_meg, 1)770            The score thresholds (in standard scores) above which a segment was771            classified as "noisy".772 773        .. note:: The scores and limits for channels marked as ``bad`` in the774                  input data will be set to ``np.nan``.775 776    See Also777    --------778    annotate_amplitude779    maxwell_filter780 781    Notes782    -----783    All arguments after ``raw``, ``limit``, ``duration``, ``min_count``, and784    ``return_scores`` are the same as :func:`~maxwell_filter`, except that the785    following are not allowed in this function because they are unused:786    ``st_duration``, ``st_correlation``, ``destination``, ``st_fixed``, and787    ``st_only``.788 789    This algorithm, for a given chunk of data:790 791    1. Runs SSS on the data, without removing external components.792    2. Excludes channels as *flat* that have had low variability793       (standard deviation < 0.01 fT or fT/cm in a 30 ms window) in the given794       or any previous chunk.795    3. For each channel :math:`k`, computes the *range* or peak-to-peak796       :math:`d_k` of the difference between the reconstructed and original797       data.798    4. Computes the average :math:`\mu_d` and standard deviation799       :math:`\sigma_d` of the differences (after scaling magnetometer data800       to roughly match the scale of the gradiometer data using ``mag_scale``).801    5. Marks channels as bad for the chunk when802       :math:`d_k > \mu_d + \textrm{limit} \times \sigma_d`. Note that this803       expression can be easily transformed into804       :math:`(d_k - \mu_d) / \sigma_d > \textrm{limit}`, which is equivalent805       to :math:`z(d_k) > \textrm{limit}`, with :math:`z(d_k)` being the806       standard or z-score of the difference.807 808    Data are processed in chunks of the given ``duration``, and channels that809    are bad for at least ``min_count`` chunks are returned.810 811    Channels marked as *flat* in step 2 are excluded from all subsequent steps812    of noisy channel detection.813 814    This algorithm gives results similar to, but not identical with,815    MaxFilter. Differences arise because MaxFilter processes on a816    buffer-by-buffer basis (using buffer-size-dependent downsampling logic),817    uses different filtering characteristics, and possibly other factors.818    Channels that are near the ``limit`` for a given ``min_count`` are819    particularly susceptible to being different between the two820    implementations.821 822    .. versionadded:: 0.20823    NZlowpassZbelowzequal toz9The input data has already been low-pass filtered with a z Hz cutoff frequency, which is z the requested cutoff of z" Hz. Not applying low-pass filter.zApplying low-pass filter with z Hz cutoff frequency ...)Zl_freq�h_freqTr�r�r�r��	min_countz8Scanning for bad channels in %d interval%s (%0.1f s) ...r)r�ryrzr{r|r}r�r�r�r�r�r�r�r�rr�r�r�gV瞯�<g��FF�g<)r�r�cs(g|]}|�dvr�dn�d�qS)r�r�r�rOrR)�flat_limitsr�rOrVrW�824s��z-find_bad_channels_maxwell.<locals>.<listcomp>��r�r	)Z825fill_valuerFr�rar�)�826first_sampr`r@z        Interval Z3dz: rsrtrcsg|]	}�j�|�qSrOrP)rSZ827chunk_flat)�good_meg_picksrKrOrVrW�828s�csg|]}�j|�vr|�qSrOrPrR)�chunk_flatsrKrOrVrW�829sz            Flat (ruz): <all>z[All-flat segment detected, all channels will be marked as flat and processing will stop (t=r!z�). Consider using annotate_amplitude before calling this function with skip_by_annotation="bad_flat" (or similar) to properly process all segments.r~�erDcs(g|]}�j|�jd��v�qS)rD)rQrarR)r6�chunk_noisy�	chunk_rawrKrOrVrWs���r`z            Flat (%2d): %srvz            Bad:       r�c3� �|]\}}|�kr|VqdSrVrO)rS�br��r0rOrVr�0��z,find_bad_channels_maxwell.<locals>.<genexpr>c��j�|�SrV�rQr�r��rKrOrV�<lambda>1�z+find_bad_channels_maxwell.<locals>.<lambda>)r�c3r:rVrO)rS�fr�r<rOrVr�4r=cr>rVr?r�r@rOrVrA5rBz    Static bad channels:  z    Static flat channels: r�)rQ�ch_typesrp�scores_flatZlimits_flat�scores_noisyZlimits_noisy)9rar�r>r`r��filterr�rr�r�r�rrgrhr�r�r9rir:r�rr�rEr�rcr8rQZget_channel_types�fullr0Z	full_liker��get_datar&r4r�r#rZreshaper r�rbrArrr?r=r�r�ZptprArGZargmaxr�r%rjr)?rK�limitrkr0Z
return_scoresryrzr{r|r}r�r�r�r�r�r�r�r/r�r�r@Zfreq_locrzr
rZstartsZstops�steprdr�ssZ	noisy_chsZflat_chsZthese_limitsZ	flat_stepZ	all_flatsrprQrDrErFZthresh_flatZthresh_noisy�sirrZn_iterrrrrZ	flat_stopr��deltarZrange_Zcs_picksrGrr r�Zmax_r�ZscoresrO)r6r8r9r1r5r0r�rKrV�find_bad_channels_maxwell�	sj'����830�831832���833���.�834��� "�835��836837838839�840�841�842	rOcs�t�}d}|durst|�}|d�|d�vr#t�dd��t|dd�}ttt|�t����}t|�dkr<td|����ttt��t|���}t|�dkrUtd|����fdd�|D�}|d	|dd�|f}|d	j	�843�|d	<||fS)844NZproj_items_chsrTrz+Missing MEG channels in cross-talk matrix:845z$Not all cross-talk channels in raw:846cr�rOr�r��Zctc_chsrOrVrWdr�z$_read_cross_talk.<locals>.<listcomp>Z	decoupler)r�rr8rbr�rcrir�rArFZtocsc)r}rQr�r�r�Z	ctc_picksrOrPrVr�Ss$r�cCs�t|td�tt�t|d�df�|��dd�}t�d�t	||||||d||||	|847d�}
|
d	|d848dd�\}}}}}||||fS)
a8Compute the SSS basis for a given measurement info structure.849 850    Parameters851    ----------852    %(info_not_none)s853    %(origin_maxwell)s854    %(int_order_maxwell)s855    %(ext_order_maxwell)s856    %(calibration_maxwell_cal)s857    %(coord_frame_maxwell)s858    %(regularize_maxwell_reg)s859    %(ignore_ref_maxwell)s860    %(bad_condition_maxwell_cond)s861    %(mag_scale_maxwell)s862    %(extended_proj_maxwell)s863    %(verbose)s864 865    Returns866    -------867    S : ndarray, shape (n_meg, n_moments)868        The basis that can be used to reconstruct the data.869    pS : ndarray, shape (n_moments, n_good_meg)870        The (stabilized) pseudoinverse of the S array.871    reg_moments : ndarray, shape (n_moments,)872        The moments that were kept after regularization.873    n_use_in : int874        The number of kept moments that were in the internal space.875 876    Notes877    -----878    This outputs variants of :math:`\mathbf{S}` and :math:`\mathbf{S^\dagger}`879    from equations 27 and 37 of :footcite:`TauluKajola2005` with the coil scale880    for magnetometers already factored in so that the resulting denoising881    transform of the data to obtain :math:`\hat{\phi}_{in}` from equation882    38 would be::883 884        phi_in = S[:, :n_use_in] @ pS[:n_use_in] @ data_meg_good885 886    .. versionadded:: 0.23887 888    References889    ----------890    .. footbibliography::891    rarQr�Fr�zComputing Maxwell basisN)rKryrzr{r|r�r�r�r�r�r�r�r�r^r�r)892r<rr&rgr�rir`r>rar�)raryrzr{r|r�r�r�r�r�r�r@rKr�r3r(r)r�r*rOrOrV�compute_maxwell_basisks.;$893���rQ)rnrorpNNNrqrrNrsFrtNTFrurvrOTrxN)rnrorpNNNrqrrNrsFrtNTFrurvrOrsTrxN)TrV)FN)rur�)TTTT)Fru)Nru)r+r,r-FrnrorpNNrrrsFrtNrurvr.rOrxN)rnrorpNrrrsTrtrurON)��collectionsr�	functoolsr�mathr�osrr�pathlibr�numpyrgZscipyrZ
scipy.specialrr�r894Z_fiff.compensatorrZ_fiff.constantsrr
Z_fiff.meas_inforrZ895_fiff.pickrrZ_fiff.proc_historyrZ896_fiff.projrZ	_fiff.tagrrZ_fiff.writerrZ_olarrrrErZbemrZchannels.channelsrr�fixesrr r!�forwardr"r#r$�ior%r&Zsurfacer'Z897transformsr(r)r*r+r,r-r.r/r0r1r2r3r4r5r6�utilsr7r8r9r:r;r<r=r>r?r@rArmr�r�r�r�r4r�r�rr�r�rrrr�r�r�r�r�r�r�r�r�r�r�r�r�rir�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rxr898r�rr�r�r�r#r�rOr�rQrOrOrOrV�<module>sfD4��Z��h%$A7c�"=899 900901hS		902T903.a904b905+�~�
Aluode/PerceptionLabPortable · CoolFace