def test_fourier_coeffs(xs: Vector, Es: Vector) -> None: assert isclose( simps( convolution_v(np_sin(2 * xs), 10 * np_cos(xs) + np_sin(1 * xs)), xs, ), 0.0, atol=1E-5, ) A0 = a0(xs, np_cos(xs)) print(bn(xs, np_cos(xs), 1, A0)) print(bn(xs, np_cos(xs), 2, A0))
def my_dist(a, b): if a[2] == b[2]: a_t = (a[0] + np_pi) / 2 b_t = (b[0] + np_pi) / 2 a_r = a[1] b_r = b[1] return 10 * ((1. - np_cos(np_abs(a_t - b_t))) + np_log(np_abs(a_r - b_r) + 1.) / 5.) else: return 20.0
def transformCP(self, silent=False, nolog=False, min=None, max=None): """Do the main ransformation on the coverage profile data""" shrinkFn = np_log10 if(nolog): shrinkFn = lambda x:x s = (self.numContigs,3) self.transformedCP = np_zeros(s) if(not silent): print " Dimensionality reduction" # get the median distance from the origin unit_vectors = [(np_cos(i*2*np_pi/self.numStoits),np_sin(i*2*np_pi/self.numStoits)) for i in range(self.numStoits)] for i in range(len(self.indices)): norm = np_norm(self.covProfiles[i]) if(norm != 0): radial = shrinkFn(norm) else: radial = norm shifted_vector = np_array([0.0,0.0]) flat_vector = (self.covProfiles[i] / sum(self.covProfiles[i])) for j in range(self.numStoits): shifted_vector[0] += unit_vectors[j][0] * flat_vector[j] shifted_vector[1] += unit_vectors[j][1] * flat_vector[j] # log scale it towards the centre scaling_vector = shifted_vector * self.scaleFactor sv_size = np_norm(scaling_vector) if(sv_size > 1): shifted_vector /= shrinkFn(sv_size) self.transformedCP[i,0] = shifted_vector[0] self.transformedCP[i,1] = shifted_vector[1] self.transformedCP[i,2] = radial if(not silent): print " Reticulating splines" # finally scale the matrix to make it equal in all dimensions if(min is None): min = np_amin(self.transformedCP, axis=0) max = np_amax(self.transformedCP, axis=0) max = max - min max = max / (self.scaleFactor-1) for i in range(0,3): self.transformedCP[:,i] = (self.transformedCP[:,i] - min[i])/max[i] return(min,max)
def get_equations(self, symbols_segment_1: dict, symbols_segment_2: dict): s1_x1, s1_y1 = symbols_segment_1['x1'], symbols_segment_1['y1'] s1_x2, s1_y2 = symbols_segment_1['x2'], symbols_segment_1['y2'] s2_x1, s2_y1 = symbols_segment_2['x1'], symbols_segment_2['y1'] s2_x2, s2_y2 = symbols_segment_2['x2'], symbols_segment_2['y2'] s1_dx, s1_dy = s1_x2 - s1_x1, s1_y2 - s1_y1 s2_dx, s2_dy = s2_x2 - s2_x1, s2_y2 - s2_y1 scalar_prod = s1_dx * s2_dx + s1_dy * s2_dy l1 = sp_sqrt(s1_dx ** 2 + s1_dy ** 2) l2 = sp_sqrt(s2_dx ** 2 + s2_dy ** 2) equations = [ Eq(scalar_prod, l1 * l2 * np_cos(self._angle)) # TODO: simplify? ] return equations
def _convert_local_operator_to_qutip(expr, full_space, mapping): """Convert a LocalOperator instance to qutip.""" n = full_space.dimension if full_space != expr.space: all_spaces = full_space.local_factors own_space_index = all_spaces.index(expr.space) return qutip.tensor( *([qutip.qeye(s.dimension) for s in all_spaces[:own_space_index]] + [convert_to_qutip(expr, expr.space, mapping=mapping)] + [ qutip.qeye(s.dimension) for s in all_spaces[own_space_index + 1:] ])) if isinstance(expr, Create): return qutip.create(n) elif isinstance(expr, Jz): return qutip.jmat((expr.space.dimension - 1) / 2.0, "z") elif isinstance(expr, Jplus): return qutip.jmat((expr.space.dimension - 1) / 2.0, "+") elif isinstance(expr, Jminus): return qutip.jmat((expr.space.dimension - 1) / 2.0, "-") elif isinstance(expr, Destroy): return qutip.destroy(n) elif isinstance(expr, Phase): arg = complex(expr.operands[1]) * arange(n) d = np_cos(arg) + 1j * np_sin(arg) return qutip.Qobj(np_diag(d)) elif isinstance(expr, Displace): alpha = expr.operands[1] return qutip.displace(n, alpha) elif isinstance(expr, Squeeze): eta = expr.operands[1] return qutip.displace(n, eta) elif isinstance(expr, LocalSigma): j = expr.j k = expr.k if isinstance(j, str): j = expr.space.basis_labels.index(j) if isinstance(k, str): k = expr.space.basis_labels.index(k) ket = qutip.basis(n, j) bra = qutip.basis(n, k).dag() return ket * bra else: raise ValueError("Cannot convert '%s' of type %s" % (str(expr), type(expr)))
def tmax_pseudo_ellipse_array(phi, theta_x, theta_y): """The pseudo-ellipse tilt-torsion polar angle for numpy arrays. @param phi: The azimuthal tilt-torsion angle. @type phi: numpy rank-1 float64 array @param theta_x: The cone opening angle along x. @type theta_x: float @param theta_y: The cone opening angle along y. @type theta_y: float @return: The array theta max angles for the given phi angle array. @rtype: numpy rank-1 float64 array """ # Zero points. if theta_x == 0.0: return 0.0 * phi elif theta_y == 0.0: return 0.0 * phi # Return the maximum angle. return theta_x * theta_y / np_sqrt((np_cos(phi)*theta_y)**2 + (np_sin(phi)*theta_x)**2)
def tmax_pseudo_ellipse_array(phi, theta_x, theta_y): """The pseudo-ellipse tilt-torsion polar angle for numpy arrays. @param phi: The azimuthal tilt-torsion angle. @type phi: numpy rank-1 float64 array @param theta_x: The cone opening angle along x. @type theta_x: float @param theta_y: The cone opening angle along y. @type theta_y: float @return: The array theta max angles for the given phi angle array. @rtype: numpy rank-1 float64 array """ # Zero points. if theta_x == 0.0: return 0.0 * phi elif theta_y == 0.0: return 0.0 * phi # Return the maximum angle. return theta_x * theta_y / np_sqrt((np_cos(phi) * theta_y)**2 + (np_sin(phi) * theta_x)**2)
assert isclose( simps( convolution_v(np_sin(2 * xs), 10 * np_cos(xs) + np_sin(1 * xs)), xs, ), 0.0, atol=1E-5, ) A0 = a0(xs, np_cos(xs)) print(bn(xs, np_cos(xs), 1, A0)) print(bn(xs, np_cos(xs), 2, A0)) if __name__ == '__main__': xs_in_rad = linspace(0, 2 * pi, 120) Es = 24.0 + 10. * np_cos(1. * xs_in_rad - pi / 3) + 20. * np_cos( 2.0 * xs_in_rad + pi / 4) + 2.0 * random.normal( 0., 1.5, len(xs_in_rad)) # pylint: disable=no-member fit_in_rad = best_fit(xs_in_rad, Es, should_plot=False, optimise_final_terms=True) xs_in_deg = rad2deg(xs_in_rad) print(xs_in_deg) fit_in_deg = best_fit(xs_in_deg, Es, unit='deg', should_plot=False, optimise_final_terms=True)