Exemplo n.º 1
0
def test():
    rObj = RPN('write.rpn', mode='w')

    nx = 20
    ny = 40

    data = np.zeros((nx, ny))
    for i in range(nx):
        for j in range(ny):
            data[i, j] = i**2 + j**2

    print('before ', data.shape, data.min(), data.max(), data.mean())
    plt.figure()
    plt.title('before')
    plt.pcolormesh(data)
    plt.colorbar()

    rObj.write_2D_field('test', level=1, data=data, grid_type='')
    rObj.close()

    rObj = RPN('write.rpn')
    x = rObj.get_first_record_for_name('test')
    rObj.close()

    print('after ', x.shape, x.min(), x.max(), x.mean())

    plt.figure()
    plt.title('after')
    plt.pcolormesh(x)
    plt.colorbar()
    plt.show()
Exemplo n.º 2
0
def test_FV_AV(path='data/pm1957090100_00589248p'):
    r = RPN(path)
    av = r.get_first_record_for_name('AV')
    fv = r.get_first_record_for_name_and_level(varname='FV', level=5)

    nx, ny = av[:, :, 0].shape
    ratio = np.zeros((nx, ny))

    for i in range(nx):
        for j in range(ny):
            if fv[i, j] != 0:
                ratio[i, j] = av[i, j] / fv[i, j]

    print(np.max(av))
    print(np.max(fv))
    print(np.max(av) / np.max(fv))

    plt.figure()
    plt.imshow(av[:, :, 0])
    plt.colorbar()

    plt.figure()
    plt.imshow(fv[:, :, 0])
    plt.colorbar()

    plt.show()
Exemplo n.º 3
0
def test():
    rObj = RPN('write.rpn', mode = 'w')

    nx = 20
    ny = 40

    data = np.zeros((nx, ny))
    for i in range(nx):
        for j in range(ny):
            data[i, j] = i ** 2 + j ** 2

    print('before ', data.shape, data.min(), data.max(), data.mean())
    plt.figure()
    plt.title('before')
    plt.pcolormesh(data)
    plt.colorbar()


    rObj.write_2D_field('test', level = 1, data = data, grid_type = '')
    rObj.close()

    rObj = RPN('write.rpn')
    x = rObj.get_first_record_for_name('test')
    rObj.close()

    print('after ', x.shape, x.min(), x.max(), x.mean())


    plt.figure()
    plt.title('after')
    plt.pcolormesh(x)
    plt.colorbar()
    plt.show()
Exemplo n.º 4
0
def test_FV_AV(path = 'data/pm1957090100_00589248p'):
    r = RPN(path)
    av = r.get_first_record_for_name('AV')
    fv = r.get_first_record_for_name_and_level(varname = 'FV', level = 5)
    
    nx, ny = av[:,:,0].shape
    ratio = np.zeros((nx, ny))

    for i in range(nx):
        for j in range(ny):
            if fv[i, j] != 0:
                ratio[i, j] = av[i, j] / fv[i, j]

    

    print(np.max(av))
    print(np.max(fv))
    print(np.max(av) / np.max(fv))

    plt.figure()
    plt.imshow(av[:,:,0])
    plt.colorbar()

    plt.figure()
    plt.imshow(fv[:,:,0])
    plt.colorbar()

    plt.show()
Exemplo n.º 5
0
def test():
    path = 'data/pm1998010100-00-00_00000000p'
    rObj = RPN(path)
    data = rObj.get_first_record_for_name('STBM')

    print(data[data < 0])
    print(data.min(), data.max(), data.mean())
    data = np.ma.masked_where(data < 0, data)

    print(np.ma.min(data))

    plt.pcolormesh(data.transpose())
    plt.colorbar()

    plt.show()
Exemplo n.º 6
0
def test():
    path = 'data/pm1998010100-00-00_00000000p'
    rObj = RPN(path)
    data = rObj.get_first_record_for_name('STBM')

    print(data[data < 0])
    print(data.min(), data.max(), data.mean())
    data = np.ma.masked_where(data < 0, data)

    print(np.ma.min(data))

    plt.pcolormesh(data.transpose())
    plt.colorbar()


    plt.show()
Exemplo n.º 7
0
def calculate_seasonal_mean(data_path = "", field_name = "STFL", file_prefix = None, months = None):
    """
    calculates seasonal means,
    months - list of months when the averaging is performed 1 = Jan, ..., 12 = Dec
    TODO: implement
    """

    result = None
    field_count = 0.0
    lons, lats = None, None
    for monthFolder in os.listdir(data_path):

        monthPath = os.path.join(data_path, monthFolder)

        for fName in os.listdir(monthPath):

            if file_prefix is not None:
                if not fName.startswith(file_prefix):
                    continue

            rObj = RPN(os.path.join(monthPath, fName))
            field = rObj.get_first_record_for_name(field_name)

            vDate = rObj.get_current_validity_date()
            originDate = rObj.get_dateo_of_last_read_record()


            print("-" * 10)
            print("validity date, origin date", vDate, originDate)
            print("-" * 10)

            if result is None:
                result = field
                lons, lats = rObj.get_longitudes_and_latitudes()
            else:
                result = (field + result * field_count) / ( field_count + 1.0 )
            rObj.close()
            field_count += 1.0




    pass
Exemplo n.º 8
0
def calculate_seasonal_mean(data_path="",
                            field_name="STFL",
                            file_prefix=None,
                            months=None):
    """
    calculates seasonal means,
    months - list of months when the averaging is performed 1 = Jan, ..., 12 = Dec
    TODO: implement
    """

    result = None
    field_count = 0.0
    lons, lats = None, None
    for monthFolder in os.listdir(data_path):

        monthPath = os.path.join(data_path, monthFolder)

        for fName in os.listdir(monthPath):

            if file_prefix is not None:
                if not fName.startswith(file_prefix):
                    continue

            rObj = RPN(os.path.join(monthPath, fName))
            field = rObj.get_first_record_for_name(field_name)

            vDate = rObj.get_current_validity_date()
            originDate = rObj.get_dateo_of_last_read_record()

            print("-" * 10)
            print("validity date, origin date", vDate, originDate)
            print("-" * 10)

            if result is None:
                result = field
                lons, lats = rObj.get_longitudes_and_latitudes()
            else:
                result = (field + result * field_count) / (field_count + 1.0)
            rObj.close()
            field_count += 1.0

    pass
Exemplo n.º 9
0
def calculate_mean_field(data_path = "", field_name = "STFL", file_prefix = None):
    """
    Calculates annual mean field from rpn files
    data_path = path to the Samples folder
    """
    result = None
    field_count = 0.0
    lons, lats = None, None
    for monthFolder in os.listdir(data_path):

        monthPath = os.path.join(data_path, monthFolder)

        for fName in os.listdir(monthPath):

            if file_prefix is not None:
                if not fName.startswith(file_prefix):
                    continue

            rObj = RPN(os.path.join(monthPath, fName))
            field = rObj.get_first_record_for_name(field_name)

            vDate = rObj.get_current_validity_date()
            originDate = rObj.get_dateo_of_last_read_record()


            print("-" * 10)
            print("validity date, origin date", vDate, originDate)
            print(rObj.get_datetime_for_the_last_read_record())
            print("-" * 10)


            if result is None:
                result = field
                lons, lats = rObj.get_longitudes_and_latitudes()
            else:
                result = (field + result * field_count) / ( field_count + 1.0 )
            rObj.close()
            field_count += 1.0

    return lons, lats, result
Exemplo n.º 10
0
def calculate_mean_field(data_path="", field_name="STFL", file_prefix=None):
    """
    Calculates annual mean field from rpn files
    data_path = path to the Samples folder
    """
    result = None
    field_count = 0.0
    lons, lats = None, None
    for monthFolder in os.listdir(data_path):

        monthPath = os.path.join(data_path, monthFolder)

        for fName in os.listdir(monthPath):

            if file_prefix is not None:
                if not fName.startswith(file_prefix):
                    continue

            rObj = RPN(os.path.join(monthPath, fName))
            field = rObj.get_first_record_for_name(field_name)

            vDate = rObj.get_current_validity_date()
            originDate = rObj.get_dateo_of_last_read_record()

            print("-" * 10)
            print("validity date, origin date", vDate, originDate)
            print(rObj.get_datetime_for_the_last_read_record())
            print("-" * 10)

            if result is None:
                result = field
                lons, lats = rObj.get_longitudes_and_latitudes()
            else:
                result = (field + result * field_count) / (field_count + 1.0)
            rObj.close()
            field_count += 1.0

    return lons, lats, result