;idZddlZddlZddlZddlZddlZddlZddlmZddl Z ddl m Z m Z mZmZddlmZddl mZmZmZddlmZdd lmZgd Zejddd d ejdd dd ejd ddd ejdd d d ejd dd d ejd d dd ejdddd ejd d d d ejd d d d ejd d d d ejddd d d ZdZdZedee eDZ!de!d<ej"dezdzZ#ej"dezdzZ$dldZ%dmdZ&e#dfdZ'e(e#dfd Z)d!Z*Gd"d#ejZ+d$Z,d%Z-d&Z.dnd(Z/e j0d)Z1e j0d*Z2e j0d+Z3dod,Z4d-Z5dpd/Z6d0Z7d1Z8dqd4Z9d5Z:drd7Z;d8Zd<Z?dtd>Z@d?ZAd@ZBdudAZCdBZDdCZEdDZFdvdEZGeHeIeJe jKLdFddGdHkre jMZGdIZNdwdJZOdKZPdLZQdxdMZRdNZSdydOZTdPZUdzdQZVdRZWdSZXd{dUZYdVZZdWZ[dvdXZ\d|dZZ]d[Z^d\Z_d]Z`d}d^Zad~d`ZbdacdaZddbZedcZfddeZgddfZhddgZiddhZjdiZkGdjdkelZmdS)z functions.py - Miscellaneous functions with no other home Copyright 2010 Luke Campagnola Distributed under MIT/X11 license. See license.txt for more information. N) OrderedDict)QtdebuggetConfigOptionreload) MetaArray)QT_LIBQtCoreQtGui)getCupy)getNumbaFunctions)0siScalesiFormatsiParsesiEvalsiApplyColormkColormkBrushmkPenhsvColor CIELabColor colorCIELab colorDistance colorTuplecolorStrintColorglColor makeArrowPatheqaffineSliceCoords affineSliceinterweaveArraysinterpolateArraysubArraytransformToArraytransformCoordinatessolve3DTransformsolveBilinearTransform clip_scalar clip_array rescaleDataapplyLookupTablemakeRGBAmakeARGB makeQImage imageToArray colorToAlphagaussianFilter downsample arrayToQPathisocurve traceImage isosurfaceinvertQTransform pseudoScattertoposort disconnect SignalBlockd) bgrcmykwdlsuyzafpnµm kMGTPEZYzyzafpnum kMGTPEZYc8g|]}t||dz dzfS)) SI_PREFIXES).0is GC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\pyqtgraph/functions.py rU@s)WWW![^ac1W5WWWiuzb(?P[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)|((?i:nan)|(inf))))\s*((?P[uz]?)(?P\w.*))?$z&(?P[+-]?\d+)\s*(?P[uz]?)(?P.*)$}:Tc "t|tjrt|} t j|sdSn#xYwt ||krd}ndttt j t j t |t j dz dd}|dkrd}n8|dks|dkr d |d zz}n#|rt|dz}nt|dz}d |z}d |z}||fS) u Return the recommended scale factor and SI prefix string for x. Example:: siScale(0.0001) # returns (1e6, 'μ') # This indicates that the number 0.0001 is best represented as 0.0001 * 1e6 = 100 μUnits )rrig"g"@rZirOze%drPg$@) isinstancedecimalDecimalfloatmathisfiniteabsintr+floorlogrQSI_PREFIXES_ASCII)xminVal allowUnicoderGprefm1ps rTrrGs!W_%% !HH}Q '   1vv   DJtxA'7'7'FGGsSS T TAvv R1q55!}  *qs#DD$QqS)D AB RA t9s AArPrZc P|durd}|durd}t|||\}}t|dkr |ddks||z}| dt|zd z} | ||z||fzS|r |d z|z} nd } dt|zd z} | ||z||| t||||| fzS)u Return the number x formatted in engineering notation with SI prefix. Example:: siFormat(0.0001, suffix='V') # returns "100 μV" T FrZreNz%.zg%s%s±z +/- z g%s%s%s%s) precisionsuffixspacerh)rlenstrr) rgrqrrrserrorrhrirlrjfmt plusminuss rTrrjs }} ~~6<00IQ IIMMd1gnnt| }S^^#g-ac4(((   u,IIIS^^#k1ac4HUi`fns}C5D5D5DEE ErVcB|}|`t|dkrM|t| d|krtd|d|d|dt| dz}|dkr|dz }||}|td|z |d }n#t $rd}YnwxYw|) |d }n#t $rd}YnwxYw|}|d |dn||dn|fS) uConvert a value written in SI notation to a tuple (number, si_prefix, suffix). Example:: siParse('100 µV") # returns ('100', 'µ', 'V') Note that in the above example, the µ symbol is the "micro sign" (UTF-8 0xC2B5), as opposed to the Greek letter mu (UTF-8 0xCEBC). Parameters ---------- s : str The string to parse. regex : re.Pattern, optional Compiled regular expression object for parsing. The default is a general-purpose regex for parsing floating point expressions, potentially containing an SI prefix and a suffix. suffix : str, optional Suffix to check for in ``s``. The default (None) indicates there may or may not be a suffix contained in the string and it is returned if found. An empty string ``""`` is handled differently: if the string contains a suffix, it is discarded. This enables interpreting characters following the numerical value as an SI prefix. NrzString 'z%' does not have the expected suffix ''XrZzCannot parse number "%s"siPrefixrrnumber)striprt ValueErrormatchgroup IndexError)rMregexrrrGsipsufs rTrrsk2  A c&kkAoo c&kk\]] v % %*UVUVUVX^X^X^_`` ` mF |m s "|| S AAy3a7888ggj!! ~ ''(##CC   CCC  778  CKbbS ""QT TTs$,C CCC-- C<;C<cdt|||\}}}||}t||S)u Convert a value written in SI notation to its equivalent prefixless value. Example:: siEval("100 μV") # returns 0.0001 )rr)rr)rMtyprrrvalsiprefixvs rTrrs<$AuV<<<C6 CA 1h  rVcj|dkr t|nd}|dkr|d|zzS|dkr |d| zz S|S)z rZr )SI_PREFIX_EXPONENTS)rrns rTrrsQ*2RH%%QA1uuRU{ QR!V| rVc eZdZdZdZdZdS)rcTtj|t|dSN)r QColor__init__rselfargss rTrzColor.__init__s$ dGTN33333rVc*|S)z-Return (r,g,b,a) normalized for use in opengl)getRgbFrs rTrz Color.glColors||~~rVcR|j|j|j|jf|Sr)redgreenbluealpha)rinds rT __getitem__zColor.__getitem__s&A$*di` (int, hues) see :func:`intColor() ` "#RGB" "#RGBA" "#RRGGBB" "#RRGGBBAA" QColor QColor instance; makes a copy. ================ ================================================ z&Not sure how to make a color from "%s"rrzNo color named "%s"N#rrZcg|]}||zSrrrRrgs rTrUzmkColor..s 2 2 21Q 2 2 2rVzUnable to convert z to QColorr?__len__rPcXg|]'}tj|rt|nd(Sr)nprarc)rRas rTrUzmkColor..(s/ B B Bbk!nn +CFFF! B B BrV)rurtr\r rColorsKeyErrorrjoinbytesfromhexisValidr issubdtypetypefloatingrchasattrr TypeErrorinteger)rerrrFqcolrErDrCrs rTrrs & 3SYY >C 4yyA~~ d1gs # #& !QA1vv{{J <q 222JJJ$%:Q%>??TIJts{{s1vv{{abbEq66A:: 2 2 2 2 233A|U]]1%5%566|A<<>> K !Ca!C!C!CDDD Q . . !<Q(( ( ]4Q=="+ 6 6 !DGcM** *A *AAA T!Wi ( ( !47||q  q'1aT!W""!!W 1aT!W""a))nn$ ]4Q=="* 5 5 !DG$$ $C.. Ta1a  Ta 1ann B BaAq\ B B BD < s A>>Bctd|vr |d}nt|dkrc|d}|(tjtjjjSt|tjrtj|S|}nt|dkr|}tjt|S)z | Convenience function for constructing Brush. | This function always constructs a solid brush and accepts the same arguments as :func:`mkColor() ` | Calling mkBrush(None) returns an invisible brush. colorrr) rtr QBrushr r BrushStyleNoBrushr\r)rkwdsrargs rTrr,s $W  Ta1g ;< 4 <== = U\ * * <$$ $EE TQ < ' ''rVc|dd}|dd}|dd}|dd}|dd}|d d}t|dkrr|d }t|tr t d i|St|t jrt j|S|tjj j }n|}t|dkr|}|td }| t|}nt|}t jt j ||} | ||| ||| ||d kr)| tjjj| S)az Convenience function for constructing QPen. Examples:: mkPen(color) mkPen(color, width=2) mkPen(cosmetic=False, width=4.5, color='r') mkPen({'color': "#FF0", width: 2}) mkPen(None) # (no pen) In these examples, *color* may be replaced with any arguments accepted by :func:`mkColor() ` rNwidthrstyledashcosmeticThsvrrLg@r)getrtr\dictrr QPenr rPenStyleNoPenrrr setCosmeticsetStylesetDashPattern setCapStyle PenCapStyleRoundCap) rkargsrrrrrrrpens rTrrAs IIgt $ $E IIgq ! !E IIgt $ $E 99VT " "DyyT**H ))E4 C 4yyA~~1g c4  <<3<<  c5: & & :c?? " [I&,EEE 4yy1}} }  # *U\%((% 0 0COOH  U  4    s{{  -6777 JrV?cFtj||||S)zEGenerate a QColor from HSVa values. (all arguments are float 0.0-1.0))r rfromHsvF)huesatrrs rTrr{s < c3 6 66rV))g7d?g,C?gv?)gz6?g,C?g]m{?)gN@aÓ?g2%䃾?"~j?))g!rh @g) 0gCl߿)g鷯gjt?g_L?)gPkw?g&1ʿgx?)rrgw-!l?ctjd|dzdz }|dxx|dz z cc<|dxx|dz zcc<t|D]+\}}|dkr||dz||<||d z d z ||<,t|z}t|z}tjd}t|d dD]"\}}|d krd |dzzdz ||<d|z||<#t |dd}tjj g||RS)u Generates as QColor from CIE L*a*b* values. Parameters ---------- L: float Lightness value ranging from 0 to 100 a, b: float (green/red) and (blue/yellow) coordinates, typically -127 to +127. alpha: float, optional Opacity, ranging from 0 to 1 Notes ----- The CIE L*a*b* color space parametrizes color in terms of a luminance `L` and the `a` and `b` coordinates that locate the hue in terms of a "green to red" and a "blue to yellow" axis. These coordinates seek to parametrize human color preception in such a way that the Euclidean distance between the coordinates of two colors represents the visual difference between these colors. In particular, the difference ΔE = sqrt( (L1-L2)² + (a1-a2)² + (b1-b2)² ) = 2.3 is considered the smallest "just noticeable difference" between colors. This simple equation represents the CIE76 standard. Later standards CIE94 and CIE2000 refine the difference calculation ΔE, while maintaining the L*a*b* coordinates. Alternative (and arguably more accurate) methods exist to quantify color difference, but the CIELab color space remains a convenient approximation. Under a known illumination, assumed to be white standard illuminant D65 here, a CIELab color induces a response in the human eye that is described by the tristimulus value XYZ. Once this is known, an sRGB color can be calculated to induce the same response. More information and underlying mathematics can be found in e.g. "CIELab Color Space" by Gernot Hoffmann, available at http://docs-hoffmann.de/cielab03022003.pdf . Also see :func:`colorDistance() `. rPtrrrAgI_{?{a?S%@Ngsåi?zG?g?)\(?ףp= )@r) rfull enumerate VECTOR_XYZnMATRIX_RGB_FROM_XYZzerosr,r rfromRgbF) LrrCrvec_XYZidxrvec_RGBarr_sRGBs rTrrsH\ga1b5#''G AJJJ!c'JJJ AJJJ!c'JJJg&&;;S =="3<?GCLL#CL61U:GCLLG#G#W,Gx{{Hwrr{,,((S ??!C%L058HSMM!CKHSMM8S#//H < 48 4U 4 4 44rVc|dd}tjd}t|D]"\}}|dkr|dzdz dz||<|dz ||<#t|z}|t z }t|D]+\}}|dkr||d z||<d ||zd z||<,tjd |d zdz d|d|d z zd|d |dz zg}|S)a Describes a QColor by an array of CIE L*a*b* values. Also see :func:`CIELabColor() ` . Parameters ---------- qcol: QColor QColor to be converted Returns ------- np.ndarray Color coordinates `[L, a, b]`. NrPg }ڵ?rrg333333@rg2#?gUUUUUU?rrrrrrrrAr)rrrrMATRIX_XYZ_FROM_RGBrarray)rsrgbrrrrvec_XYZ1vec_Labs rTrrs3 <<>>"1" DhqkkGt%%''S # $ $ Y-3GCLL;GCLL!G+G$Hh''99S >>$SMC0HSMM!(3-/&8HSMMh hqkB x{Xa[() x{Xa[()+--G NrVCIE76c|}t|dkrtjgtS|dkrtg}d}|D]Y}t |}||}t jtj||z dz}| ||}Ztj|Std|d)a Returns the perceptual distances between a sequence of QColors. See :func:`CIELabColor() ` for more information. Parameters ---------- colors: list of QColor Two or more colors to calculate the distances between. metric: str, optional Metric used to determined the difference. Only 'CIE76' is supported at this time, where a distance of 2.3 is considered a "just noticeable difference". The default may change as more metrics become available. Returns ------- List The `N-1` sequential distances between `N` colors. rdtyperNrzMetric z is not available.) upperrtrrr_rr`sqrtsumappendr)colorsmetricdistlab1collab2dEs rTrrs&\\^^F 6{{Qrx%8888   Cs##D|BFT$YN4466B KKOOODDx~~ 9v999 : ::rVc*|S)z&Return a tuple (R,G,B,A) from a QColor)getRgbrFs rTrrs 88::rVc&dt|zS)z(Generate a hex string code from a QColorz%02x%02x%02x%02x)rr s rTrrs  1 %%rV hc t|}t|}t|||zz} | |z} | |z} |dkr|| ||z |dz zzz} n|} || ||z z|zz} tj| || |S)a Creates a QColor from a single index. Useful for stepping through a predefined list of colors. The argument *index* determines which color from the set will be returned. All other arguments determine what the set of predefined colors will be Colors are chosen by cycling across hues while varying the value (brightness). By default, this selects from a list of 9 hues.r)rcr rfromHsv)indexhuesvaluesmaxValueminValuemaxHueminHuerrrindhindvrhs rTrr$s t99D [[F e**v &C :D $;D zz t 1vax@A A $&-(T11A <  35 1 11rVcBt|i|}|S)z Convert a color to OpenGL color format (r,g,b,a) floats 0.0-1.0 Accepts same arguments as :func:`mkColor `. )rr)rrrFs rTrr:s$ A 99;;rVc|,|tjtj|dzz}tj}|dd||| |C||tjtj|zz }||dn|dz}|||z tjtj|zz }||| |||z| |||z||||||||dd|S)a Construct a path outlining an arrow with the given dimensions. The arrow points in the -x direction with tip positioned at 0,0. If *headWidth* is supplied, it overrides *tipAngle* (in degrees). If *tailLen* is None, no tail will be drawn. N?r)r`tanradiansr QPainterPathmoveTolineTo)headLen headWidthtipAngletailLen tailWidth baseAnglepathinnerYs rTr r Ds`dht|HsN'C'CDDD    DKK!KK)$$$9tx Y0G0G'H'HHH FAS Ii/48DLur| S| tj urt?| St| tjs%tC| d r| "d r{ |j|jkrdSn#YdSxYwtC| d r;| "d r&| #$S| $StKd t=t| z) aThe great missing equivalence function: Guaranteed evaluation to a single bool value. This function has some important differences from the == operator: 1. Returns True if a IS b, even if a==b still evaluates to False. 2. While a is b will catch the case with np.nan values, special handling is done for distinct float('nan') instances using math.isnan. 3. Tests for equivalence using ==, but silently ignores some common exceptions that can occur (AtrtibuteError, ValueError). 4. When comparing arrays, returns False if the array shapes are not the same. 5. When comparing arrays of the same shape, returns True only if all elements are equal (whereas the == operator would return a boolean array). 6. Collections (dict, list, etc.) must have the same type to be considered equal. One consequence is that comparing a dict to an OrderedDict will always return False. TF)rP)moduleNz#failed to evaluate equivalence for:z a:z b: implementsr z== operator returned type %s)&r\r_r`isnanrndarrayr rshaperrrtsetkeysitemsr!rsys version_infoziplisttuplewarningscatch_warnings __enter__ ExceptionrAttributeError__exit__printruboolbool_rr/asarrayallr) rrCaIsArrbIsArrrIra_itemb_itemv1v2catcherrots rTr!r!_s  Avvt!U 1e 4 4 :a== TZ]] 4BJ 2 3 3F BJ 2 3 3F&d1gga00u &ag00AGqw4F4Fu!T z!T22  77d1gg  Q3q66!1!15 qvvxx==CMM ) )5GGII  DAqa1;; uu  a % % !)9V)C)C"%aggii";"; ! !&&))! 55!t!dE]## 1tUm(D(D 77d1gg  Q3q66!1!15AYY  EBrb":: uu t/ .b999G          GGG  qD  '     T4 . . . . .    3444 fc$q''llCFF+++ fc$q''llCFF+++       T4 . . .     T4 . . . .  QADyy bhAww Arz " " Gwq,'?'? GALLQ\D]D] G w!'!!u" 55 A| $ $ k)B)B 99;;??$$ $5577N6T!WWEFFFsU+.LL3 L)&L3(L)) L32P3O#P"BO##PPR**R/ct|t|krtdt|t|krtd|D]1}t|t|krtd2tttj|}t |tjst j|}t |tjst j|}t|fdt|zz|_ tj td|D}|tj df| tftj ft|zzzd}||z }|S) zQReturn the array of coordinates used to sample data arrays in affineSlice(). z(shape and vectors must have same length.z&origin and axes must have same length.z(each vector must be same length as axes.rc.g|]}td|Sr)slicers rTrUz%affineSliceCoords..s 555!51::555rV.raxis)rtr>r9maprceilr\r1rr2mgridr:newaxis transposeEllipsisr)r2originvectorsaxesrgridrgs rTr"r"s 5zzS\\!!BCCC 6{{c$ii@AAA HH q66SYY  FGG G  RWe$$ % %E grz * *$(7## fbj ) )"&!!II<$s5zz/1FL 8E55u55566 7D bjn  1 1 3 3XK2:-PSTYPZPZBZ4Z [ [``fg`hhAKA HrVFc t||||}tt|j} |D]} | | t |t | z} || }|dkr ddl} n#t$rtdwxYw|j t|d} tj t || z|j }tj| D],}tf|z}| jj|||fd|i|||<-nJt td|jdz}t%||||}tt|j}g}tt'|D]a}| |t|t|z z}||||bt ||z}||}|r||fS|S) a Take a slice of any orientation through an array. This is useful for extracting sections of multi-dimensional arrays such as MRI images for viewing as 1D or 2D data. The slicing axes are aribtrary; they do not need to be orthogonal to the original data or even to each other. It is possible to use this function to extract arbitrary linear, rectangular, or parallelepiped shapes from within larger datasets. The original data is interpolated onto a new array of coordinates using either interpolateArray if order<2 or scipy.ndimage.map_coordinates otherwise. For a graphical interface to this function, see :func:`ROI.getArrayRegion ` ============== ==================================================================================================== **Arguments:** *data* (ndarray) the original dataset *shape* the shape of the slice to take (Note the return value may have more dimensions than len(shape)) *origin* the location in the original dataset that will become the origin of the sliced data. *vectors* list of unit vectors which point in the direction of the slice axes. Each vector must have the same length as *axes*. If the vectors are not unit length, the result will be scaled relative to the original data. If the vectors are not orthogonal, the result will be sheared relative to the original data. *axes* The axes in the original dataset which correspond to the slice *vectors* *order* The order of spline interpolation. Default is 1 (linear). See scipy.ndimage.map_coordinates for more information. *returnCoords* If True, return a tuple (result, coords) where coords is the array of coordinates used to select values from the original dataset. *All extra keyword arguments are passed to scipy.ndimage.map_coordinates.* -------------------------------------------------------------------------------------------------------------------- ============== ==================================================================================================== Note the following must be true: | len(shape) == len(vectors) | len(origin) == len(axes) == len(vectors[i]) Example: start with a 4D fMRI data set, take a diagonal-planar slice out of the last 3 axes * data = array with dims (time, x, y, z) = (100, 40, 40, 40) * The plane to pull out is perpendicular to the vector (x,y,z) = (1,1,1) * The origin of the slice will be at (x,y,z) = (40, 0, 0) * We will slice a 20x20 plane from each timepoint, giving a final shape (100, 20, 20) The call for this example would look like:: affineSlice(data, shape=(20,20), origin=(40,0,0), vectors=((-1, 1, 0), (-1, 0, 1)), axes=(1,2,3)) rrNz]Interpolating with order > 1 requires the scipy.ndimage module, but it could not be imported.rorderr)r_)r"r9rangendimremover:rX scipy.ndimage ImportErrorr2rtremptyrndindexrYndimagemap_coordinatesr%minrr)datar2rZr[r\r_ returnCoordsrrgtrAxaxtr1scipy extraShapeoutputindsrtrtrbrStr2s rTr#r#sN^ %$77A di  ! !D B ++d #C >>#  D qyy     }~~ ~ ZD + %,,34:FFFJ + \ \D+$C7%-7S 1[[E[UZ[[F3KK \ 5AF## $ $t +!$ BuEEE eFK  ! !B C 3t99  iillc%jjT23 # 3 B--C  c " "F{ s BB(ctd|D}tj|f|dj}t |}t |D] \}}|||d|<|S)a Parameters ---------- args : numpy.ndarray series of 1D numpy arrays of the same length and dtype Returns ------- numpy.ndarray A numpy array with all the input numpy arrays interwoven Examples -------- >>> result = interweaveArrays(numpy.ndarray([0, 2, 4]), numpy.ndarray([1, 3, 5])) >>> result array([0, 1, 2, 3, 4, 5]) c3$K|] }|jV dSr)sizers rT z#interweaveArrays..Os$$$!qv$$$$$$rVrrN)rrrerrtr)rrxresultrrrs rTr$r$:sx* $$t$$$ $ $D XtgT!W] 3 3 3F D A!$!! u uxax MrVrc|dvrtd|ztj}|j}|jd}||krt dt j|jddt}|dkrt j | tt|D]@}d|fdkd|f|j|d z kz} dd|f| <|| z}A|tfd tjdD} nr|d krkt jtd|d zf|z} t j| t} | d z} t j| t jdf| t jdfg}g}t|D]}| d|fdk|d|f|j|d z kz} || z}| | d|f|j|kz} |d|f| |}d||dk<d|||j|k<||||t|}|t j|f|jzt*}|| z }t|D]}| || |jd |jd z zz}||d|fzd |z d |d|fz zz}||jd |jd z |jz zz}|||<t j|d }||z} t|D]}| d } ||jdkr|| |<n |d ur|| dd<|| S)a N-dimensional interpolation similar to scipy.ndimage.map_coordinates. This function returns linearly-interpolated values sampled from a regular grid of data. It differs from `ndimage.map_coordinates` by allowing broadcasting within the input array. ============== =========================================================================================== **Arguments:** *data* Array of any shape containing the values to be interpolated. *x* Array with (shape[-1] <= data.ndim) containing the locations within *data* to interpolate. (note: the axes for this argument are transposed relative to the same argument for `ndimage.map_coordinates`). *default* Value to return for locations in *x* that are outside the bounds of *data*. *order* Order of interpolation: 0=nearest, 1=linear. ============== =========================================================================================== Returns array of shape (x.shape[:-1] + data.shape[x.shape[-1]:]) For example, assume we have the following 2D image data:: >>> data = np.array([[1, 2, 4 ], [10, 20, 40 ], [100, 200, 400]]) To compute a single interpolated point from this data:: >>> x = np.array([(0.5, 0.5)]) >>> interpolateArray(data, x) array([ 8.25]) To compute a 1D list of interpolated locations:: >>> x = np.array([(0.5, 0.5), (1.0, 1.0), (1.0, 2.0), (1.5, 0.0)]) >>> interpolateArray(data, x) array([ 8.25, 20. , 40. , 55. ]) To compute a 2D array of interpolated locations:: >>> x = np.array([[(0.5, 0.5), (1.0, 2.0)], [(1.0, 1.0), (1.5, 0.0)]]) >>> interpolateArray(data, x) array([[ 8.25, 40. ], [ 20. , 55. ]]) ..and so on. The *x* argument may have any shape as long as ```x.shape[-1] <= data.ndim```. In the case that ```x.shape[-1] < data.ndim```, then the remaining axes are simply broadcasted as usual. For example, we can interpolate one location from an entire row of the data:: >>> x = np.array([[0.5]]) >>> interpolateArray(data, x) array([[ 5.5, 11. , 22. ]]) This is useful for interpolating from arrays of colors, vertexes, etc. rrz/interpolateArray requires order=0 or 1 (got %s)z3x.shape[-1] must be less than or equal to data.ndimNrr.rc$g|] }d|f S).r)rRrSxindss rTrUz$interpolateArray..s!JJJaU3q5\JJJrVrOrRF)rrProfilerrar2rronesrBroundastypercr`r:rVrQrd concatenaterWrrer_reshapeprodr)rjrgdefaultr_profndmd totalMaskrmmaskrzfieldsxminxmaxindexes fieldInds axisIndex fieldDatarMdxf1saxrSrs @rTr%r%Wsz FJURSSS >  D B B BwwMNNN D111I zz ""3''))  B#b&MQ&5R=DJrN11 2   Y ' ' ' ' y))*   HbUY_,E : : : X))  B##F2J$4tRWQY7G$GHHBr#b&z/QrTa3r6 l$;;C++ci$!&(382C*DDEECAbEE GAA   Qr ( (AZZQZ''FFDFFF~$ z   F111IDFFF MrVc|tj||d}t|}|jdd}t |jddd}|d}|dddD]}|||zt|ddd}tj|||z||jS)a Unpack a sub-array from *data* using the specified offset, shape, and stride. Note that *stride* is specified in array elements, not bytes. For example, we have a 2x3 array packed in a 1D array as follows:: data = [_, _, 00, 01, 02, _, 10, 11, 12, _] Then we can unpack the sub-array with this call:: subArray(data, offset=2, shape=(2, 3), stride=(4, 1)) ..which returns:: [[00, 01, 02], [10, 11, 12]] This function operates only on the first axis of *data*. So changing the input in the example above to have shape (10, 7) would cause the output to have shape (2, 3, 7). Nrr})bufferr2stridesr) rascontiguousarrayr:r2r9rrr1r)rjoffsetr2striderpritemsizerMs rTr&r&s,   % %fgg .D %LLEABBJ4<"%&&Gr{H AErE]%%x!|$$$$GDDbDM""G :Tz)97RVR\ ] ] ]]rVct|tjrtj|||g|| | g| | | ggSt|tjr:tj|ddSt#d)a Given a QTransform, return a 3x3 numpy array. Given a QMatrix4x4, return a 4x4 numpy array. Example: map an array of x,y coordinates through a transform:: ## coordinates to map are (1,5), (2,6), (3,7), and (4,8) coords = np.array([[1,2,3,4], [5,6,7,8], [1,1,1,1]]) # the extra '1' coordinate is needed for translation to work ## Make an example transform tr = QtGui.QTransform() tr.translate(3,4) tr.scale(2, 0.1) ## convert to array m = pg.transformToArray()[:2] # ignore the perspective portion of the transformation ## map coordinates through transform mapped = np.dot(m, coords) rz;Transform argument must be either QTransform or QMatrix4x4.)r\r QTransformrrm11m21m31m12m22m32m13m23m33 QMatrix4x4 copyDataTorr>)rss rTr'r's4"e&''Wx"&&((BFFHHbffhh7"&&((BFFHHbffhh9WZ\Z`Z`ZbZbdfdjdjdldlnpntntnvnvYwxyyy B( ) )Wx ((001555UVVVrVc h|rD||jdz fttd|jdz z}|jd}t |t jr|}n't|}|d|jddz }|jdkrK|dkrEt j d}|ddddf|ddddf<|dddf|dddf<d|d<|}|jdkrF|dkr@t j d}|ddddf|ddddf<|dddf|dddf<|}| |jd |jdz zz}|t j d f}|ddd f}|dddd f}tj5tjd t ||zd }dddn #1swxYwY||z }|r8|ttd|jdz}|S)a Map a set of 2D or 3D coordinates through a QTransform or QMatrix4x4. The shape of coords must be (2,...) or (3,...) The mapping will _ignore_ any perspective transformations. For coordinate arrays with ndim=2, this is basically equivalent to matrix multiplication. Most arrays, however, prefer to put the coordinate axis at the end (eg. shape=(...,3)). To allow this, use transpose=True. rrNrrPrP)rPrrrrrO.r}ignorerRr)rXrar:r`r2r\rr1r'rrerrWr;r< simplefilterRuntimeWarningr)rscoordsrXrrGm2 translatemappeds rTr(r(!sT!!6;q="2U56;q=;Q;Q5R5R"RSS aB"bj!!  R  mqwqz!|m  w%B!GG Xe__rr"1"uX2A2rr6 bqbdG2A2q5 3  w%B!GG Xe__RaRU8111RaR4BQBqD'111Q3  !'D&+a-0011A BJO $F!!!B$I !!!SbS& A  " "((h777F(Q''((((((((((((((( iFF!!%a (<(<"="="DEE Ms(4G((G,/G,cddl}g}||fD]ttjr.lsFTTTa3q688::s1vxxzz3q688::qATTTrVrr) numpy.linalgr\rr1rer_rr`rrlinalgsolve)points1points2numpyptsAmatrixrSrs @rTr)r)^s!  C! c2: & & Ve,,,A!!!BQB$iAaaadGAaaacFFTTTT5QR88TTTUUA 1 Xe__F 1XX<<L&&s1vs1vaaac{;;q MrVcbddl}tjfdtdD}tjfdtdD}tjd}tdD]*}|j||dd|f||<+|S)a Find a bilinear transformation matrix (2x4) that maps points1 onto points2. Points must be specified as a list of 4 Vector, Point, QPointF, etc. To use this matrix to map a point [x,y]:: mapped = np.dot(matrix, [x*y, x, y, 1]) rNcg|]k}||z||dglSrOrgrH)rRrSrs rTrUz*solveBilinearTransform..sYgggYZ71:<<>>'!*,,..0'!*,,..'!*,,..RSTgggrVrcxg|]6}||g7Srr)rRrSrs rTrUz*solveBilinearTransform..s6EEEq71:<<>>71:<<>>2EEErV)rrr)rrrr`rrr)rrrrBrrSs`` rTr*r*ws gggg^cde^f^fggghhA EEEEE!HHEEEFFAXe__F 1XX22L&&q!AAAaC&11q MrVc&||kr|n ||kr|n|S)z? convenience function to avoid using np.clip for scalar values r)rvminvmaxs rTr+r+s ::443::443>rVc.||tj||||S|'tjj|||S|'tjj|||Stjj||||S)Nout)rclipcoreumathminimummaximum)arrrrrs rTr,r,s  | wsD$C0000 |w}$$S$C$888 w}$$S$C$888w}!!#tTs!;;;rV.r)rc"tj||}tj||gddgdgddggd|gdd }|5|D]5\}} || d <| |z} | |z} |t| |d |d | 6 dddn #1swxYwY|S)z(Refer to documentation for rescaleData()r external_loopbufferedreadonly writeonly no_broadcastNunsafei)flagsop_flags op_dtypescasting buffersize.rrr)r empty_likenditerr,) data_inscaler work_dtype out_dtyperdata_outitrgrHs rT_rescaleData_nditerrs}WI666H GX&"J/!l[.$ABZ(    B 77 7 7DAqAcF KA JA1d1gtAwA6666 7777777777777777 Os9BB BcJ||j}ntj|}|jdvrftj|}||j|jf}t |d|jt |d|jf}d|D}tj|tjr tj}n tj}t|}t|}t}|rr| ||krY| |d} | |z} | |z} |t| |d|d| | |d St} | r|| |||||St!||||||S) zReturn data rescaled and optionally cast to a new dtype. The scaling operation is:: data => (data-offset) * scale Nuirrc6g|]}tj|Sr)r`truncrs rTrUzrescaleData..s ,,,! 1 ,,,rVT)copyrF)rrkindiinforimaxcan_castfloat32float64r_r get_array_modulerr,rr-r) rjrrrrrlimrcprnumba_fns rTr-r-s }J HUOO ~hy!! <7CG#D47CG$$c$q'37&;&;;-,t,,, {4$$ Z Z 6]]F %LLE B 6b!!$''2--;;z;55FE   xa$q'x @ @ @ @yu555 ""HJD$##D%DIII tUFJ 4 P PPrVc J|jjdvr|t}t }|rT|||kr;||||d|jddz dStj||ddS)a Uses values in *data* as indexes to select values from *lut*. The returned data has shape data.shape + lut.shape[1:] Note: color gradient lookup tables can be generated using GradientWidget. Parameters ---------- data : np.ndarray lut : np.ndarray Either cupy or numpy arrays are accepted, though this function has only consistently behaved correctly on windows with cuda toolkit version >= 11.1. )rSrWrrrRr)rSmode) rrrrcr rtakerr2r)rjlutrs rTr.r.s zj(({{3 B 7b!!$''2--wwsBGGD!SYq\A-=>>QwGGGwsDqv6666rVc$d|d<t|i|S)z)Equivalent to makeARGB(..., useRGBA=True)TuseRGBA)r0)rrs rTr/r/sDO T "T " ""rVc t}|r||nt}tj} |jdvrt d|jdkr |jddkrt d|*t||j s| |}||j j dkr&| d d|j d zzd z g}ns|j j d kr,d|j d zd z z} | | | d z g}n7|j j d kr| d d g}ntdt||j s| |}||j}|jd kr!|jd dkrtdns|jdkrD||jd krtd|j|jddfkrtdn$tdt#|jz| d|||jd }nd}||j} n#||jd d z } d} |rn|j j dkr^||r7||} |jdkr|| d} |=t||j r|jdkr|jd |jdkrtd||jt0} t3|jdD]^}||\}}||kr||d|z}||z }|d krd n|}t7|d|f||z || | d|f<_| }nU|\}}|d ks||krD||kr||d|z}||z }|d krd n|}t7|||z || }| d|t9||}n?|j |jkr/||d d|j}| d|-||jdddz|j}n|}| d|rgd }nt<jd!krgd"}ngd#}|jdkr t3dD]}||d||f<nj|jdd kr&t3dD]}|d$|d||f<n3t3d |jdD]}|d|f|d||f<| d%|jdkr|jddkrd&}nd'}d|d|df<| dd&}||krOtAtCt0|j"#d(d)krd || dd|df<n d || |df<| d*||fS)+a Convert an array of values into an ARGB array suitable for building QImages, OpenGL textures, etc. Returns the ARGB array (unsigned byte) and a boolean indicating whether there is alpha channel data. This is a two stage process: 1) Rescale the data based on the values in the *levels* argument (min, max). 2) Determine the final output by passing the rescaled values through a lookup table. Both stages are optional. ============== ================================================================================== **Arguments:** data numpy array of int/float types. If levels List [min, max]; optionally rescale data before converting through the lookup table. The data is rescaled such that min->0 and max->*scale*:: rescaled = (clip(data, min, max) - min) * (*scale* / (max - min)) It is also possible to use a 2D (N,2) array of values for levels. In this case, it is assumed that each pair of min,max values in the levels array should be applied to a different subset of the input data (for example, the input data may already have RGB values and the levels are used to independently scale each channel). The use of this feature requires that levels.shape[0] == data.shape[-1]. scale The maximum value to which data will be rescaled before being passed through the lookup table (or returned if there is no lookup table). By default this will be set to the length of the lookup table, or 255 if no lookup table is provided. lut Optional lookup table (array with dtype=ubyte). Values in data will be converted to color by indexing directly from lut. The output data shape will be input.shape + lut.shape[1:]. Lookup tables can be built using ColorMap or GradientWidget. useRGBA If True, the data is returned in RGBA order (useful for building OpenGL textures). The default is False, which returns in ARGB order for use with QImage (Note that 'ARGB' is a term used by the Qt documentation; the *actual* order is BGRA). maskNans Enable or disable masking NaNs as transparent. Converting NaN values to ints is undefined behavior per the C-standard, results may vary across platforms. Highly recommend leaving this option to the default value of True. ============== ================================================================================== rzdata must be 2D or 3DrPrrzdata.shape[2] must be <= 4NrWrrOrrSrCz1levels argument is required for float input typesz"levels argument must have length 2z 2r}z*levels must have shape (data.shape[-1], 2)z0levels argument must be 1D or 2D (got shape=%s).z check inputso@frRzzWhen rescaling multi-channel data, there must be the same number of levels as channels (data.shape[-1] == levels.shape[0])r.z apply levelsr?z apply lutrallocaterrrrPlittle)rrrrP)rrrPr).rzreorder channelsTFr)rrz alpha channel)$r rrrrrarr2r\r1rrrrr>rrreprubytemin_scalar_typer0rianyrercr` nextafterr-r.rr6 byteorderr:rT __version__split)rjrlevelsrrmaskNansrqrxpprofilerMrnanMasknewDatarSrhmaxValrngimgData dst_orderrs rTr0r0sV B&( 0  T " " "bBnG y/000 yA~~$*Q-!++4555 z#rz::hhsmm ~ :?c ! !XXq!dmAo"6q"89::FF Z_ # #DM!Oa'(AXXr1Q3i((FF Z_ # #XXqe__FFOPP P fbj ) )"&!! ]]2: & &F {a <?a  @AA A    ?sx!||Z[[ [ 22G/DJOs**rxx /C/C*((4.. 9q==ffW2f..G fbj ) ) IfkQ.>.>|A$*R.00!]^^^hhtzh55G4:b>** \ \!'V##\\&!F(;;FVm!88aa!,T#a%[%#+vUZ![![![ADD$NFF{{fooV##\\&!F(;;FVm!88aa"4sF%HHH GN c** : ! !774C((//99D GK~((4:bqb>$.bh(?? GJ! LL ( " " LL  LL  yA~~q . .A)-GC1% & & . A!  q 6 6A)-fGC1% & & 6q$*Q-(( 6 6A)-c1fGC1% & & G  yA~~$*Q-1,,%(Yq\!" 88c#r~';';C'@'@AABBWLL01GGQQQ ! , - --.GGYq\) * GO E>rVctjdr-ttj|}n|}|jdd\}}|jd}tj |||||}||_ |S)z Low level function to encapsulate QImage creation differences between bindings. "arr" is assumed to be C-contiguous. PyQtNrr) r startswithrcrrvoidptrr2rr QImagerj)rrwimg_ptrrrJ bytesPerLineqimgs rTndarray_to_qimager s~  bfnnS))** 9RaR=DAq;q>L <A|S 9 9DDI KrVcLtj}d}|jdkrtjjj}n|jdkr||jddk}|jddkr]|durJtj |jdddz|j }||ddddddf<d |dddddf<|}d}ntd |d |rtjjj }n&tjjj }ntd |r|d }|jds2|dur|rdnd}td|ztj|}d}|d|dur|dur|}|dt'||S)a Turn an ARGB array into QImage. By default, the data is copied; changes to the array will not be reflected in the image. The image will be given a 'data' attribute pointing to the array which shares its data to prevent python freeing that memory while the image is in use. ============== =================================================================== **Arguments:** imgData Array of data to convert. Must have shape (height, width), (height, width, 3), or (height, width, 4). If transpose is True, then the first two axes are swapped. The array dtype must be ubyte. For 2D arrays, the value is interpreted as greyscale. For 3D arrays, the order of values in the 3rd axis must be (b, g, r, a). alpha If the input array is 3D and *alpha* is True, the QImage returned will have format ARGB32. If False, the format will be RGB32. By default, _alpha_ is True if array.shape[2] == 4. copy If True, the data is copied before converting to QImage. If False, the new QImage points directly to the data in the array. Note that the array must be contiguous for this to work (see numpy.ascontiguousarray). transpose If True (the default), the array x/y axes are transposed before creating the image. Note that Qt expects the axes to be in (height, width) order whereas pyqtgraph usually prefers the opposite. ============== =================================================================== FrrPNrTrrr?z>Array has only 3 channels; cannot make QImage without copying.zadd alpha channelz$Image array must have ndim = 2 or 3.rrr C_CONTIGUOUSz (try setting transpose=False)rZz Format_ARGB32 Format_RGB32rrXrrrr ) rrrrXrcopied imgFormatd2extras rTr1r1s>nG F|qL'9    =]1%*E = q t||XgmBQB/$6gmLLL$111QQQrr6 111QQQq5  `aaa#$$$  9 +9II +8II>???/##I.. = ( 5==8AI44rEZ[``aa a&w// G     t||%,,.. GFOOO Wi 0 00rVc|}|td||}}|}|}||zdz}t jdr|||ztj |tj  ||f}|ddd|f}|dvrtj }|dz} n%|dvrtj}|dz} ntd||f} | d kr| | fz} || | } | S) NzNull QImage not supportedrOrr)rO )r@rzUnsupported Image Typer)bitsrheightrrdepthr rsetsizer frombufferrruint8uint16view) rrrrJbplr2 logical_bplmemoryrnchanr2rs rTndarray_from_qimager<Is[iikkG4555 ;;==$**,,qA     C JJLLEe)q.K   ! C   ]7"( 3 3 3 ; ;QH E EF AAA| |O $F   (    1222 qDE zz  ++e   $ $U + +C JrVct|}|}||jjkrd|d<|r|}|r|dS|S)a_ Convert a QImage into numpy array. The image must have format RGB32, ARGB32, or ARGB32_Premultiplied. By default, the image is not copied; changes made to the array will appear in the QImage as well (beware: if the QImage is collected before the array, there may be trouble). The array will have shape (width, height, (b,g,r,a)). r?.rPr")r<formatr$r'rrX)imgrrXrrws rTr2r2osk c " "C **,,C cj%%%E  hhjj}}W%%% rVc|t}|jddkr;tj|jdddz|j}||dddf<d|d <|}|t}tj|jddd zt}|}d D]U}|d|f}||}||k}|||z d |z z |d|f|<||k} ||| z |z |d|f| <V|d d z|d <|d dk}d |d |z } d D]W}|d|f|||z | z||z|d|f|<|d |xx|d |d z zcc<Xtj |ddtj S)a Given an RGBA image in *data*, convert *color* to be transparent. *data* must be an array (w, h, 3 or 4) of ubyte values and *color* must be an array (3) of ubyte values. This is particularly useful for use with images that have a black or white background. Algorithm is taken from Gimp's color-to-alpha function in plug-ins/common/colortoalpha.c Credit: /* * Color To Alpha plug-in v1.0 by Seth Burgess, sjburges@gimp.org 1999/05/14 * with algorithm by clahey */ r}rPNrrr.r?r>rPrrrrrRrr) rr_r2rrerrrrrr) rjrr*rrqrSrKrFrimask corrections rTr3r3s ;;u  D z"~ Xdj!nT) < < <3rr6 5  LL  E HTZ^D( 6 6 6E YY[[F 11 QK !H1ugkdQh7c!e TA 1U8|q0c!e UII1I%%,F5M %=C Du d++J 88 &s1u d 3E!H < JeTUhVs1u du dtE{40477 761c " " ) )"( 3 33rVc t}|r||nt}||r |f|jz}|}||z }t |jD]q}||}|dkrt|dz}|| |} | | dz d|dzzz } dg|jz} t| | |<| | } |j ||z} dt|d|jzdzzz } | |j|j|| ||j| | |z|z}t%dg|jz}t%|j ||j |z dd||<|t'|}s||zS) z Drop-in replacement for scipy.ndimage.gaussian_filter. (note: results are only approximately equal to the output of gaussian_filter) rrrrrrrRN)r rrisscalarrameanr`rcarangeexprtrr2rbpifftirfftrfftrQr:)rjsigmarrbaselinefilteredrmrMksizergkernelkshaper2rsls rTr4r4s B&( 0  T " " "bB {{5%49$yy{{HhHDI'' "I 66 AE  IIufe $ $A1a4()) ![[r '' 2&s1vv253./26<< He" (M(M(* FE (K(K)L-/(111 Dkk]TY &x~b)$*R.8dCC2E"II& h rV subsamplecd}t|dr6|dr!|}|tj}t|drat|ds|gt |z}t t |D]}t|||||} |S|dkr|St|j ||z }t|j }|||<| |dz|tdg|j z}td||z||<|t|} t|| _ | |dz} || S|} d| |vrZ|dkr)| |ddd|d|| |d<n+|d kr%t| |d|| |d<t#| | S) zDownsample by averaging points together across axis. If multiple axes are specified, runs once per axis. If a metaArray is given, then the axis values can be either subsampled or downsampled to match. Nr/r rrrrrVr5)info)rr/r7rr1rtr`r5rcr2r9insertrQrar:rHinfoCopyr ) rjrrSxvalsmarSnPtsrMrUd1r*rXs rTr5r5s  Bl##% (D(D% yy$$tYq)$$ CII As4yy!! 3 3AdAaD$q'22DD Avv tz$!# $ $D TZAAdGHHT!VQ ++ "BQQBtH eBiiBQxxBH aB z {{}} tDz ! ! ##'+Dz(';CCaC'@$'GT 8$$,&&'1$t*X2F'J'JT 8$$''''rVc|}tjt|}d||<tj||tj|d}|t|kr ||d|<|SdS)Nr}rr)rrIrtr accumulate searchsorted)rarrfirsts rT_compute_backfill_indicesrcs} 9D )CMM " "CCIJ#3''' OC # #E s8}}FUF  trVc4|jd}|dkrtjSd}|rftj|tj|z}|s)|d}t|}|dkrtjSd}||zdz |z}d}||krt|} t| } ||| dddf<|| dddf<n||| dddf<||| dddf<tj} t| dr| || | | Stj} t| dr| |tj } d} t|D][}t||zt!|dz|z|}|j|jz }|| krMt| dr| |n'| t-j|t| }||||dddf<|||dddf<n&||}|||dddf<|||dddf<| tj} | | | | t| dr| Yd} ]| S) Nrri'rrPreserveresizeclear)r2r r!rrarEnonzerortcreate_qpolygonfndarray_from_qpolygonfrre addPolygon QPolygonFr`rQristopstartrxrffillr QPointF connectPathrg)rgrH finiteCheckr finite_idxra chunksize numchunks minchunkspolyrr*subpolysubpathrrUcurrsizesubarrfivs rT_arrayToQPath_allr}s/  AAvv!###J ;q>>BKNN2||~~ !))++A.JJA1uu!###IY"y0II9""$T**  C1IC1II* C1I* C1I!## 4 # #  LLOOO      DtY QoGGY 3y=#s1ui&7";"; < <7RX% w||~~ % %w)) 9x(((( V^--x888'00  R5F111a4LR5F111a4LLR.CS6F111a4LS6F111a4L ?(**G7### !!! 7G $ $  MMOOOOGG KrVc4|jd}|dkrtjS|)tj|tj|z}tj}t |dr||tj|ddz}tj||}tj||}tt||}td|D} t| t} t drj} ntjffd } |ddD]^\} } t#| }|dkr| || | d|df<| | d|df<| |dz | |dz <|_|ddD]M\} } t#| }|dkr| || | d|df<| | d|df<|N|S) Nrrerc34K|]}t|VdSrrt)rRchunks rTryz'_arrayToQPath_finite..ts(11U111111rVrfc0||Sr)ro)rrrxs rTz&_arrayToQPath_finite..}s Q8J8JrVr}r)r2r r!rrarrerhr r9r8rrirjrfr rprtrk)rgrHrarr*sidxxchunksychunkschunksmaxlenr{subpoly_resizexchunkychunklcrxs @rT_arrayToQPath_finiterasM  AAvv!###;q>>BKNN2    DtY Q :xi  #a 'Dhq$Ghq$G #gw'' ( (F11111 1 1Fv&&G #G , ,Fw!!K &,^%5%5JJJJJ!"+ ! ! [[ 77 rssAvssAvbd|r!t      !+!! [[ 77 rssAvssAv     KrVrEc |jd}|dkrtjSd}t|tjr|d}}d}|dkr}|st ||St j|t j|z}|t j|z }|dk}|rd}d}n||z dkrt |||Sd}|}|dkrt|||Stj} t| dr| |t| dr2td r#d} tj| |} nt!j} | d |d zzd z| dd t)jd || d |d zzd t)jdddt j| gd|d } d} |rP|=t j|t j|z}t j|}|st1|} | || d<|| d<n|| | d<|| | d<|dkrd| dddd<d| dddd<n8|dkr#d| ddd<|dd| ddd<nt3dt| t jrt!j| } | | z | S)a Convert an array of x,y coordinates to QPainterPath as efficiently as possible. The *connect* argument may be 'all', indicating that each point should be connected to the next; 'pairs', indicating that each pair of points should be connected, or an array of int32 values (0 or 1) indicating connections. Parameters ---------- x : np.ndarray x-values to be plotted of shape (N,) y : np.ndarray y-values to be plotted, must be same length as `x` of shape (N,) connect : {'all', 'pairs', 'finite', (N,) ndarray}, optional Argument detailing how to connect the points in the path. `all` will have sequential points being connected. `pairs` generates lines between every other point. `finite` only connects points that are finite. If an ndarray is passed, containing int32 values of 0 or 1, only values with 1 will connect to the previous point. Def finiteCheck : bool, default True When false, the check for finite values will be skipped, which can improve performance. If nonfinite values are present in `x` or `y`, an empty QPainterPath will be generated. Returns ------- QPainterPath QPainterPath object to be drawn Raises ------ ValueError Raised when the connect argument has an invalid value placed within. Notes ----- A QPainterPath is generated through one of two ways. When the connect parameter is 'all', a QPolygonF object is created, and ``QPainterPath.addPolygon()`` is called. For other connect parameters a ``QDataStream`` object is created and the QDataStream >> QPainterPath operator is used to pass the data. The memory format is as follows numVerts(i4) 0(i4) x(f8) y(f8) <-- 0 means this vertex does not connect 1(i4) x(f8) y(f8) <-- 1 means this vertex connects to the previous vertex ... cStart(i4) fillRule(i4) see: https://github.com/qt/qtbase/blob/dev/src/gui/painting/qpainterpath.cpp All values are big endian--pack using struct.pack('>d') or struct.pack('>i') This binary format may change in future versions of Qt rNrfiniterEFg{Gz?reenableExperimentalrrrOz>iz>ii))rFz>i4)rg>f8)rHr)rcountrrgrHpairsrFrrr}z;connect argument must be "all", "pairs", "finite", or array)r2r r!r\rr1rrarr}rrerr internalsget_qpainterpath_element_arrayr QByteArrayrfreplacestructpackr4rErcr QDataStream)rgrHconnectrrr connect_arrayra nonfinite_cnt all_isfiniter* backstorer backfill_idxdss rTr6r6sXn  AAvv!###M'2:&&2!('w H( .'1-- -;q>>BKNN2BF8,,, $)  %GKK Q  ( ('1h77 7G$M% A{333    DtY QtY O4H$I$I  l99$BB%'' QrTA&&&!Q D! 4 4555!AbD&!V[1%=%=>>>mI-W-W-WAL?  {1~~ A6H6(++L ?4X>>LCC\?C\?C'CACA G   C! $SbS)C VWWW)V.//   * * d KrVctj|t |dzdzd}t j|t jdS)NrrOTr)r}r) rcompatrrjrtrr4rr)polylinevps rTrjrj-sY   8==??CMM!OA,=t D DB =2: . . . 6 6w ? ??rVctj}t|dr||n'|t j||S)Nrf)r rlrrfror rp)rxrs rTriri3sW  Hx"". fn&&--- OrVc|j|jcxkr#|jdcxkr|jdksntd|j}t|}t |}||dddf<||dddf<|S)u Utility function to convert two 1D-NumPy arrays representing curve data (X-axis, Y-axis data) into a single open polygon (QtGui.PolygonF) object. Thanks to PythonQwt for making this code available License/copyright: MIT License © Pierre Raybaut 2020. Parameters ---------- x : np.array x-axis coordinates for data to be plotted, must have have ndim of 1 y : np.array y-axis coordinates for data to be plotted, must have ndim of 1 and be the same length as x Returns ------- QPolygonF Open QPolygonF object that represents the path looking to be plotted Raises ------ ValueError When xdata or ydata does not meet the required criteria rz&Arguments must be 1D and the same sizeNr)rxr2rrirj)rgrHrxrr:s rTarrayToQPolygonFr<s8 !&4444AGAJ4444!'!*4444ABBB 6D%%H #H - -FF111a4LF111a4L OrVc |durd}|rtj|jddz|jddzf|j}||ddddf<|d|dddf<|d|dddf<|dddf|dddf<|dddf|dddf<|d|d <|d |d <|d |d <|d|d<|}gddgddgddgddgddggdddgddggdddgddgddgddgddggg}dd gd dgddgddgg}g}||k} tjd|jDtj} tjdt } tddtddg} dD]P} dD]K}| | | | |f| | |f<| d|zz}tj| | | |fd|zz| dLQt| jdD]} t| jdD]}|| | |f}tdt|dD]}|||dz}g}dD]y}|||d}|||d}|| |dz||dzf}|| |dz||dzf}||z ||z z }d|z }|d|z|d|zz| zdz|d|z|d|zz|zdzf}|rjt|jddz td|ddz t|jddz td|ddz f}|rI| ||dkrdndz|||dkrdndz||dzf}| ||fd| |{| |ِ|s|Si}|D]u\}}|d|vr g||d<||d ||g|d|vr g||d<||d ||gvt|D]} || }!n#t $rYwxYw|!D]}"d}# |#|"ddkrnk|"dd}#|#| krnV|"dd}$||#}%|%ddD]1}&|&dd|$kr|"|&dd2||#=~|"dd|"ddkr|!ng}|D]_}"t|"dkr#|"dddddd|"dz}"n|"d}"| d|"D`|s|St)j}|D])}'|j|'d|'ddD] }|j| *|S)a Generate isocurve from 2D data using marching squares algorithm. ============== ========================================================= **Arguments:** data 2D numpy array of scalar values level The level at which to generate an isosurface connected If False, return a single long list of point pairs If True, return multiple long lists of connected point locations. (This is slower but better for drawing continuous lines) extendToEdge If True, extend the curves to reach the exact edges of the data. path if True, return a QPainterPath rather than a list of vertex coordinates. This forces connected=True. ============== ========================================================= This function is SLOW; plenty of room for optimization here. Trrrrr}Nr|)rr)rr})rr})r}r)r}r)r})r}r}rPr)rr)rrcg|]}|dz SrOrrs rTrUzisocurve.....aac...rVrrrrrrrcg|] }|d Srr)rRrls rTrUzisocurve..a s***qad***rV)rrer2rrrobjectrQaddr`rtrirrr9r4rextendpoprr r!r"r#)(rjlevel connected extendToEdger*r* sideTableedgeKeylinesrrrslicesrSj vertIndexsidesrLedgesrrGp1p2rJrKrfirlgridKeypointsrrCrIchainschainrgrHconnectsconnlines( rTr7r7s* t||   Xtz!}Q 1 a8 K K K1R42:1g1ad7 Bx2qt8 111a4j1R47 AAArE{1R48 S'3d84d84uI5  1 1 1 1 1 1 1 1 1 1 1 1 ! I(      G E % " """u{1~&& " "AeAaCj)E1c%jj!,, " "a!e &&A q*1-B q*1-Ba1gqAw./Ba1gqAw./Brbe,AqB1b2a57*Q.41b2a57*Q.4A$  1 aQ!Q@@ 1 aQ!Q@@!&"#E!HaKKqqQ"?5QR8UV;;aa\]A^`efg`hij`j"j Aw<0000 1  S!!!!5 " "<  F##! Q4v  F1Q4Lqt QqE""" Q4v  F1Q4Lqt QqE""""&++--  AYFF    H   EA b ! $$"IaL66"IaL!!9$QQQK//DAwqzQ T!""X...1I Qx{eBil** + E,, u::??!HQRRL2&q1EE!HE **E***++++     D T!Wabb  A DKOOO  Ks4Q== R  R rc|jdkr|j}|tjtjdft }|dtjft }tj||z }|jdkr|d}tj|d}g}t|j dD]}||kt }t|||f}t|ddd}tj} |D])} | j| d | d d D] } | j|  *|| |S) aY Convert an image to a set of QPainterPath curves. One curve will be generated for each item in *values*; each curve outlines the area of the image that is closer to its value than to any others. If image is RGB or RGBA, then the shape of values should be (nvals, 3/4) The parameter *smooth* is expressed in pixels. r.rrRr}rT)rrrrN)raTrrWrr_rbrargminr`r2r4r7r r!r"r#r) imagersmoothdifflabelspathsrSrKrr*rrls rTr8r8o sz{a BJ C/ 0 7 7 > >F #rz/ " ) )% 0 0E 6%,  D {axxQx Yt! $ $ $F E 4:b> " "   QY  u % % 1vv. / /C4dCCC!##  D DKa ! !!""X   Q   T LrVc$%&twtjgdtj}gggdgdgdgdgdgd gd gd gd gd gdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgd gd!gd"gd#gd$gd%gd&gd'gd(gd)gd*gd+gd,gd-gd.gd/gd0gd1gd2gd3gd4gd5gd6gd7gd8gd9gd:gd;gd<gd=gd>gd?gd@gdAgdBgdCgdDgdEgdFgdGgdHgdIgdJgdKgdLgdMgdNgdOgdPgdQgdRgdSgdTgdUgdVgdWgdXgdYgdZgd[gd\gd]gd^gd_gd`gdagdbgdcgddgdegdfgdggdhgdigdjgdkgdlgdmgdngdogdpgdqgdrgdsgdtgdugdvgdwgdxgdygdzgd{gd|gd}gd~gdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgd¢gdâgdĢgdŢgdƢgdǢgdȢgdɢgdʢgdˢgd̢gd͢gd΢gdϢgdТgdѢgdҢgdӢgdԢgdբgd֢gdעgdآgd٢gdڢgdۢgdܢgdݢgdޢgdߢgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdgdg&tjgdgdgdgdgdgdgdgd gd gd gd gd g tj}tjd&Dtj}dg}t ddD]}tjt&|dzftj}tj||k}tj&fd|D||dddf<| t&|df}| ||||||fan t\}}}}|j dstd||k} tjd|j Dtj} tjdt} t!ddt!ddg} dD]u}dD]o} dD]i}| | || | | |f| || |f<|d| z|zz d| zzd|zz}tj| | || |fd|zz| djpvtjd| j Ddgztj$|| }t'|ddD]Z\}%$%fd t dD} $| d| d| d%dfxx|d|zzz cc<[$dk}tj|}|ddddftj}| |j d|j dz|j dz}tj|j d$|dddf|dddf|dddf|dddff<d!D]}|dddf|k}||ddf}|tj|jdd|jztjddfzd"}||}|||j||jzz}|||fxx||z ||z z z cc<|| }|}tj|dftj}d}tj$j$jz}$$t ddD]R}tj||k}|j ddkr/| |dddf|dddf|dddff} ||| }!tj|!d#ddf|ddtjtjddf|!d#ddfd|! |!j d|zf|!j ddz}!|!|tjtjddfzd"}!$|!}"|"j d}#|"||||#z<||#z }T||fS($a Generate isosurface from volumetric data using marching cubes algorithm. See Paul Bourke, "Polygonising a Scalar Field" (http://paulbourke.net/geometry/polygonise/) *data* 3D numpy array of scalar values. Must be contiguous. *level* The level at which to generate an isosurface Returns an array of vertex coordinates (Nv, 3) and an array of per-face vertex indexes (Nf, 3) N(r          093:6?5<< 5 ?6 :39 0   `icjfoell e ofjc i ` r?   PYSZV_U\\U_ V Z S YP  rNrMrLrKrJrIrHrGrFrErDrCrBrAr@r?r>r=r<r;r:r9r8r7r6r5r4r3r2r1r0r/r.r-r,r+r*r)r(r'r&r%r?r$r#r"r!r rrrrrrrrrrrrrrrrrrr r r r r rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr)rrOrP)rrr )rrOrPr rOr)rrr)rrOrPrrr)r rrrrr ) rrOrPrrrOrr rO)rP r)rrOrrOrOr)rr rrrPrO) rrOrrr rOr rOrO)rPrrrOrrP) rrrrrOrrOrOr) rPr rrPrOr rOrr )r rOrrrOrO)rr-rO)rrPrr-rPr)rrr rOrr-) rrr rr-rr-rPr)rrrrOrr-) rPrr-rPrrrrr) r rrr rrrOrr-) rrr rr r-rr-rPr-r r)rOrr-rPrOr) rOrr-rOrrrrr) r rrrOrr-rrPrO) rr-rOr rrOr rOrr rr) rPrrrPrOrr-rOr) rrOrrrrOrrrr-rOr) rr-rOr rrOr rOrrOrrP) rr-rOrrOr r rOr)r r)r rPrrrOrP)rrPrrrPr) rOrPrrOrPrPrPrrP)rrrr rPr) rPrrOrrrrr rP) rPrrrPrrrrr) rrrPrPrrPrPrPrrPrrO)r rPrrrPrO) rrOrrrOrOrr rP) rrPrrrrPrrPrO) rrrPrrPrOrrOrOrrOrP) rrPrOrrrPr rPr) rr rPrrOrrOrrrOrOr) rPrrrPrrOrPrOrrOrrP) rPrrOrPrOrrrOrO)r r-rOrPr-r ) r rPrr rPrPrPr-rP) rr-rOrrr-rrPr-)rrPrPrPrPr-) r r-rOr rPr-rrr) rrrr rPrrPrPrrPr-rP) rOrrrOrrPrOrPr-rrPr) rrrPrrPrPrPrPr-) r-r rPr-rOr rPrOr) r rPr-r r-rr rrrr-rO) rrPrOrrrOrr-rOrrPr-) rOrrrOrr-r-rrP) r rPrOrOrPr-rrrPrrPrO)rPr-rrPrr r-rOrrrrrOrr)rOrrrOrrPrrPrrOrr-rPr-r)rOrrPr-rOrP)rrrP)rrOrPrPrr)r rrrPrr) rrOrPrr rOrPrr)rrrPrrr) rrrPrrrrPrrO) r rrPr rrrrr) rPr rOrPrOrrPrrrPrrO)rrPrOrrrP) rOrrOrOrrrrrP) rrr rrPrOrPrr) rPrrrr rr rOrr rOrO) rrPrOrrPrPrPrrP) rrOrOrrOrPrrPrrPrOr) rPrOrrrPrrrrPrrPr ) rrPr rr rOrOr rO)rPrrrr-rO) rrPrrr-rPrrPr) rr rrPrrrOrr-) rrrPrr r-rr-rPr-r r) rrrrrPrrr-rO) rrrPrPrrrPrrrPrr-) rOrr-r rrPrrrPrrr)r-rPr r-r rrPrr rPr rrrr ) rPrOrr-rOrrrrP) rPrrrr-rrrrrr-rO) rrr rr-rOrrPrOrPrr)r rrr rOrr rrOr-rOrrPrr) rOrr-rPrOrPrPrPrrPrOr)rPrrOrPrOrrrrOr-rOrrrrO)rrPr rrrPrrPrrOrrPrOrr-) rrPr rr rOrr-r r-rOr )rrr rrr) rrrrr rrrOrP) rrrrrrrrr) rOrPrrOrrrOrrrrr) rrr rrrrrr) rPrrOrrr rrr rrr)rrrrrr) rOrPrrOrrrrr) rrr rrrrOrrP) rrOrrrOrOrr rrrr) rPrOrrrrrrrrrr)rrrrrrrrOrrrrOrOrOr) r rrr rPrr rrPrOrrP)rOrOrrOrrrOrrr rrrrr) rPrOrrPrrrrr)rrrOrOrrO) r-rrr-rOrrOr r) rr-rPrrr-rr rrr-r) rrr-rrr-rr-rOrrOr) rrr-rr-rrr-rP) rrrrrrOrrOr rOrr-)rrr rr rrr-r rr rPr-rPr ) r-rOrr-rrrrr)r-rPrrr-r) rrPrOrrrOrrOr rOrr-)rrr-rr-rOrr r-rr-rr rr-)rrOrrr-rOrrr-rr-rrrPrO) rOrrrOrr-rrrrr-r)rOr rrOrr-r rrrOrrPrrPr)rr rrOrr-) r-rOrr-rrrPrOrrOrr)r-rOr)r-rrO)rPrrOrOr-r)rrr rOr-r) rOrr rOrPrrOr-r)rrrrrOr-) rrrrPrrOrrOr-) rr rrrr rrOr-) rrOr-rrrPrrOrPrr rO)r-rrPrrr-) r-rrOr-rrrrr) rr-rrrPr-rrr ) rrrrrOrrr rOrOr-r) rr-rrrr-rrPr-) rr-rrr-rrrOr-rrrO) rrPr-rr-rrrr rrr-) r-rrr-rrOrOrr )rrOrrOrOr) rPrrOrPrrrrr) rOrrOrOrrr rr) r rrr rrPr rPrrOrPr) rrOrrrOrOrrr) rrrrPrrOrrrOrrr) rrOrOrrrOrrr rrr )rr rPrrPrr rrPrOrPrrrrP) rOrrPrOrrrrr)rrrrrr) rr rrrPrrrrrrPrO) rr rrrrrrr) rOrrPrOrrrOrrrrr) rrrrrrrrr)rrrPrrPrOrrrPrrPr rr rP)rr rrrr)rr rPr-rrO) rrOrPrr rPrOr-r) rPrrrPrrr-rrO) rOr-rrOrPrrPrPrrPrrP) r rPrrrrr-rrO) rrOr-rrrrrOrPrr rP) r-rrOrPrrrrrrrr)rPrrOrPrPrrPrrPrrPrrOr-r) r-rrPr-rrrPrr ) r rPrrrOrrrrrrOr-) rPrrrPr-rrrPrrPrr)rrrOrrOr-rrrOrrOrPrrPrO) r rPrrrrrr-rrrPr-)rrrrr-rrrr-rOr-rr rPr)rrrrrrPrrPrrrr-rPr-r) r-rrr-rrOrPrrrrOr) rr rPrrOr rOrOr ) rPrrOrrrPrrPrrr rP) rrOrOrrPrOrrrPrPrrO) rrOrPrrPrPrPrPr) rrrr rPrOr rOrOrOrPr)rrOrPrrrOrr rrPrr rrr)rOrOrPrOrPrrOrrPrrPrrrrP) rrOrPrrPrPrrrPrrPrP) rPrOr rPrrOrPrrrPrOr) r rPrr rrrrr)rrPrOrrOrrPrrOrPrOrrrrO)rrPrrrr)rrPrrrrrPrOrrPrr rOr r) rrrrrrr rPrrPrr)rrPrOrPrr)rrPr)rOrPrr-rPrO) rOrPrrOr-rPrOrPr) rPrOr-rPrrOrr r) rr-rPrrOr-r rOrrOrPr) rOrrrOr-rr-rPr) rrOrPrrr-rr-rPr-rrO) r r-rPr rr-r rrrrOr-)r-rPrr-rrOrPr rrPrrOr rOr) rrPrrrPrPrPr-rP) rOrrrOrPrrOr-rPrrrP) r rrrPrrPrPrPr-rPrr)r rOrr rrrOr-rrrrPr-rPr)rrPrPrPr-rP) rrOr-rr-rrr-rP) r rrPr rPrPrPrPr-)r rOr-rPr r-) rPrOrrPrrOrrOrO) rPrrrPrOrrPrrOrOrPr) rrr rOrrrOrrOrrrP)rrOrrrrPrOrPrr rrrPrr) rrPrrrOrPrrOrOrrPrO)rrrOrrOrPrrPrOrrOrrPrrO)rrrPrrPr rrOrPrrPrOrOrOrP)r rrPrrOrP) rrPrrPrPrrPrrPrPrOr) rPrrrPrrrrr)rPrrrPrPrrPrOrPrrPrOrrr ) rPrrrPrrrr rr rr) rOrrPrOrPrPrPrPr)rrrPrrrP) rOrrPrOrPrPr rrPrrPrP)r rrP) rrOr-rr rOr rrO) rrOrPrr r-r rOr-r rrO) rrrOrrOrrrrr-rrO)rPrrrPrrOrrrr-rrOrrOr) rrOr-r rOrr rrOr rr)r r-rr rOr-r rrOrrOrrrOrP) rOr-rrOrrrrr) rOr-rrOrrrOrPrrPrr) rr rrr-r rrPr-r-rr )r rr-r r-rrrr-rOr-rrrr-)rPr-rrPrrr-rrrrrrrr)rrrrOr-r) rr rrrr-r-rrP) rr rrrr-rrOrrOr-r)rrrPr-rrP)rrOr-)r rrOrrOrO) rPrr rPr rOrOr r) rrrrrrOrOrrO)rPrrrOrPr) rrrOrrOr r rOrO) rPrr rPr rOrrr rrOr )rrrOrOrrO)rPrrO) rrPrOrrOrrrOr )r rrrr r) rrPrOrrOrrrrOrrrO)rrr)rrPrOr rrO)rr r)rrPrO)rrrr)rrrr)rrrr)rrrr)rrrr)rrrr)rrrr)rrrr)rrrr)rrrr)rrrr)rrrrc2g|]}t|dz SrBr)rRrs rTrUzisosurface.. s";;;QAq;;;rVrrrPc,g|]}|dSrr)rRrtriTables rTrUzisosurface.. s!6]6]6]!x!~6]6]6]rVrr#z+isosurface input data must be c-contiguous.cg|]}|dz SrOrrs rTrUzisosurface.. rrV)rrrr}r|rrrrcg|]}|dzSrOrrs rTrUzisosurface.. s2221222rV cjg|]/}t|j||dz z0SrO)rQr2)rRrcutEdgesshifts rTrUzisosurface.. s;SSSQ%a!2E!HQJ!?@@SSSrVrCrR.)IsosurfaceDataCacherrr6rr`rrtargwhererrrrr2rerrQruint32rrrrIrrrWrflatten)'rjr edgeTable edgeShifts nTableFacesfaceShiftTablesrS faceTableI faceTableIndsrrrrrrIrrrG vertexIndsvertexesdataFlatvimviviFlatrJrKnFacestotFacesfacesptrcscellscellIndsvertsvertIndsnvrXrYrSs' @@@rTr9r9 s(" H!!!BYC! ! ! NA A IIA  IIA     A JJ A   A   A  * ) )A  JJA  ! A   A  + * *A  " ! !A  , + +A  + * *A " ! !!A " II#A $   %A &   'A ( ( ' ')A *  +A , ) ( (-A . ) ( (/A 0 2 1 11A 2  3A 4 * ) )5A 6 ) ( (7A 8 4 3 39A : + * *;A < 5 4 4=A > 5 4 4?A @ , + +AA B IICA D   EA F   GA H ( ' 'IA J  KA L ) ( (MA N ) ( (OA P 2 1 1QA R  SA T * ) )UA V ) ( (WA X 2 1 1YA Z + * *[A \ 4 3 3]A ^ 5 4 4_A ` + * *aA b   cA d ( ' 'eA f ( ' 'gA h   iA j ) ( (kA l 2 1 1mA n 2 1 1oA p ) ( (qA r ) ( (sA t 2 1 1uA v 2 1 1wA x * ) )yA z 4 3 3{A | > = =}A ~ > = =A @ " ! !AA B JJCA D  EA F  GA H ) ( (IA J   KA L ( ' 'MA N ( ' 'OA P 1 0 0QA R ! SA T + * *UA V * ) )WA X 4 3 3YA Z ) ( ([A \ 4 3 3]A ^ 2 1 1_A ` * ) )aA b  cA d ) ( (eA f ) ( (gA h 2 1 1iA j ( ' 'kA l 1 0 0mA n 1 0 0oA p : 9 9qA r * ) )sA t 3 2 2uA v 3 2 2wA x > = =yA z 3 2 2{A | ? > >}A ~ ; : :A @ 3 2 2AA B ! CA D * ) )EA F * ) )GA H 2 1 1IA J ( ' 'KA L 1 0 0MA N   OA P ( ' 'QA R + * *SA T 4 3 3UA V 3 2 2WA X = < >_A ` 5 4 4aA b * ) )cA d 2 1 1eA f 4 3 3gA h ) ( (iA j 5 4 4kA l = < = =iA j 2 1 1kA l ? > >mA n < ; ;oA p  qA r 2 1 1sA t ) ( (uA v < ; ;wA x 2 1 1yA z ( ' '{A |   }A ~ 1 0 0A @ IIAA B , + +CA D 4 3 3EA F 5 4 4GA H > = =IA J 4 3 3KA L = < >WA X  YA Z ( ' '[A \ 1 0 0]A ^   _A ` IIaA b " ! !cA d + * *eA f , + +gA h " ! !iA j + * *kA l 3 2 2mA n ! oA p JJqA r * ) )sA t  uA v 3 2 2wA x JJyA z   {A | II}A ~ IIA @ AA DX LL LL LL LL LL LL LL LL LL LL LL LL  h;;(;;;28LLL &q ; ;A3x==!A#"6bhGGGJK q(899M-/X6]6]6]6]}6]6]6]-^-^J}QQQqS) *#++S]]Aq,ABBJ  " ":j#9 : : : : / I{S>Q;Y  :n %GEFFF %QE"HB//" Fzz||H Hh]") 4 4 4E C (" # #X%6 6B!!H 1QZZ FaK(( ;q>Q   qqqsU111Q3Zqqqs;< "8, uS!V}eAAAbjAAA$=>E#bqb&M[cdddd u{1~a/1%+abb/ABBBJ AAA566;;;CCE? ^A $c#b&j r  U?rVc 0tj|||||||| | g }d|_ tj |}tj|S)N)rPrP)rrrrrrrrrrrr2rpinvr rraveltolist)rsrrus rT_pinv_fallbackrx` s (BFFHHbffhhFFHHbffhhFFHHbffhh2 3 3CCI 9>>#  D  TZZ\\0022 33rVc |}d|z }|}||z}|S#t$rt|cYSwxYw)aCReturn a QTransform that is the inverse of *tr*. A pseudo-inverse is returned if tr is not invertible. Note that this function is preferred over QTransform.inverted() due to bugs in that method. (specifically, Qt has floating-point precision issues when determining whether a matrix is invertible) r) determinantadjointZeroDivisionErrorrx)rsdetdetrinvs rTr:r:i si"nnSyjjll t  """b!!!!!"s36AAexactcj|dkrt||||S|dkrt||||SdS)aJReturn an array of position values needed to make beeswarm or column scatter plots. Used for examining the distribution of values in an array. Given an array of x-values, construct an array of y-values such that an x,y scatter-plot will not have overlapping points (it will look similar to a histogram). r)spacingshufflebidir histogramN)_pseudoScatterExact_pseudoScatterHistogram)rjrrrmethods rTr;r;{ sR"4'QVWWWW ;  &tWgUZ[[[[  rVcttjt|}|rtj|||}|*dtj|zt|dzz }tjt|}|}|}t||z |z dz}tj |||} | d| dz } || dz | z t} i} t| D](\} }| |ddz}|| |<||| <)|dur=t|D]-} || | kxx| | ddzzcc<.|tj|S)zWorks by binning points into a histogram and spreading them out to fill the bin. Faster method, but can produce blocky results. N@rrrr}T)rrIrtrandomrstdrerirrclinspacerrrr`argsort)rjrrrrryvalsdmindmaxnbinsbinsrdbins binCountsrSrrFs rTrr s 9SYY  D  $ :DRVD\\/#d))S.0 HSYY  E 88::D 88::D dg% & & *E ;tT5 ) )D a47 BT!Wn " * *3 / /EI! MM!R 1 $ ! a }}u 9 9A %(OOOy}}Q22S8 8OOOO D!! ""rVc tjt|}|rtj|||}|*dtj|zt|dzz }|dz}tjt|}t|dkr|Sd|d<tdt|D]}||}|d|} |d|} d} | |z dz} | |k} | dkrI|rddg}ndg}g}|D] }d} | | }||z dz}tjdt|f}| | |z |d<| | |z|d< |dkr |d| k}n |d| k}|dd|f}|d| k|d| kz}|dkrnD|dkr|dd|f } n|dd|f } | |  |r$|d |dkr|dn|d} n|d} | ||<|tj |S)zWorks by stacking points up one at a time, searching for the lowest position available at each point. This method produces nice, smooth results but can be prohibitively slow for large datasets. Nrrrrrr}) rrIrtrrrrer`rrrirr)rjrrrrrs2rrSrgx0y0rHrxmaskdirsyopts directiondx2dylimitsrlimits2s rTrr s 9SYY  D  $ :DRVD\\/#d))S.0 !B HSYY  E 4yyA~~ E!H 1SYY  -- G "1"X 2A2Y dQYR 99;;?? AwsE!  i3h_1SWW+..uINq uINq 2 1}}%ayA~%ayA~$QQQtVnG$AJNwqzA~>DxxzzQ 1}}#AAAdFO//11#AAAdFO//11#2$ Q !&q E!H 4 4E!HH%(!Ha D!! ""rVc z|}t|D]\}}|D] }||vrg||< |[t}|D]}|t|z}t||z }|t}g}g} |D]}} | |vrt d|| gz| |vr|| | t||| ||| gz|dz| | ~| S)uTopological sort. Arguments are: deps dictionary describing dependencies where a:[b,c] means "a depends on b and c" nodes optional, specifies list of starting nodes (these should be the nodes which are not depended on by any other nodes). Other candidate starting nodes will be ignored. Example:: # Sort the following graph: # # B ──┬─────> C <── D # │ │ # E <─┴─> A <─┘ # deps = {'a': ['b', 'c'], 'c': ['b', 'd'], 'e': ['b']} toposort(deps) => ['b', 'd', 'c', 'a', 'e'] NzCyclic dependency detectedr)r2) rr9r5r3rr4r>rrr<r) depsnodesseenstackr2rIrremdepsortedrs rTr<r< s\( 99;;DDJJLL!!!  A}}Q  }ee;;==  C 3s88OCCDIIKK  3& |uu F  ::8%1#+FF F 99    xd1gtUA3YeAgNNNOOO a MrVc ||}|d}n#ttf$rd}YnwxYw|rdStj|}|dSQ)aDisconnect a Qt signal from a slot. This method augments Qt's Signal.disconnect(): * Return bool indicating whether disconnection was successful, rather than raising an exception * Attempt to disconnect prior versions of the slot when using pg.reload TNF)r=r RuntimeErrorrgetPreviousVersion)signalslotsuccesss rTr=r=" s  ''--G<(   GGG   4(.. <5 s 33c$eZdZdZdZdZdZdS)r>zClass used to temporarily block a Qt signal connection:: with SignalBlock(signal, slot): # do something that emits a signal; it will # not be delivered to slot c"||_||_dSr)rr)rrrs rTrzSignalBlock.__init__B s  rVcDt|j|j|_|Sr)r=rr reconnectrs rTr=zSignalBlock.__enter__F s#DK;; rVcV|jr!|j|jdSdSr)rrrrrs rTr@zSignalBlock.__exit__J s4 > + K   * * * * * + +rVN)rrr__doc__rr=r@rrVrTr>r>; sK +++++rVr>)rXT)rPrZTNrXT)rrr)r)r)r rr?r@rrr?r?)rNrrrPr)rF)rr)Fr)NN)NNNFTN)NTT)FT)rrV)rET)FFF)r)NTFr)NTF)NNNr)nrr]r`rerr6r; collectionsrrrrZrrrr metaarrayr r r r util.cupy_helperr util.numba_helperr__all__rrrQrfrr`rtrcompile FLOAT_REGEX INT_REGEXrrrr_rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r:rTrcr r rrr-r.r/r0r r1r<r2r3r4r5rcr}rr6rjrirr7r8rZr9rxr:r;rrr<r=rr>rrVrTrs  ######000000000000 %%%%%%%%%%%%%%%%000000 > > >0 a#c " " aAc " " c!Ac " " aC $ $ c!C $ $ c#a $ $ a!C c#c# & & c#c# & & c#c# & & c#c# & &  # 'dWWuuSSEUEU?V?VWWWXXCbj~BMMPiijj BJ@;NQff g g     FEEEE<!4U4U4U4Un{4         D D D D DEL D D DDDDN(((*777t7777 bh! "" bh! "" bh133 C5C5C5C5J$$$L!;!;!;!;F&&& 2222,6_G_G_GD   :YYYYx:CCCCL ^ ^ ^FWWWB8888z2.??? <<<<  5S".&&s++BQB/ 0 011W<< J09Q9Q9Q9Qx7772### yyyyx>M1M1M1M1`###L*+4+4+4Z&&&R)()()()(X(DDDN<<<<~KKKKZ@@@ $$$zsssslFJJJZ444"""$ \ \ \ \!#!#!#!#HB#B#B#B#L,,,,^2+++++&+++++rV