def test_create_non_equidistant_calendar():
    dfs0file = r'random12.dfs0'
    data = np.random.random([1000, 2])
    data[2, :] = np.nan
    start_time = datetime.datetime(2017, 1, 1)
    time_vector = []
    for i in range(1000):
        time_vector.append(start_time + datetime.timedelta(hours=i * 0.1))
    title = 'Hello Test'
    names = ['VarFun01', 'NotFun']
    variable_type = [100000, 100000]
    unit = [1000, 1000]
    data_value_type = [0, 1]

    dfs = dfs0.dfs0()
    dfs.create_non_equidistant_calendar(dfs0file=dfs0file,
                                        data=data,
                                        time_vector=time_vector,
                                        names=names,
                                        title=title,
                                        variable_type=variable_type,
                                        unit=unit,
                                        data_value_type=data_value_type)

    assert True
Esempio n. 2
0
def test_create_timestep_7days():

    dfs0File = r"zeros_ones.dfs0"

    data = []

    nt = 10
    d1 = np.zeros(nt)
    data.append(d1)
    d2 = np.ones(nt)
    data.append(d2)

    names = ["Zeros", "Ones"]

    dfs = dfs0.dfs0()

    dfs.create(filename=dfs0File,
               data=data,
               names=names,
               title="Zeros and ones",
               timeseries_unit=TimeStep.DAY,
               dt=7)

    assert True

    res = dfs.read(dfs0File)

    dt = res.time[1] - res.time[0]

    assert dt == timedelta(days=7)

    os.remove(dfs0File)
def test_create_equidistant_calendar():

    dfs0file = r'random11.dfs0'
    data = np.random.random([1000, 2])
    data[2, :] = np.nan
    start_time = datetime.datetime(2017, 1, 1)
    timeseries_unit = 1402
    title = 'Hello Test'
    names = ['VarFun01', 'NotFun']
    variable_type = [100000, 100000]
    unit = [1000, 1000]
    data_value_type = [0, 1]
    dt = 5
    dfs = dfs0.dfs0()
    dfs.create_equidistant_calendar(dfs0file=dfs0file,
                                    data=data,
                                    start_time=start_time,
                                    timeseries_unit=timeseries_unit,
                                    dt=dt,
                                    names=names,
                                    title=title,
                                    variable_type=variable_type,
                                    unit=unit,
                                    data_value_type=data_value_type)

    #os.remove(dfs0file)
    assert True
Esempio n. 4
0
def test_read_dfs0_to_matrix():
    dfs0file = r'tests/testdata/random.dfs0'

    dfs = dfs0.dfs0()
    mat = dfs.read(dfs0file, indices=[0])[0]

    assert np.isnan(mat[2, 0])
Esempio n. 5
0
def test_read_dfs0_to_matrix():
    dfs0file = r'tests/testdata/random.dfs0'

    dfs = dfs0.dfs0()
    (data, t, names) = dfs.read(filename=dfs0file)

    assert len(data) == 2
Esempio n. 6
0
def test_read_dfs0_to_pandas():

    dfs0file = r'tests/testdata/random.dfs0'

    dfs = dfs0.dfs0()
    pd = dfs.read_to_pandas(dfs0file)

    assert np.isnan(pd[pd.columns[0]][2])
Esempio n. 7
0
def test_read_dfs0_single_item():

    dfs0file = r'tests/testdata/random.dfs0'

    dfs = dfs0.dfs0()
    (data, t, names) = dfs.read(dfs0file, item_numbers=[1])

    assert len(data) == 1
Esempio n. 8
0
def test_read_dfs0_to_pandas_single_item():

    dfs0file = r'tests/testdata/random.dfs0'

    dfs = dfs0.dfs0()
    df = dfs.read_to_pandas(dfs0file, item_numbers=[1])

    assert df.shape[1] == 1
Esempio n. 9
0
def test_read_dfs0_single_item_named_access():

    dfs0file = r'tests/testdata/random.dfs0'

    dfs = dfs0.dfs0()
    res = dfs.read(dfs0file, item_numbers=[1])
    data = res.data

    assert len(data) == 1
def convertDFS02Excel(dfs0Filename, outputFilename="out.csv"):
    dfs = dfs0.dfs0()
    data, t, names = dfs.read(dfs0Filename)
    print("outputfilename = " + outputFilename)
    fileHandle = open(outputFilename, "w")
    fileHandle.write(names[0] + "\n")
    for i in range(len(data)):
        line = str(t[i]) + ',' + str(data[i][0]) + '\n'
        fileHandle.write(line)
    fileHandle.close()
    print('data')
    print(data[0])
    print('t')
    print(t[0])
    print('names')
    print(names)
Esempio n. 11
0
def test_simple_create():

    dfs0File = r"simple.dfs0"

    data = []

    nt = 100
    d = np.random.random([nt])
    data.append(d)

    dfs = dfs0.dfs0()

    dfs.create(filename=dfs0File, data=data)

    assert True
    os.remove(dfs0File)
Esempio n. 12
0
def test_multiple_create():

    dfs0File = r"zeros_ones.dfs0"

    data = []

    nt = 10
    d1 = np.zeros(nt)
    data.append(d1)
    d2 = np.ones(nt)
    data.append(d2)

    names = ["Zeros", "Ones"]

    dfs = dfs0.dfs0()

    dfs.create(filename=dfs0File,
               data=data,
               names=names,
               title="Zeros and ones")

    assert True
    os.remove(dfs0File)
def dfs0Generating(inputFilename,
                   outputFilename='default',
                   titleName="Rainfall",
                   name='Binh_Dinh'):
    dfs0file = outputFilename + '.dfs0'
    # dfs0file_1 = outputFilename + 'bis.dfs0'
    readData = np.loadtxt(fname=inputFilename,
                          delimiter=',',
                          skiprows=0,
                          dtype='str')
    print("inputfile  = " + inputFilename)
    print('outputfile = ' + outputFilename)
    if (len(readData) == 0):
        return
    newData = []
    for i in readData[:, 1]:
        newData.append([float(i)])
    newData1 = np.asarray(newData)

    time_vector = []
    for i in range(len(newData)):
        time_vector.append(
            datetime.strptime(readData[i, 0], '%d-%m-%Y %H:%M:%S'))

    title = titleName
    names = [name]
    if (titleName == 'Rainfall'):
        variable_type = [100004]
        unit = [1002]  #1000 meter, 1001 km, 1002 mm
        data_value_type = [2]
    elif (titleName == 'Evaporation'):
        variable_type = [100005]
        unit = [1002]  #1000 meter, 1001 km, 1002 mm
        data_value_type = [2]
    elif (titleName == 'WaterLevel'):
        variable_type = [100000]
        unit = [1000]  #1000 meter, 1001 km, 1002 mm
        data_value_type = [0]
    else:
        variable_type = [100004]
        unit = [1002]  #1000 meter, 1001 km, 1002 mm
        data_value_type = [2]
    dfs = dfs0.dfs0()
    dfs.create_non_equidistant_calendar(dfs0file=dfs0file,
                                        data=newData1,
                                        time_vector=time_vector,
                                        names=names,
                                        title=title,
                                        variable_type=variable_type,
                                        unit=unit,
                                        data_value_type=data_value_type)

    start_time = time_vector[0]
    #1400 = 5s
    #1401 = 5m
    #1402 = 5h
    #1403 =
    #1404 = 5h
    # timeseries_unit = 1403
    # dt = 5
    # dfs.create_equidistant_calendar(dfs0file=dfs0file_1, data=newData1,
    #                                 start_time=start_time,
    #                                 timeseries_unit=timeseries_unit, dt=dt,
    #                                 names=names, title=title,
    #                                 variable_type=variable_type,
    #                                 unit=unit, data_value_type=data_value_type)
    assert True