def b_vector(self): """ Creation of the independent vector b to solve the kriging system Args: verbose: -deprecated- Returns: theano.tensor.vector: independent vector """ length_of_C = self.matrices_shapes()[-1] # ===================== # Creation of the gradients G vector # Calculation of the cartesian components of the dips assuming the unit module G_x = T.sin(T.deg2rad(self.dip_angles)) * T.sin(T.deg2rad( self.azimuth)) * self.polarity G_y = T.sin(T.deg2rad(self.dip_angles)) * T.cos(T.deg2rad( self.azimuth)) * self.polarity G_z = T.cos(T.deg2rad(self.dip_angles)) * self.polarity G = T.concatenate((G_x, G_y, G_z)) # Creation of the Dual Kriging vector b = T.zeros((length_of_C, )) b = T.set_subtensor(b[0:G.shape[0]], G) if str(sys._getframe().f_code.co_name) in self.verbose: b = theano.printing.Print('b vector')(b) # Add name to the theano node b.name = 'b vector' return b
def dist(y_pred, y): y_pred_ra = T.deg2rad(y_pred) y_ra = T.deg2rad(y) lat1 = y_pred_ra[:, 0] lat2 = y_ra[:, 0] dlon = (y_pred_ra - y_ra)[:, 1] EARTH_R = 6372.8 y = T.sqrt((T.cos(lat2) * T.sin(dlon)) ** 2+ (T.cos(lat1) * T.sin(lat2) - T.sin(lat1) * T.cos(lat2) * T.cos(dlon)) ** 2) x = T.sin(lat1) * T.sin(lat2) + T.cos(lat1) * T.cos(lat2) * T.cos(dlon) c = T.arctan2(y, x) return EARTH_R * c
def phaseSpaceToAstrometry_and_RV(a): """ From the given phase space coordinates calculate the astrometric observables, including the radial velocity, which here is seen as the sixth astrometric parameter. The phase space coordinates are assumed to represent barycentric (i.e. centred on the Sun) positions and velocities. This function has no mechanism to deal with units. The velocity units are always assumed to be km/s, and the code is set up such that for positions in pc, the return units for the astrometry are radians, milliarcsec, milliarcsec/year and km/s. For positions in kpc the return units are: radians, microarcsec, microarcsec/year, and km/s. NOTE that the doppler factor k=1/(1-vrad/c) is NOT used in the calculations. This is not a problem for sources moving at typical velocities of Galactic stars. Parameters ---------- x - The x component of the barycentric position vector (in pc or kpc). y - The y component of the barycentric position vector (in pc or kpc). z - The z component of the barycentric position vector (in pc or kpc). vx - The x component of the barycentric velocity vector (in km/s). vy - The y component of the barycentric velocity vector (in km/s). vz - The z component of the barycentric velocity vector (in km/s). Returns ------- phi - The longitude-like angle of the position of the source (radians). theta - The latitude-like angle of the position of the source (radians). parallax - The parallax of the source (in mas or muas, see above) muphistar - The proper motion in the longitude-like angle, multiplied by cos(theta) (mas/yr or muas/yr, see above) mutheta - The proper motion in the latitude-like angle (mas/yr or muas/yr, see above) vrad - The radial velocity (km/s) """ x = a[:,0] y = a[:,1] z = a[:,2] vx = a[:,3] vy = a[:,4] vz = a[:,5] b = cartesianToSpherical(a[:,:3]) phi = b[:,0] theta = b[:,1] parallax = b[:,2] p, q, r = normalTriad(tt.deg2rad(phi), tt.deg2rad(theta)) velocities= a[:,3:] muphistar = tt.sum(p*velocities,axis=1)*parallax/_auKmYearPerSec mutheta = tt.sum(q*velocities,axis=1)*parallax/_auKmYearPerSec vrad = tt.sum(r*velocities,axis=1) #------- Join ------ res = tt.stack([phi, theta, parallax, muphistar, mutheta, vrad],axis=1) return res
def srgb_to_ucs(RGB, Y_w, L_A, Y_b, F, c, N_c): """Converts sRGB (gamma=2.2) colors to CAM02-UCS (Luo et al. 2006) Jab.""" XYZ_w = T.dot([[1, 1, 1]], M_SRGB_to_XYZ) * Y_w RGB_w = T.dot(XYZ_w, M_CAT02) # D = T.clip(F * (1 - (1/3.6) * T.exp((-L_A - 42) / 92)), 0, 1) D = floatX([1, 1, 1]) # Discount the illuminant fully k = 1 / (5 * L_A + 1) D_rgb = D * Y_w / RGB_w + 1 - D F_L = 0.2 * k**4 * (5 * L_A) + 0.1 * (1 - k**4)**2 * (5 * L_A)**(1/3) n = Y_b / Y_w z = 1.48 + T.sqrt(n) N_bb = 0.725 * (1/n)**0.2 N_cb = N_bb RGB_wc = D_rgb * RGB_w RGB_wp = T.dot(T.dot(RGB_wc, M_CAT02_inv), M_HPE) RGB_aw_i = (F_L * RGB_wp / 100)**0.42 RGB_aw = 400 * RGB_aw_i / (RGB_aw_i + 27.13) + 0.1 A_w = (T.sum(RGB_aw * [2, 1, 1/20], axis=-1) - 0.305) * N_bb RGB_linear = T.maximum(EPS, RGB)**2.2 XYZ = T.dot(RGB_linear, M_SRGB_to_XYZ) * Y_w RGB_ = T.dot(XYZ, M_CAT02) RGB_c = D_rgb * RGB_ RGB_p = T.dot(T.dot(RGB_c, M_CAT02_inv), M_HPE) RGB_ap_p_i = (F_L * RGB_p / 100)**0.42 RGB_ap_n_i = (-F_L * RGB_p / 100)**0.42 RGB_ap_p = 400 * RGB_ap_p_i / (RGB_ap_p_i + 27.13) + 0.1 RGB_ap_n = -400 * RGB_ap_n_i / (RGB_ap_n_i + 27.13) + 0.1 RGB_ap = T.switch(RGB_ap_p >= 0, RGB_ap_p, RGB_ap_n) a = T.sum(RGB_ap * [1, -12/11, 1/11], axis=-1) b = T.sum(RGB_ap * [1/9, 1/9, -2/9], axis=-1) h = T.rad2deg(T.arctan2(b, a)) h_p = T.switch(h < 0, h + 360, h) e_t = (T.cos(h_p * np.pi / 180 + 2) + 3.8) / 4 A = (T.sum(RGB_ap * [2, 1, 1/20], axis=-1) - 0.305) * N_bb J = 100 * T.maximum(0, A / A_w)**(c * z) t_num = 50000/13 * N_c * N_cb * e_t * T.sqrt(a**2 + b**2) t = t_num / T.sum(RGB_ap * [1, 1, 21/20], axis=-1) C = t**0.9 * T.sqrt(J / 100) * (1.64 - 0.29**n)**0.73 M = C * F_L**0.25 K_L, c_1, c_2 = 1, 0.007, 0.0228 J_p = (1 + 100 * c_1) * J / (1 + c_1 * J) M_p = (1 / c_2) * T.log(1 + c_2 * M) a_Mp = M_p * T.cos(T.deg2rad(h_p)) b_Mp = M_p * T.sin(T.deg2rad(h_p)) return T.stack([J_p, a_Mp, b_Mp], axis=-1)
def jacobian_sq(latitude, R = 6365.902): """ jacobian_sq(latitude) Computes the "square root" (Cholesky factor) of the Jacobian of the cartesian projection from polar coordinates (in degrees longitude, latitude) onto cartesian coordinates (in km east/west, north/south) at a given latitude (the projection's Jacobian is invariante wrt. longitude). """ return R*(np.pi/180.0)*(abs(tt.cos(tt.deg2rad(latitude)))*np.array([[1.0, 0.0], [0.0, 0.0]])+np.array([[0.0, 0.0],[0.0, 1.0]]))
def dist(self, y_pred, y): """A helper method that computes distance between two points on the surface of earth according to their coordinates. Inputs are tensors. """ y_pred_ra = T.deg2rad(y_pred) y_ra = T.deg2rad(y) lat1 = y_pred_ra[:, 0] lat2 = y_ra[:, 0] dlon = (y_pred_ra - y_ra)[:, 1] EARTH_R = 6372.8 y = T.sqrt( (T.cos(lat2) * T.sin(dlon)) ** 2 + (T.cos(lat1) * T.sin(lat2) - T.sin(lat1) * T.cos(lat2) * T.cos(dlon)) ** 2 ) x = T.sin(lat1) * T.sin(lat2) + T.cos(lat1) * T.cos(lat2) * T.cos(dlon) c = T.arctan2(y, x) return EARTH_R * c
def th_haversine(): """Returns a reference to the compiled Haversine distance function""" from theano import tensor as T from theano import function from .vectorops import floatX coords1 = T.matrix("Coords1", dtype=floatX) coords2 = T.matrix("Coords2", dtype=floatX) R = np.array([6367], dtype="int32") # Approximate radius of Mother Earth in kms coords1 = T.deg2rad(coords1) coords2 = T.deg2rad(coords2) lon1, lat1 = coords1[:, 0], coords1[:, 1] lon2, lat2 = coords2[:, 0], coords2[:, 1] dlon = lon1 - lon2 dlat = lat1 - lat2 d = T.sin(dlat / 2) ** 2 + T.cos(lat1) * T.cos(lat2) * T.sin(dlon / 2) ** 2 e = 2 * T.arcsin(T.sqrt(d)) d_haversine = e * R f_ = function([coords1, coords2], outputs=d_haversine) return f_
def jmh_to_jab(JMh): """Converts cylindrical (JMh) CAM02-UCS colors to rectangular (Jab) format.""" J, M, h = JMh[:, 0], JMh[:, 1], JMh[:, 2] a = M * T.cos(T.deg2rad(h)) b = M * T.sin(T.deg2rad(h)) return T.stack([J, a, b], axis=-1)