ó
    §½Àjä  ã            
       ó²  • S r SSKrSSKrSSKrSSKJrJr  SSKJ	r	J
r
Jr  SSKJrJr  SSKJrJr  \" \R&                  5      S:”  a  \R&                  S   OSr\R+                  S	5      (       a  \" \S
S 5      OSr\S;   r\(       d  \(       a  SO\" \5      r\R4                  " S5      r\R8                  R;                  \SS\ 35      r\	" SSS/SSSS9r\R4                  " S5      r S r!S r"S r#\$S:X  aa  \RJ                  " \SS9  \" 5       RL                  RO                  5       r(\)" \" S
S9" S \( 5       5      5      r*\+" S\ S\* S\" \(5       35        gg) aÕ  Glimpse features (Raghavan et al.: glimpsed vs masked speech are encoded differently; the ignored talker is mostly
encoded in its glimpses, the attended talker also in its masked parts).

Per trial, from the RAW 128-Hz envelopes of both streams (unfiltered gammatone^0.6, supplied):
  level  L_s(t) = (20/0.6) log10(causal 1st-order smoothing (25 ms) of env_s)     (env ~ amplitude^0.6 -> dB)
  mask   m_s(t) = 1 if L_s(t) - L_other(t) > THR dB (talker s clearly louder: a glimpse of s), else 0
  glim_s = causal Butterworth band-pass 1-9 Hz (order 2) of env_s * m_s
  mask_s = causal band-pass of env_s * (1 - m_s)                                    (the masked part of s)
then 128 -> 32 Hz and the same 1-s edge trim as the decoder cache (alignment with cache env checked: lag 0).
Everything is CAUSAL (no exempted method is used a second time): smoothing, mask and band-pass only use the past.
Output cache/glimpse<THR>/<key>.npz: glim (T,2), mask (T,2), m (T,2) at 32 Hz; loaded by common_exp.load_trial.
Graded variant ('softW', e.g. soft20): dominance STRENGTH instead of the binary mask, m_s = clip((L_s - L_other) / W dB,
0, 1) (0 when not louder, 1 when >= W dB louder); glim = BP(env m), mask = BP(env (1 - m)) as before.
Normalised variant ('norm'): g_s = (e_s - e_o) / (e_s + e_o + eps) in [-1, 1] on the smoothed envelopes (independent of
the overall loudness; eps = 5% of the CAUSAL running mean (EW, 10 s, past only) of e_s + e_o); m_s = max(g_s, 0);
additionally the dominance target dom = causal band-pass of [g_0, g_1 = -g_0].
Onset variant ('onorm' = norm + relative onsets): o_s = positive first difference of the smoothed envelope (128 Hz);
  odiff = o_0 - o_1 ;  orel = (o_0 - o_1) / (o_0 + o_1 + eps), exactly 0 where neither talker has an onset
  (eps = 5% of the causal running mean (10 s, past only) of o_0 + o_1); both causally band-passed, target pair [x, -x].
  +1: only talker 0 has an onset, -1: only talker 1, 0: equal onsets or none.
'full' = onorm + the RAW envelope difference ediff = e_0 - e_1 (smoothed envelopes, causal band-pass, pair [x, -x]):
the un-normalised counterpart of dom (dom treats 0.9 vs 0.4 and 0.6 vs 0.1 differently, ediff does not).
usage: python build_glimpse.py [THR_dB=10 | softW | norm | onorm | full]é    N)ÚParallelÚdelayed)ÚbutterÚlfilterÚsosfilt)ÚEXPÚ
load_trial)Úload_envÚtrial_indexé   Ú10Úsofté   )ÚnormÚonormÚfullgš™™™™™I¿ÚcacheÚglimpseé   é	   Úbandpassé€   Úsos)ÚfsÚoutputg      Ô¿c                 óx   • [        S[        -
  /S[        * /U 5      n[        R                  " U S   /USS /5      $ )z6Causal EW running mean (10 s) of the samples BEFORE t.r   r   Néÿÿÿÿ)r   ÚA_EPSÚnpÚconcatenate)ÚxÚruns     Úb/root/disk_3tb/EEG-sAAD-Grand-Challenge-Training-Dataset/experiments/decoder_lodo/build_glimpse.pyÚ	past_meanr$   ,   s<   € ä
�1”u‘9�+ ¤E 6˜{¨AÓ
.€CÜ�>Š>˜A˜a™D˜6 3 s¨ 8Ð,Ó-Ð-ó    c                 ó@  • [        S[        -
  /S[        * /[        R                  " U S5      SS9nS n0 n[        (       Ga[  UR                  S5      nUSS2S4   USS2S4   -
  US[        U5      -  -   -  n[        R                  " [        R                  " US5      [        R                  " U* S5      /S5      nU" U5      US'   [        S	:X  a  U" USS2S4   USS2S4   -
  5      US
'   [        S;   a¥  [        R                  " S[        R                  " USUSS S95      nUR                  S5      nU" [        R                  " US:„  USS2S4   USS2S4   -
  US[        U5      -  -   S-   -  S5      5      US'   U" USS2S4   USS2S4   -
  5      US'   OÎS[        R                  " USS2S4   USS2S4   -  5      -  n	[        (       aT  [        R                  " [        R                  " U	[        -  SS5      [        R                  " U	* [        -  SS5      /S5      OD[        R                  " U	[        :„  U	* [        :„  /S5      R                  [        R                   5      nUR#                  [%        [&        X-  SS9[%        [&        U SU-
  -  SS9US9  U$ )z‹e: (N, 2) raw 128-Hz envelopes -> dict of (N, 2) arrays at 128 Hz, all causal: glim, mask, m (+ dom for 'norm',
+ orel, odiff for 'onorm').r   g•Ö&è.>r   ©Úaxisc                 óN   • [        [        [        R                  " X * /S5      SS9$ )Nr   r   r'   )r   ÚBPr   Ústack)r!   s    r#   Ú<lambda>Úfeatures.<locals>.<lambda>6   s   € ”WœR¤§¢¨1¨b¨'°1Ó!5¸AÒ>r%   Ngš™™™™™©?Údomr   Úediff)r   r   g        )r(   Úprependgê-�™—q=ÚorelÚodiffg«ªªªªª@@)ÚglimÚmaskÚm)r   ÚAr   ÚmaximumÚNORMÚsumr$   r+   ÚARGÚdiffÚwhereÚlog10ÚSOFTÚclipÚTHRÚastypeÚfloat64Úupdater   r*   )
ÚeÚsÚpairÚoutÚtotÚgr5   ÚoÚtoÚDs
             r#   ÚfeaturesrM   2   sP  € ô 	�”Q‘�˜!œa˜R˜¤"§*¢*¨Q°Ó"5¸AÑ>€AÙ>€DØ
€CßƒtØ�e‰e�A‹hˆØŠq�!ˆt‰W�qš˜A˜‘wÑ 3¨´	¸#³Ñ)>Ñ#>Ñ?ˆÜ�HŠH”b—j’j  AÓ&¬¯
ª
°A°2°qÓ(9Ð:¸AÓ>ˆÙ˜!“WˆˆE‰
Ü�&‹=Ù ¢! Q $¡¨!ªA¨q¨D©'Ñ 1Ó2ˆC�‰LÜÐ#Ó#Ü—
’
˜3¤§¢¨°¸1¸R¸a¸5Ñ AÓBˆAØ—‘�q“ˆBÙœrŸxšx¨¨Q©°²1°a°4±¸1ºQÀ¸T¹7Ñ1BÀrÈDÔS\Ð]_ÓS`ÑL`ÑG`ÐchÑGhÑ0iÐknÓoÓpˆC�‰KÙ ¢! Q $¡¨!ªA¨q¨D©'Ñ 1Ó2ˆC�‰LøàœŸš !¢A q D¡'¨Aªa°¨d©GÑ"3Ó4Ñ4ˆßQUÒQUŒR�XŠX”r—w’w˜q¤4™x¨¨AÓ.´·²¸¸¼T¹	À1ÀaÓ0HÐIÈ1ÔMÜ—(’(˜A¤™G a R¬#¡XÐ.°Ó2×9Ñ9¼"¿*¹*ÓEð 	
à‡J�J”GœB ¡¨AÑ.´W¼RÀÀaÈ!ÁeÁÐSTÑ5UÐYZ€JÑ[Ø€Jr%   c           	      óN  • [         R                  R                  [        U S-   5      n[         R                  R	                  U5      (       a  g[        [        SU 5      S   5      n[        [        U 5      R                  [        R                  5      5      R                  5        VVs0 s H0  u  p4X4S S S2   SSU-    R                  [        R                  5      _M2     nnn[        US   5      U:X  d   U [        US   5      U45       e[        R                  " U40 UD6  gs  snnf )	Nz.npzr   Úmat_reacÚenvr   é    r3   r   )ÚosÚpathÚjoinÚOUTÚexistsÚlenr	   rM   r
   rA   r   rB   ÚitemsÚfloat32Úsavez)ÚkeyÚpÚTÚkÚvÚFs         r#   Úbuildra   L   së   € Ü
�‰�‰”S˜# ™,Ó'€AÜ	‡w�w‡~�~�a×ÑØÜŒJ�z 3Ó'¨Ñ.Ó/€AÜ=EÄhÈsÃm×FZÑFZÔ[]×[eÑ[eÓFfÓ=g×=mÑ=mÔ=oÔpÒ=o±T°Qˆ‰c�ˆc‰F�2�b˜1‘fÐ×$Ñ$¤R§Z¡ZÓ0Ò	0Ñ=o€AÑpÜˆq�‰y‹>˜QÓÐ8 ¤c¨!¨F©)£n°aÐ 8Ó8ÐÜ‡H‚HˆQÑ�!ÒØùó 	qs   Â'7D!Ú__main__T)Úexist_ok)Ún_jobsc              #   óL   #   • U  H  n[        [        5      " U5      v •  M     g 7f)N)r   ra   )Ú.0r^   s     r#   Ú	<genexpr>rg   Z   s   é € Ð?º$°Qœw¤uœ~¨a×0Ð0º$ùs   ‚"$z: built z of ),Ú__doc__rR   ÚsysÚnumpyr   Újoblibr   r   Úscipy.signalr   r   r   Ú
common_expr   r	   Úcommonr
   r   rW   Úargvr:   Ú
startswithÚfloatr>   r8   r@   Úexpr   rS   rT   rU   r*   r6   r$   rM   ra   Ú__name__Úmakedirsr[   ÚtolistÚkeysr9   ÚnÚprint© r%   r#   Ú<module>rz      sG  ðñLó. 
Û 
ã ß $ß 1Ñ 1ç &ß (á˜Ÿ™“] QÓ&€c‡h�hˆq‚k¨D€ØŸ™¨×/Ñ/�uˆS��ˆW„~°T€Ø
Ð'Ñ'€Þ–t�d¡%¨£*€Ø
�ŠÐ Ó!€Ø‡g�g‡l�l�3˜ 7¨3¨% Ó1€ÙˆA��1ˆv�z c°%Ñ8€Ø‡F‚FÐÓ€ò.òò4ð ˆzÓØ‡K‚K�˜dÒ#Ù‹=×Ñ×#Ñ#Ó%€DÙ‰H˜AÒÑ?¹$Ó?Ó?Ó@€AÙ	ˆG�C�5˜   4©¨D«	 {Ð
3Õ4ð	 r%   