Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
1677 views
�
��Wc@ s�ddlmZddlZddlZddlZddlmZedkr-ddl	m
Z
dd4d��YZed�Zd	e_
d
e_de_de_d
e_de_de_de_ed�Zed�Zed�Zed�Zed�Zed�Zge_d�Zee_n
ddl	TedkrXde_de_ nd�Z!dd5d��YZ"dd6d��YZ#dd7d ��YZ$d!d8d"��YZ%d#d9d$��YZ&d%e'd&e(d'�Z)gd(�Z*d)ej+fd*��YZ,d+ej+fd,��YZ-d-ej+fd.��YZ.d/ej+fd0��YZ/d1ej+fd2��YZ0edkr|d3GHej1�ndS(:i����(tdivisionN(tndarrayt__main__(tvectortMockcB s#eZd�Zd�Zd�ZRS(cO s||_d|_dS(Ni(tnametcalled(tselfRtargstkwargs((sphysutil.pyt__init__s	cO sJ||_||_x"|D]}t||||�qW|jd7_|S(Ni(RR	tsetattrR(RRR	R((sphysutil.pyt__call__s		
cC s
d|_dS(Ni(R(R((sphysutil.pytreset#s(t__name__t
__module__R
RR
(((sphysutil.pyRs		tcolortredtgreentbluetyellowtorangetcyantmagentatwhitetarrowtlabeltpointstcurvetgdisplaytgcurvecC stjj|�dS(N(Rtplotstappend(tpos((sphysutil.pytmockPlot7s(t*i2cC sZt|�tks$t|�tkr+|jSt|�tkrVt|j|j|j�SdS(N(ttypetboxtpyramidtsizetsphereRtradius(tobj((sphysutil.pytobj_sizeXs$t	MotionMapcB steZdZddejeeddd�eeddd�eddd�ejd�	Z	eddd�d�Z
RS(s�
    This class assists students in constructing motion maps 
    using either arrows (measuring a quantity) or "breadcrumbs" 
    (with timestamps).
    Riic
C s�||_||_||_||_||_||_||_||_|
|_|	|_	||_
||_y|j|j|_Wn-t
k
r�}
dGHdGHdGH|
GH|
�nXd|_dS(Ns**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************i(R*ttft
numMarkerst
markerTypetmarkerScaletmarkerColortlabelMarkerOrdertlabelMarkerOffsett
timeOffsettdropTimetarrowOffsett
labelColortintervalt	TypeErrort	curMarker(RR*R-R.R/R0R1R2R3R5R4R6R7terr((sphysutil.pyR
es*												
cC s�y�||j|jkr�|jd7_|jdkrjtd|jj|jd|j|d|j�n?|jdkr�t	d|jjdd|j|d|j�n|j
tk	rtd	|jd
d	�|j
}td|jj|ddt|�d
dddtd|j�}n|jtk	r�td|jjtd	|jd
d	�|jdt|j�dddtd|j�q�nWn-tk
r�}dGHdGHdGH|GH|�nXdS(NiRR!taxisRtbreadcrumbsR'i
ig�?ttextst=tstheightR%s**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(R8R:R/RR*R!R6R0R1RR5tFalseRR4RtstrR7R2R3R9(RtttquantitytepsilontdroptimeTextR;((sphysutil.pytupdate�s( E_(RRt__doc__RRtTrueRRARR
RG(((sphysutil.pyR,^s	0't
MotionMapNcB steZdZddejeeddd�eeddd�eddd�ejd�	Z	eddd�d�Z
RS(s�
    This class assists students in constructing motion maps 
    using either arrows (measuring a quantity) or "breadcrumbs" 
    (with timestamps).
    Riic
C s�||_||_||_||_||_||_||_||_|
|_|	|_	||_
||_y|j|j|_Wn-t
k
r�}
dGHdGHdGH|
GH|
�nXd|_dS(Ns**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************i(R*tdttnumStepsR/R0R1R2R3R4R5R6R7R8R9R:(RR*RKRLR/R0R1R2R3R5R4R6R7R;((sphysutil.pyR
�s*												
cC s�y�|j|j}||kr�|jd7_|jdkrptd|jj|jd|j|d|j�n?|jdkr�t	d|jjdd|j|d|j�n|j
tk	r#td	|jd
d	�|j
}td|jj|ddt|�d
dddtd|j�}n|jtk	r�td|jjtd	|jd
d	�|jdt|j�dddtd|j�q�nWn-tk
r�}dGHdGHdGH|GH|�nXdS(NiRR!R<RR=R'i
ig�?R>st=R?R@R%s**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(R8R:R/RR*R!R6R0R1RR5RARR4RRBR7R2R3R9(RRCRDt	thresholdRERFR;((sphysutil.pyRG�s* E_(RRRHRRRIRRARR
RG(((sphysutil.pyRJ�s	0'tPhysAxisc	B skeZdZdeddd�d	d	d	dejejd�Zd�Z	d	d	d	d	d	d�Z
d�ZRS(
sP
    This class assists students in creating dynamic axes for their models.
    txiitdowncC s�y�g|_g|_||_||_t|jjj|jjj|jjj�|_	||_
||_|dkr{|ntddd�|_|dk	r�|nt|�j|_|dk	r�|n4tt|�jddt|�jd�|jj|_|	|_|
|_|dkr=tdd|jd�|_n�|dkrhtdd	|jd�|_nV|d
kr�td|jdd�|_n+|dkr�td
|jdd�|_n|j�Wn-tk
r�}dGHdGHdGH|GH|�nXdS(Ntyiiii����RPg��������tupg�������?tleftg��������trightg�������?s**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(tintervalMarkerstintervalLabelst	labelTextR*RR!RORQtztlastPost	numLabelstaxisTypeR<tNoneR+tlengthtstartPost	axisColorR7t
labelShiftt_PhysAxis__reorientR9(RR*RZR[R<R^R]tlabelstlabelOrientationR_R7R;((sphysutil.pyR
s8				0		'$L		cC sy�|jj|jkr�|jj|j}xItt|j��D]2}|j|j|7_|j|j|7_qAWg|jjD]}||^q�|j_t|jjj	|jjj
|jjj�|_nWn-tk
r}dGHdGHdGH|GH|�nXdS(Ns**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(
R*R!RYtrangetlenRURVt	axisCurveRRORQRXR9(RtdifftiROR;((sphysutil.pyRG/s)7cC sfy2|dk	r|n|j|_|dk	r3|n|j|_|dk	rQ|n|j|_|dk	ro|n|j|_|dkr�tdd|jd�|_n�|dkr�tdd|jd�|_nV|dkr�td|jdd�|_n+|dkr'td	|jdd�|_n|j�Wn-t	k
ra}d
GHdGHdGH|GH|�nXdS(
NRPig��������RRg�������?RSg��������RTg�������?s**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(
R\R<R^R]RbRWRR`RaR9(RR<R^R]RbRcR;((sphysutil.pytreorientBs(cC s�t|j�dkrtnt}|j|j|j}|j|jd|j}d}x(||jkr�|j||}|jdk	r�|j|}n,|j
dkr�d|j}n
d|j}|r
||j|_
||j|j|_
t|�|j|_ni|jjtd|d|jdd��|jjtd||jd	t|�d
tddd|j��|d}q\W|r�|j|g|j_
n$td|j|gd|j�|_dS(
NiiRQs%.2fR!RR'iR>R%R@i(ReRURIRAR^R]R<RZRWR\R[RQROR!R`RVRBR>R RR_RR7RfR(RtupdatingtfinalR8RhtintervalPosRW((sphysutil.pyt
__reorient\s.!
		8N(RRRHRR\RRRR
RGRiRa(((sphysutil.pyRNs)	t	PhysTimercB s,eZdZdeejd�Zd�ZRS(sL
    This class assists students in creating an onscreen timer display.
    i
c	C s�y�||_||_|tkrTtdt||d�dddtd|�|_n0tdt||d�dddtd|�|_Wn-tk
r�}dGHd	GHd
GH|GH|�nXdS(NR!iR>s00:00:00.00R%R@t00E01s**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(t
useScientifict
timerColorRARRt
timerLabelR9(RRORQtfontsizeRpRqR;((sphysutil.pyR
�s		34cC s�y�|jrd||j_n�t|d�}t|dd�}t|d�}ttd|d��}|dkr�d}|d}nd||||f|j_Wn-tk
r�}dGHd	GHd
GH|GH|�nXdS(Ns%.4Eii<idiis%02d:%02d:%02d.%02ds**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(RpRrR>tinttroundR9(RRCthourstminstsecstfracR;((sphysutil.pyRG�s"	
 (RRRHRARRR
RG(((sphysutil.pyRn�st	PhysGraphcB sheZdZejejejejejej	ej
ejgZddddejd�Zd�ZRS(sU
    This class assists students in creating graphs with advanced functionality.
    ic
C s�y�tddddd|d|d|d|�|_||_g|_xAt|�D]3}|jjtd	tj|t	tj���qRWWn-t
k
r�}d
GHdGHdGH|GH|�nXdS(
NROi�RQi^ttitletxtitletytitlet
backgroundRs**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(tgraphtgraphDisplaytnumPlotstgraphsRdR RRztgraphColorsReR9(RR�R{txlabeltylabeltbackgroundColorRhR;((sphysutil.pyR
�s0		5cG s�yft|�|jkr'td��nx;tt|��D]'}|j|jd|||f�q:WWn-tk
r�}dGHdGHdGH|GH|�nXdS(Ns\ERROR: Number of dependent parameters given does not match numPlots given at initialization!R!s**********TYPE ERROR**********sqPlease check that you are not passing in a variable of the wrong type (e.g. a scalar as a vector, or vice-versa)!s******************************(ReR�t	ExceptionRdR�tplotR9(Rtindependentt
dependentsRhR;((sphysutil.pyR��s)N(RRRHRRRRRRRRRR�R\R
R�(((sphysutil.pyRz�s
iic
C sdg|}xt|�D]}g||<qWtjjdkrt|d���}tj|�}x!td|�D]}|j�qqW|r�|dkr�|j�nx^|D]V}	xMt|�D]?}
|r�||
jt	|	|
��q�||
j|	|
�q�Wq�WWdQXn�tjjdkr�t|dd���}tj|�}x!td|�D]}|j�qTWt
r�|dkr�|j�nx^|D]V}	xMt|�D]?}
|r�||
jt	|	|
��q�||
j|	|
�q�Wq�WWdQXntjjd�t
d�|S(	Niitrbitnewlinets!You need to use python 2* or 3* 
i(Rdtsystversion_infotmajortopentcsvtreadertnextR tfloattignoreHeadertstderrtwritetexit(tfilenametcolstIgnoreHeadertstartrowtNumericDatatdataRhtcsvfiletcsvdatatrowtc((sphysutil.pytreadcsv�s<


&

&
c
C s�g}t}tjjdkr0t|d�}nDtjjdkrZtdddd�}ntjjd�td	�t|t	�r�|j
}|j�}nt|�d	kr�|j
�dSt}d
}d
}t|d
ttf�rt}t|d
�}t|�}nt}t|�}d	}|r�xTtd	t|��D]:}t||�|kr?tjjd�|j
�dSq?Wnt|�d
kr�t|�|kr�tjjd�q�t}ntj|d
ddddtj�}	|r�|	j|�nxytd
|�D]h}
g}|d	krTx@td
|�D]}|j|||
�q2Wn|j||
�|	j|�q
W|j
�dS(NitwbispythonTest.csvtwR�R�s!You need to use python 2* or 3* 
iis/All lists in datalist must be the same length 
sDHeader length did not match the number of columns, ignoring header.
t	delimitert,t	quotechart|tquoting(RAR�R�R�R�R�R�R�t
isinstancet
numpy_ndarraytTttolistRetclosetlistttupleRIRdR�twritert
QUOTE_MINIMALtwriterowR (
R�tdatalisttheaderR�t	useheadertisLofLt
ListLengthtnumListstLidxt
DataWriterR�tthisrowtcol((sphysutil.pytwritecsv	sZ
	

	$t
TestMotionMapcB s#eZd�Zd�Zd�ZRS(cC s�td�|_tddd�|j_d|_d|_tddd�|_d|_tddd�|_t	j
�tj
�tj
�t
|j|j|jddd	dd
tjdtd|jd
|j�|_dS(NR*ii
iiiR/RR0R1R5R4R6(RR*RR!R-R.R4R0R6RR
RRR,RRRItmap(R((sphysutil.pytsetUpSs			


cC s'|j|j|jj�|j|j|jj�|j|j|jj�|jd|jj�|j|j|jj�|jtj|jj	�|jt
ddd�|jj�|jt|jj
�|j|jj|j|j�|j|jjd�|jt
ddd�|jj�dS(NRii(tassertEqualR*R�R-R.R/R0RRR1RR4RIR5R8R:R6(R((sphysutil.pyt	test_initds" cC sd|j_|jjd�|jtjd�|jtjd�|jtjd�|jjddd�|jtjd�|jtjd�|jtjd�|j|jjd�|jtj|j	j|j
�|jtjd�|jtjtj
�|jtjd�dS(NiiiRDiit2(R�R:RGR�RRRRR!R*R6R<RRR>(R((sphysutil.pyttest_updaters (RRR�R�R�(((sphysutil.pyR�Rs		tTestMotionMapNcB s#eZd�Zd�Zd�ZRS(cC s�td�|_tddd�|j_d|_d|_tddd�|_d|_tddd�|_t	j
�tj
�tj
�t
|j|j|jddddd	tjd
td|jd|j�|_dS(
NR*iiiiR/RR0R1R5R4R6(RR*RR!RKRLR4R0R6RR
RRRJRRRIR�(R((sphysutil.pyR��s			


cC s|j|j|jj�|j|j|jj�|j|j|jj�|jd|jj�|j|j|jj�|jtj|jj	�|jt
ddd�|jj�|jt|jj
�|j|jjd�|jt
ddd�|jj�dS(NRii(R�R*R�RKRLR/R0RRR1RR4RIR5R:R6(R((sphysutil.pyR��s"cC sd|j_|jjd�|jtjd�|jtjd�|jtjd�|jjddd�|jtjd�|jtjd�|jtjd�|j|jjd�|jtj|j	j|j
�|jtjd�|jtjtj
�|jtjd�dS(NiiiRDiiR�(R�R:RGR�RRRRR!R*R6R<RRR>(R((sphysutil.pyR��s (RRR�R�R�(((sphysutil.pyR��s		tTestPhysAxiscB s,eZd�Zd�Zd�Zd�ZRS(cC s�td�|_tddd�|j_d|_tddd�|_tddd�|_d|_dddd	d
g|_dg|_	d|_
d|_tj
�t|j|jd
|j
d|jd|jd|jd|jd|j�|_dS(NR*iiii
tatbR�tdtet	arbitraryRSR[R<R^R]RbRc(RR*RR!RZR<R^R]RbtwrongLabelsR[RcRR
RNtphysAxis(R((sphysutil.pyR��s				
$cC s�|j|jj|j�|j|jj|j�|j|jj|jj�|j|jj|j�|j|jj|j�|j|jj	|j	�|j|jj
|j
�|j|jj|j�|j|jjt
d|j	dd��|jt|jj�|j�|jt|jj�|j�|j
|j	|j}|j|jjdj|�|j|jjdj||jj�|j|jjdjd�|jtjd�dS(Ng��������ii����R�i(R�R�RWRbR*RYR!RZR<R]R^R[R`RReRURVR>RR(RRl((sphysutil.pyR��s )'cC sJtddd�}tddd�}dddddg}|jjd|d	|d
dd|dd
�|j|jj|�|j|jj|�|j|jjd�|j|jjtddd��||}|j|jjdj	|�|j|jj
dj	||jj�|j|jj
djd�|jtj
d�dS(NiitftgthRhtjR<R^R]RbRcRTg�������?i����(RR�RiR�R<R^R]R`RUR!RVR>RR(RtnewAxisR^totherLabelsRl((sphysutil.pyt
test_reorient�s
"
'cC s�t|jjdjj|jjdjj|jjdjj�}t|jjdjj|jjdjj|jjdjj�}t|jjjdj|jjjdj|jjjdj�}|jj	�|j
||jjdj�|j
||jjdj�|j
||jjjd�|jjjtddd�|jj_|jj	�|j||jjdj�|j||jjdj�|j||jjjd�dS(Ni����ii(
RR�RUR!RORQRXRVRfRGR�R*tassertNotEqual(RtstartMarkerPost
startLabelPost
startCurvePos((sphysutil.pyR��s$
(
(RRR�R�R�R�(((sphysutil.pyR��s			t
TestPhysGraphcB s#eZd�Zd�Zd�ZRS(cC stdd�|_dS(NR�i(Rzt	physGraph(R((sphysutil.pyR�scC sh|j|jjjd�|j|jjjd�|j|jjd�|jt|jj�d�dS(Ni�i^i(R�R�R�RORQR�ReR�(R((sphysutil.pyR�sc
C s|jt|jjtddd�tddd��|jjtddd�tddd�tddd�tddd�tddd�tddd��|jt|jjdj�d�|j|jjdjdtddd�tddd�f�dS(Niiiiiii����(	tassertRaisesR�R�R�RR�ReR�R(R((sphysutil.pyt	test_plots4g#(RRR�R�R�(((sphysutil.pyR�s		t
TestPhysTimercB s#eZd�Zd�Zd�ZRS(cC stdd�|_dS(Ni(Rnttimer(R((sphysutil.pyR�scC sB|j|jjjd�|j|jjjtddd��dS(Ns00:00:00.00ii(tassertEqualsR�RrR>R!R(R((sphysutil.pyR�scC sb|jjd�|j|jjjd�t|j_|jjd�|j|jjjd�dS(Ng����L��@s01:05:23.65s
3.9237E+03(R�RGR�RrR>RIRp(R((sphysutil.pyR� s
(RRR�R�R�(((sphysutil.pyR�s		sBeginning unit tests!(((((((2t
__future__RtunittestR�R�tnumpyRR�RtvpythonRRRRRRRRRRRRRRRRRRR"R�tsceneRORQR+R,RJRNRnRzRARIR�R�tTestCaseR�R�R�R�R�tmain(((sphysutil.pyt<module>s\												

		OS�02%I20S