def calc_2d_ellipse_properties(cov,nstd=<NUM_LIT:2>):
def eigsorted(cov):<EOL><INDENT>vals, vecs = np.linalg.eigh(cov)<EOL>order = vals.argsort()[::-<NUM_LIT:1>]<EOL>return vals[order], vecs[:,order]<EOL><DEDENT>vals, vecs = eigsorted(cov)<EOL>width, height = <NUM_LIT:2> * nstd * np.sqrt(vals[:<NUM_LIT:2>])<EOL>normal = vecs[:,<NUM_LIT:2>] if vecs[<NUM_LIT:2>,<NUM_LIT:2>] > <NUM_LIT:0> else -vecs[:,<NUM_LIT:2>]<EOL>d = np.cross(normal, (<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>))<EOL>M = rotation_matrix(d)<EOL>x_trans = np.dot(M,(<NUM_LIT:1>,<NUM_LIT:0>,<NUM_LIT:0>))<EOL>cos_val = np.dot(vecs[:,<NUM_LIT:0>],x_trans)/np.linalg.norm(vecs[:,<NUM_LIT:0>])/np.linalg.norm(x_trans)<EOL>theta = np.degrees(np.arccos(np.clip(cos_val, -<NUM_LIT:1>, <NUM_LIT:1>))) <EOL>return { '<STR_LIT:width>': width, '<STR_LIT>': height, '<STR_LIT>': theta }, normal<EOL>
Calculate the properties for 2d ellipse given the covariance matrix.