示例#1
0
def gen_rand_params(params=None, num=1):
    if params is None:
        params = rdb.loadObject('orbparams_minmax.p')
    rand_params = ({name:np.random.uniform(low=values[0], high=values[1], 
                    size=num) for name, values in params.items()})
    rand_params['e'] = (rand_params['a'] - rand_params['q'])/rand_params['a']
    rand_params['per'] = 2*pi*np.sqrt(rand_params['a']**3/(G*M))/86400.0
    if num == 1:
        print "rand_params:", rand_params
    return rand_params
示例#2
0
def gen_rand_params(params=None, num=1):
    if params is None:
        params = rdb.loadObject('orbparams_minmax.p')
    rand_params = ({
        name: np.random.uniform(low=values[0], high=values[1], size=num)
        for name, values in params.items()
    })
    rand_params['e'] = (rand_params['a'] - rand_params['q']) / rand_params['a']
    rand_params['per'] = 2 * pi * np.sqrt(rand_params['a']**3 /
                                          (G * M)) / 86400.0
    if num == 1:
        print "rand_params:", rand_params
    return rand_params
def gen_rand_params(params=None, distdict=None, num=1):
    """
    Deprecated function for random orbit parameters generation. 
    May produce orbits with negative eccentricity.
    """
    if distdict is None:
        distdict = rdb.loadObject('./asteroid_data/param_dist.p')

    #     if params is None:
    #         params = rdb.loadObject('./asteroid_data/orbparams_minmax.p')
    #     rand_params = ({name:np.random.uniform(low=values[0], high=values[1], 
    #                     size=num) for name, values in params.items()})
    # else:

    rand_params = ({name: contdist.get_rvs(size=num)
                    for name, contdist in distdict.items()})
    try:
        rand_params['e'] = (rand_params['a'] - rand_params['q'])/rand_params['a']
        rand_params['per'] = 2*pi*np.sqrt((rand_params['a']*AU)**3/(G*M))/86400.0
    except:
        pass
    # if num == 1:
    #     print "rand_params:", rand_params
    return rand_params
示例#4
0
                    size=num) for name, values in params.items()})
    rand_params['e'] = (rand_params['a'] - rand_params['q'])/rand_params['a']
    rand_params['per'] = 2*pi*np.sqrt(rand_params['a']**3/(G*M))/86400.0
    if num == 1:
        print "rand_params:", rand_params
    return rand_params

def gen_rand_orbits(params, names, num=100):
    rand_params = gen_rand_params(params=params, num=num)
    randdata = np.array([rand_params[name] for name in names]).T
    return randdata


if __name__ == '__main__':

    haz = rdb.loadObject('./asteroid_data/haz_test.p')
    nohaz = rdb.loadObject('./asteroid_data/nohaz_test.p')

    names = ['a', 'i', 'w', 'om', 'q', 'n', 'ma', 'epoch']
    params = get_param_bounds(haz, nohaz, names)
    rdb.dumpObject(params, './asteroid_data/orbparams_minmax.p')
    gen_rand_params(params)
    
    print "init orbit generation..."
    names = ['a', 'e', 'i', 'w', 'om', 'q']
    randdata = gen_rand_orbits(params, names, num=1e2)
    print "orbit generation finished.", randdata.shape

    dataframe = pd.DataFrame(randdata, columns=names)
    
    ### CALCULATE MOID ###
    # print len(rand_params['e']), type(rand_params['e'])
    # print len(rand_params['i']), type(rand_params['i'])
    # print len(rand_params['om']), type(rand_params['om'])
    # print len(rand_params['q']), type(rand_params['q'])
    # print len(rand_params['w']), type(rand_params['w'])
    # print len(rand_params['a']), type(rand_params['a'])

    names_extend = rand_params.keys()
    randdata = np.array([rand_params[name] for name in names_extend]).T
    dataframe = pd.DataFrame(randdata, columns=names_extend)
    return dataframe


if __name__ == '__main__':

    haz = rdb.loadObject('./asteroid_data/haz_test.p')
    nohaz = rdb.loadObject('./asteroid_data/nohaz_test.p')
    
    names = ['a', 'i', 'w', 'om', 'q', 'n', 'ma', 'epoch']
    data_full = pd.concat([haz[names], nohaz[names]])
    params = get_param_bounds(data_full, names)
    rdb.dumpObject(params, './asteroid_data/orbparams_minmax.p')
    # gen_rand_params(params=params)
    
    print "init orbit generation..."
    # names = ['a', 'e', 'i', 'w', 'om', 'q']
    # gkde = GaussianKDE('gkde', data_full['w'].as_matrix())
    # gkde2 = GaussianKDE('gkde2', data_full['om'].as_matrix())
    # gkde_a = GaussianKDE('gkde_a', data_full['a'].as_matrix())
    # kde_a = GaussianKDE(data_full['a'])
    names = ['a', 'i', 'w', 'om', 'q']