コード例 #1
0
ファイル: test_core.py プロジェクト: ebranlard/iea29-turb
def test_timecon_get_time():
    """verify we get correct time frame"""
    # given
    con_tc = TimeConstraint(np.atleast_2d([0, 0, 0, 119, 0, 1]).T,
                            index=['k', 'x', 'y', 'z', 0, 1],
                            columns=['u_p0'])
    theo_time = con_tc.loc[[0, 1]]  # pulls out last two rows
    # when
    time_vec = con_tc.get_time()
    # then
    np.testing.assert_array_equal(theo_time, time_vec)
コード例 #2
0
def test_data_spectrum_nolabels():
    """test 1)can interpolate with no/incorrect column labels 2) float comparisons"""
    # given
    dt, z, T = 1, 65, 4
    con_tc = TimeConstraint([[0, 0], [0, 0], [0, 0], [60, 70], [9, 17],
                             [11, 20], [10, 18], [9, 16]],
                            index=['k', 'x', 'y', 'z', 0, dt, 2 * dt, 3 * dt],
                            columns=['dog', 'cat'])
    mags_theo = np.abs(np.fft.rfft(con_tc.get_time(), axis=0) / (T / dt))
    spec_theo = np.mean(2 * mags_theo**2 * T, axis=1).reshape(-1, 1)
    f = np.arange(mags_theo.shape[0]) / T + 1e-12
    # when
    spec = data_spectrum(f, 0, 0, z, con_tc=con_tc)
    # then
    np.testing.assert_array_almost_equal(spec, spec_theo)
コード例 #3
0
def test_data_spectrum():
    """verify 1) data interpolator implement in data_spectrum works, 2) dtype"""
    # given
    f, T, dt = [0, 0.5], 2, 1
    k, y, z = np.repeat(range(3),
                        3), np.zeros(9, dtype=int), np.tile([40, 70, 100], 3)
    con_tc = TimeConstraint(
        [[0, 0, 1, 1, 2, 2], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
         [50, 90, 50, 90, 50, 90], [0, 0, 0, 0, 0, 0], [1, 2, 3, 4, 5, 6]],
        index=['k', 'x', 'y', 'z', 0.0, 1.0])
    spec_cols = 2 * np.abs(np.fft.rfft(con_tc.get_time(), axis=0) /
                           (T / dt))**2 * T
    spec_theo = np.tile(
        np.interp([0, 0.5, 1, 2, 2.5, 3, 4, 4.5, 5], np.arange(6),
                  spec_cols[0]), (2, 1))
    # when
    spec_arr = data_spectrum(f, k, y, z, con_tc=con_tc)
    # then
    np.testing.assert_array_equal(spec_theo, spec_arr)
コード例 #4
0
    print('running file ' + savename)
    # import pdb; pdb.set_trace()
    con_tc = TimeConstraint(con_df)  # Constraining in time
    con_tc.index = con_tc.index.map(lambda x: float(x)
                                    if (x not in 'kxyz') else x)

    # Inputs to constrained Turbulence:
    spat_df = gen_spat_grid(GridY.iloc[0, :], GridZ.iloc[
        0, :])  # create our spatial pandas dataframe with our grid data.
    kwargs = {
        'u_ref': Variables.iloc[0, 2],
        'z_ref': Variables.iloc[0, 4],
        'z_hub':
        Variables.iloc[0, 4],  # necessary keyword arguments for IEC turbulence
        'T': con_tc.get_T(),
        'dt': con_tc.get_time().index[1],
        'turb_class': Variables.iloc[0, -1],
        'alpha': Variables.iloc[0, -2],
        'seed': Variables.iloc[0, 9]
    }  # simulation length (s) and time step (s)

    wsp_funcin = Variables.iloc[0, 6]
    sig_funcin = Variables.iloc[0, 7]
    spec_funcin = Variables.iloc[0, 8]
    interp_data2 = Variables.iloc[0, 10]
    nf_chunkin = Variables.iloc[0, 3]
    coh_model_in = Variables.iloc[0, 5]

    if interp_data2 == "Take_list":
        # here we have to define all the cases in wsp_func, spec_func and sig_func that we want to use as inputs for "gen_turb":
        if wsp_funcin == 'power_profile':
コード例 #5
0
    GenerateBox=True
    # GenerateBox=False


    # --- Constants and derived params
    pkl_file  = '{}{}.pkl'.format(Case,Suffix)
    pkl_space = '{}{}_space.pkl'.format(Case,Suffix)
    box_file  = '{}{}{}.bts'.format(OUT_Folder,Case,Suffix)
    con_file  = '35Hz_data/{}_pyConTurb_tc.csv'.format(Case)
    # --- Loading files
    print('Loading files...')
    sim_ts  = pickle.load(open(pkl_file,'rb'))
    sim_sp = pickle.load(open(pkl_space,'rb'))
    con_tc = TimeConstraint(pd.read_csv(con_file, index_col=0))  # load data from csv directly into tc
    con_tc.index = con_tc.index.map(lambda x: float(x) if (x not in 'kxyz') else x)  # index cleaning
    con_ts = con_tc.get_time()
    con_sp = con_tc.loc[['k','x','y','z']]

    RefPoints = con_sp.filter(regex='u_', axis=1).loc[['x','y','z']]
    print(RefPoints)
    print(sim_ts.columns)
    print(sim_sp.columns)

    if GenerateBox:
        print('Generating turbulence file:',box_file)
        ts = TurbSimFile()
        ts['y'] = np.unique(np.around(sim_sp.loc['y'].values,7))
        ts['z'] = np.unique(np.around(sim_sp.loc['z'].values,7))
        ts['t'] = np.around(sim_ts.index,10)
        ts['zHub']= (ts['z'][0]+ts['z'][-1])/2 # Not the real hub height
        nt      =  len(ts['t'])
コード例 #6
0
Suffix=Suffix+'_'+str(ny)'_'+str(nz)

print('>>> Case:   {}'.format(Case))
print('>>> Suffix: {}'.format(Suffix))
print('>>> Write:  {} {}'.format(write_freq_data,combine_freq_data))
print('>>> y:      {} {} {}'.format(ymin,ymax,ny))
print('>>> z:      {} {} {}'.format(zmin,zmax,nz))
h_hub=57;
pkl_file = '{}{}.pkl'.format(Case,Suffix)
pkl_space = '{}{}_space.pkl'.format(Case,Suffix)
con_file = '35Hz_data/{}_pyConTurb_tc.csv'.format(Case)

# --- Constraint time series
con_tc = TimeConstraint(pd.read_csv(con_file, index_col=0))  # load data from csv directly into tc
con_tc.index = con_tc.index.map(lambda x: float(x) if (x not in 'kxyz') else x)  # index cleaning
time_df = con_tc.get_time()
dt      = con_tc.get_time().index[1]
T       = con_tc.get_T()-dt          # TODO
print('>>> Pkl : {}Mb'.format(0.07*ny*nz))
print('>>> T, dt:',T,dt)

# --- Fitting power law and sigma
# alpha,u_ref, my_wsp_func,veer_func = get_wsp_func(con_tc, h_hub, plot   = False)
# my_sig_func                        = get_sigma_func(con_tc, plot = False)
if Case=='A1':
    def my_sig_func(k, y, z, **kwargs):
        sig = np.zeros(y.shape)
        sig[k==0] =  0.46577620264919134*np.exp(-0.009459702869284256*z[k==0])+0.5242096170226613
        sig[k==1] =  0.32501065767141885*np.exp(-0.009059732365499604*z[k==1])+0.4664357892808409
        sig[k==2] =  0.25265083664918636*np.exp(-0.00816719396912162 *z[k==2])+0.27864558900332614
        return sig