def generateRotation(axis, angle, radians=True):
    if not radians:
        angle = np.radian(angle)

    sqr_a = axis.x*axis.x
    sqr_b = axis.y*axis.y
    sqr_c = axis.z*axis.z
    len2  = sqr_a+sqr_b+sqr_c

    k2    = math.cos(angle)
    k1    = (1.0-k2)/len2
    k3    = math.sin(angle)/math.sqrt(len2)
    k1ab  = k1*axis.x*axis.y
    k1ac  = k1*axis.x*axis.z
    k1bc  = k1*axis.y*axis.z
    k3a   = k3*axis.x
    k3b   = k3*axis.y
    k3c   = k3*axis.z

    rotation = np.matrix([[k1*sqr_a+k2, k1ab-k3c, k1ac+k3b],
                          [k1ab+k3c, k1*sqr_b+k2, k1bc-k3a],
                          [k1ac-k3b, k1bc+k3a, k1*sqr_c+k2]],
                         dtype=np.float)
    rotation[np.abs(rotation) < 1.e-15] = 0.

    checkRotation(rotation)
    return rotation
Example #2
0
def dip_rand_samp(dip, err, num, threshold=30, output='degrees'):
    """
    Creates a uniform random sample between min(dip+err, threshold)
    and returns both the sample and the fraction (decimal) of the total
    dip range that is below the threshold (this fraction should be multiplied
    by any final probabilities of observing an earthquake on a dip below the
    threshold value).

    Assumes input dips are in degrees (it's dip...) but output can be in
    radians, if desired.

    Returns: tuple [samp, fraction]
    """
    if threshold != None:

        dip_min = dip - err
        dip_max = min((dip + err), threshold)

        dip_samp = np.random.rand(num) * (dip_max - dip_min) + dip_min

        frac = (dip_max - dip_min) / float(2 * err)

    else:
        dip_min = dip - err
        dip_max = dip + err

        dip_samp = np.random.rand(num) * (dip_max - dip_min) + dip_min

        frac = 1

    if output == 'radians':
        dip_samp = np.radian(dip_samp)

    return [dip_samp, frac]
def dip_rand_samp(dip, err, num, threshold=30, output='degrees'):
    """
    Creates a uniform random sample between min(dip+err, threshold)
    and returns both the sample and the fraction (decimal) of the total
    dip range that is below the threshold (this fraction should be multiplied
    by any final probabilities of observing an earthquake on a dip below the
    threshold value).

    Assumes input dips are in degrees (it's dip...) but output can be in
    radians, if desired.

    Returns: tuple [samp, fraction]
    """
    if threshold != None:

        dip_min = dip - err
        dip_max = min((dip + err), threshold)
    
        dip_samp = np.random.rand(num) * (dip_max - dip_min) + dip_min

        frac = (dip_max-dip_min) / float(2 * err)

    else:
        dip_min = dip - err
        dip_max = dip + err
        
        dip_samp = np.random.rand(num) * (dip_max - dip_min) + dip_min

        frac = 1

    if output == 'radians':
        dip_samp = np.radian(dip_samp)

    return [dip_samp, frac]
Example #4
0
def generateRotation(axis, angle, radians=True):
    if not radians:
        angle = np.radian(angle)

    sqr_a = axis.x*axis.x
    sqr_b = axis.y*axis.y
    sqr_c = axis.z*axis.z
    len2  = sqr_a+sqr_b+sqr_c

    k2    = math.cos(angle)
    k1    = (1.0-k2)/len2
    k3    = math.sin(angle)/math.sqrt(len2)
    k1ab  = k1*axis.x*axis.y
    k1ac  = k1*axis.x*axis.z
    k1bc  = k1*axis.y*axis.z
    k3a   = k3*axis.x
    k3b   = k3*axis.y
    k3c   = k3*axis.z

    rotation = np.matrix([[k1*sqr_a+k2, k1ab-k3c, k1ac+k3b],
                          [k1ab+k3c, k1*sqr_b+k2, k1bc-k3a],
                          [k1ac-k3b, k1bc+k3a, k1*sqr_c+k2]],
                         dtype=np.float)
    rotation[np.abs(rotation) < 1.e-15] = 0.

    checkRotation(rotation)
    return rotation
Example #5
0
 def filter_curve(self, angle):
     angle = np.radian(angle)
     mask = np.ones(self.dim)
     mask[self.index_nan] = np.nan
     # !!! En lugar de self.teta utilizar (psi-psi0)
     index = np.where(np.abs(self.teta * mask - np.pi / 2) > angle)
     index_red = np.where((self.teta * mask - np.pi / 2) > angle)
     index_blue = np.where((np.pi / 2 - self.teta * mask) > angle)
     filterrc = self.sort_curve(self.arcsec, self.Vc, self.sigmaVc, index)
     appr = self.sort_curve(self.arcsec, self.Vc, self.sigmaVc, index_blue)
     receed = self.sort_curve(self.arcsec, self.Vc, self.sigmaVc, index_red)
     # Those output velocity curves will be in [km/s],[arcsec]
     return filterrc, appr, receed
Example #6
0
import numpy as np
import pandas as pd
from sklearn.cluster import DBSCAN
lat = np.array([22.45, 29.45, 36.567])
lon = np.array([73.345, 75.34, 95.567])
minimum_samples = 2
minimum_dist = 2 / 6371.0088  #distance in KM / 6371.0088
X = np.column_stack([np.radian(lat), np.radians(lon)])
db = DBSCAN(eps=minimum_dist,
            min_samples=minimum_samples,
            algorithm='ball_tree',
            metric='haversine').fit(X)
db.labels_

#This code was in a Tableau workbook to find hot spots in a geography
# db.labels_ gives the cluster labels as 0,1,.. .Label -1 is noise.
Example #7
0
from numpy import genfromtxt
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import os.path
import math
from math import pi
from helper import *
#%%

position_data = genfromtxt('Coordinate_Meas_1', delimiter=',')
polar_data = np.zeros((position_data.shape))
for i in range(0, position_data.shape[1]):
    polar_data[:, i] = cart2pol(position_data[0, i], position_data[1, i])
# %% Polar data

np.radian(2)

heading = pi
import numpy as np

a = np.ones(10)
selfPosition = np.array((0, 0))
r = polar_data[0, :]
t = polar_data[1, :]
r.shape = (r.size, 1)
t.shape = (t.size, 1)
type(heading)
t = t + heading * np.ones((t.size, 1))
self_x = selfPosition[0] * np.ones((t.size, 1))
self_y = selfPosition[1] * np.ones((t.size, 1))
self_x.shape = (t.size, 1)