Esempio n. 1
0
def get_lon_lat(
    path='/home/huziy/skynet3_rech1/gemclim/quebec/Samples/quebec_220x220_199912/pm1999050100_00068760p'
):
    r = RPN(path)
    lons, lats = r.get_longitudes_and_latitudes()
    r.close()
    return lons, lats
Esempio n. 2
0
def test():

    path = 'data/pm1957090100_00589248p'
    #path = 'data/crcm_sim_with_lakes/data_selected/Coupled11_36cpu_Test_C_198505/pm1957090100_00727920p'
    rpn = RPN(path)
    data = rpn.get_first_record_for_name_and_level(varname = 'FV', level = 7 )

    lons, lats = rpn.get_longitudes_and_latitudes()

    print(lons.shape, np.min(lons), np.max(lons))
    print(lats.shape, np.min(lats), np.max(lats))
#    print data.shape

#    plot_field_2d(lons, lats, data[:,:,0])

    print(data.shape)
    plot_field_2d(lons, lats, data)


    plt.savefig('plot.png')
    #plt.figure()
    #plt.imshow(np.transpose(lons[:,:]), origin = 'lower')
    #plt.imshow(np.transpose(data[:,:]), origin = 'lower') #for plotting in order to see i,j we supply j,i

    plt.show()
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
def get_lon_lat(path="/home/huziy/skynet3_rech1/gemclim/quebec/Samples/quebec_220x220_199912/pm1999050100_00068760p"):
    r = RPN(path)
    lons, lats = r.get_longitudes_and_latitudes()
    r.close()
    return lons, lats
Esempio n. 8
0
def get_lon_lat(path='data/pm1957090100_00589248p'):
    print('reading lons and lats from the file %s' % path)
    r = RPN(path)
    lons, lats = r.get_longitudes_and_latitudes()
    r.close()
    return lons, lats
Esempio n. 9
0
def get_lon_lat(path = 'data/pm1957090100_00589248p'):
    print('reading lons and lats from the file %s' % path)
    r = RPN(path)
    lons, lats = r.get_longitudes_and_latitudes()
    r.close()
    return lons, lats