
    e
                        d Z ddlZddlZddlZddlZddlZddlm	Z	  ej                           ej                         Zej                  d       ej                  dd       ej                  dd        G d dej                         Zdd	Z eej(                        d
kD  rej(                  d
   ZnddZej,                  j/                  e      sGe	j0                  j3                  dddd      \  ZZes ej8                  d       n e eedz                ej<                  ed      Z e       Z e jC                  ed          ejE                  e        e#dk(  r ejH                          yy)a   
In this example we create a subclass of PlotCurveItem for displaying a very large 
data set from an HDF5 file that does not fit in memory. 

The basic approach is to override PlotCurveItem.viewRangeChanged such that it
reads only the portion of the HDF5 data that is necessary to display the visible
portion of the data. This is further downsampled to reduce the number of samples 
being displayed.

A more clever implementation of this class would employ some kind of caching 
to avoid re-reading the entire visible waveform at every update.
    N)	QtWidgetsz pyqtgraph example: HDF5 big dataFi  c                   $    e Zd Zd Zd Zd Zd Zy)HDF5Plotc                 f    d | _         d| _        t        j                  j                  | g|i | y )Ni'  )hdf5limitpgPlotCurveItem__init__)selfargskwdss      9/usr/lib/python3/dist-packages/pyqtgraph/examples/hdf5.pyr   zHDF5Plot.__init__    s.    	

!!$666    c                 2    || _         | j                          y N)r   updateHDF5Plot)r   datas     r   setHDF5zHDF5Plot.setHDF5%   s    	r   c                 $    | j                          y r   )r   )r   s    r   viewRangeChangedzHDF5Plot.viewRangeChanged)   s    r   c                 r   | j                   | j                  g        y | j                         }|y |j                         d   }t	        dt        |d         dz
        }t        t        | j                         t        |d   dz               }t        ||z
  | j                  z        dz   }|dk(  r| j                   || }d}n/d||z
  |z  z   }t        j                  |dz  | j                   j                        }|}	d}
d|z  |z  }|	|dz
  k  r| j                   |	t        ||	|z          }|	t        |      z  }	|d t        |      |z  |z   j                  t        |      |z  |      }|j	                  d      }|j                  d      }|||
|
|j                  d   dz  z   d<   ||d|
z   d|
z   |j                  d   dz  z   d<   |
|j                  d   dz  z  }
|	|dz
  k  r|d |
 }|dz  }| j                  |       | j                  |d       | j                          | j!                  |d       y )Nr         )dtype@B )axisg      ?)r   setData
getViewBox	viewRangemaxintminlenr   npzerosr   reshapeshapesetPosresetTransformscale)r   vbrange_startstopdsvisibler+   samples	sourcePtr	targetPtr	chunkSizechunkchunkMaxchunkMins                  r   r   zHDF5Plot.updateHDF5Plot,   sK   99LL__: "Ac&)nQ&'3tyy>3vay{#34 $u*

*+a/7iid+GE DJ2-.Ghhwqy		@GII !"*Id1f$		)CYy5H,IJSZ'	 4E
B"45==c%j"nbQ !99!9, 99!9, CK	)EKKN1,<"<Q>?FN)AiKAq0@$@BCU[[^A--	 d1f$  jy)GHEWE1

5!r   N)__name__
__module____qualname__r   r   r   r    r   r   r   r      s    7
5r   r   c                    t         j                  j                  d      j                  t         j                        }t        j                  dd      }|j                  d|dd       |d   }| |j                  |j                  z  z  }t        j                  d	d
|      5 }t        |      D ]  }|j                  d
   |j                  d
   z   g}|j                  |       |||j                  d
    d |dz  }|j                         s]|j!                          t#        j$                  d       t'        j(                           |dz  }ddd       |j!                          y# 1 sw Y   xY w)zzCreate a large HDF5 data file for testing.
    Data consists of 1M random samples tiled through the end of the array.
    r   )size	test.hdf5wr   Tr   )r   chunksmaxshapezGenerating test.hdf5...r   Nr   )r%   randomnormalastypefloat32h5pyFilecreate_datasetr>   itemsizer	   ProgressDialogranger(   resizewasCanceledcloseosremovesysexit)	finalSizer6   fr   nChunksdlginewshapes           r   
createFilerZ   f   s5   
 II'*11"**=E		+s#AV%wGV9DEJJ78G			4a	A 
Sw 	A

1A67HKK!%*D%++a.!"1HC 			+&
	 	q
 GGI
 
s   !A(E#
A E##E,r   r?   zCreate HDF5 Dataset?zeThis demo requires a large HDF5 array. To generate a file, enter the array size (in GB) and press OK.g       @g    eArr   __main__)i 5w)%__doc__rP   rR   rG   numpyr%   	pyqtgraphr	   pyqtgraph.Qtr   mkQAppplotpltsetWindowTitleenableAutoRange	setXRanger
   r   rZ   r$   argvfileNamepathisfileQInputDialog	getDoubler>   okrS   r"   rH   rU   curver   addItemr9   execr<   r   r   <module>rq      sP   
 
    " 			 bggi   5 6   E5 ! a Br BN2 sxx=1xx{HH77>>(#))33D:P  Sz  |  @bCHHQKs48}% DIIh
 ai  E zBGGI r   