def get_mu_star_from_glacier(gdir):
    """ Reads RACMO data and calculates the mean temperature sensitivity
    from RACMO SMB data and snow melt estimates. In a glacier wide average and
    a mean value of the entire RACMO time series. Based on the method described
    in Oerlemans, J., and Reichert, B. (2000).

        Parameters
        ------------
        gdir : :py:class:`oggm.GlacierDirectory`
            the glacier directory to process
        :returns
        Mu_star_racmo mean value in mm.w.e /K-1
        """
    fpath = gdir.dir + '/racmo_data.nc'

    if os.path.exists(fpath):
        with ncDataset(fpath, mode='r') as nc:
            smb = nc.variables['smb'][:]
            melt = nc.variables['snow_melt'][:]
            mu = smb / melt
            mean_mu = np.average(mu,
                                 weights=np.repeat(gdir.rgi_area_km2, len(mu)))
    else:
        print('This glacier has no racmo data ' + gdir.rgi_id)
        mean_mu = None

    return mean_mu
def get_smb31_from_glacier(gdir):
    """ Reads RACMO data and takes a mean over 31 year period of the
        surface mass balance

    Parameters
    ------------
    gdir : :py:class:`oggm.GlacierDirectory`
        the glacier directory to process
    :returns
    smb_31 mean value in km^3/yr
    """
    fpath = gdir.dir + '/racmo_data.nc'

    if os.path.exists(fpath):
        with ncDataset(fpath, mode='r') as nc:
            smb = nc.variables['smb'][:]
            if smb.all() == 0:
                smb_mean = None
                smb_cum = None
                smb_calving_mean = None
                smb_calving_cum = None
                print('This glacier has no racmo data ' + gdir.rgi_id)
            else:
                smb_mean = np.nanmean(smb)
                smb_cum = np.nansum(smb)
                smb_calving_mean = calving_flux_km3yr(gdir, smb_mean)
                smb_calving_cum = calving_flux_km3yr(gdir, smb_cum)
    else:
        print('This glacier has no racmo data ' + gdir.rgi_id)
        smb_mean = None
        smb_cum = None
        smb_calving_mean = None
        smb_calving_cum = None

    return smb_mean, smb_cum, smb_calving_mean, smb_calving_cum
Esempio n. 3
0
def get_smb31_from_glacier(gdir):
    """ Reads RACMO data and takes a mean over a reference period for the
        surface mass balance and adds an uncertainty based on the std
        over the entire data period.
    :param
        gdir: `oggm.GlacierDirectory`
    :return
        out_dic: a dictionary with averages and cumulative estimates of smb in
                 original units and in frontal ablation units.
                 It also includes uncertainty.
    """
    fpath = gdir.dir + '/racmo_data.nc'

    if os.path.exists(fpath):
        with ncDataset(fpath, mode='r') as nc:
            smb = nc.variables['smb'][:]
            std = nc.variables['std'][:]
            if smb.all() == 0:
                smb_mean = None
                smb_std = None
                smb_cum = None
                smb_calving_mean = None
                smb_calving_std = None
                smb_calving_cum = None
                print('This glacier has no racmo data ' + gdir.rgi_id)
            else:
                smb_mean = np.nanmean(smb)
                smb_std = np.nanmean(std)
                smb_cum = np.nansum(smb)
                smb_calving_mean = calving_flux_km3yr(gdir, smb_mean)
                smb_calving_std = calving_flux_km3yr(gdir, smb_std)
                smb_calving_cum = calving_flux_km3yr(gdir, smb_cum)
    else:
        print('This glacier has no racmo data ' + gdir.rgi_id)
        smb_mean = None
        smb_std = None
        smb_cum = None
        smb_calving_mean = None
        smb_calving_std = None
        smb_calving_cum = None

    out_dic = dict(smb_mean=smb_mean,
                   smb_std=smb_std,
                   smb_cum=smb_cum,
                   smb_calving_mean=smb_calving_mean,
                   smb_calving_std=smb_calving_std,
                   smb_calving_cum=smb_calving_cum)

    return out_dic
def process_racmo_data(gdir, racmo_path, time_start=None, time_end=None):
    """Processes and writes RACMO data in each glacier directory.

    Parameters
    ----------
    gdir : :py:class:`oggm.GlacierDirectory`
        the glacier directory to process
    racmo_path: the main path to the RACMO data

    :returns
    writes an nc file in each glacier directory with the RACMO data
    time series of SMB, precipitation, run off and melt for a 31 reference
    period according to X. Fettweis et al. 2017,
     Eric Rignot and Pannir Kanagaratnam, 2006.
    """
    mask_file = os.path.join(racmo_path,
                             'Icemask_Topo_Iceclasses_lon_lat_average_1km.nc')

    smb_file = os.path.join(
        racmo_path, 'smb_rec.1958-2018.BN_RACMO2.3p2_FGRN055_GrIS.MM.nc')

    prcp_file = os.path.join(
        racmo_path, 'precip.1958-2018.BN_RACMO2.3p2_FGRN055_GrIS.MM.nc')

    run_off_file = os.path.join(
        racmo_path, 'runoff.1958-2018.BN_RACMO2.3p2_FGRN055_GrIS.MM.nc')

    melt_file = os.path.join(
        racmo_path, 'snowmelt.1958-2018.BN_RACMO2.3p2_FGRN055_GrIS.MM.nc')

    fall_file = os.path.join(
        racmo_path, 'snowfall.1958-2018.BN_RACMO2.3p2_FGRN055_GrIS.MM.nc')

    # Get files as xarray all units mm. w.e.
    # Surface Mass Balance
    ds_smb = open_racmo(smb_file, mask_file)
    # Total precipitation: solid + Liquid
    ds_prcp = open_racmo(prcp_file)
    # Run off
    ds_run_off = open_racmo(run_off_file)
    # water that result from snow and ice melting
    ds_melt = open_racmo(melt_file)
    # Solid precipitation
    ds_fall = open_racmo(fall_file)

    # crop the data to glacier outline
    smb_sel = crop_racmo_to_glacier_grid(gdir, ds_smb)
    prcp_sel = crop_racmo_to_glacier_grid(gdir, ds_prcp)
    run_off_sel = crop_racmo_to_glacier_grid(gdir, ds_run_off)
    melt_sel = crop_racmo_to_glacier_grid(gdir, ds_melt)
    fall_sel = crop_racmo_to_glacier_grid(gdir, ds_fall)

    # get RACMO time series in 31 year period centered in t*
    smb_31 = get_racmo_time_series(smb_sel,
                                   var_name='SMB_rec',
                                   dim_one='x',
                                   dim_two='y',
                                   dim_three='time',
                                   time_start=time_start,
                                   time_end=time_end)

    prcp_31 = get_racmo_time_series(prcp_sel,
                                    var_name='precipcorr',
                                    dim_one='lon',
                                    dim_two='lat',
                                    dim_three='time',
                                    time_start=time_start,
                                    time_end=time_end)

    run_off_31 = get_racmo_time_series(run_off_sel,
                                       var_name='runoffcorr',
                                       dim_one='lon',
                                       dim_two='lat',
                                       dim_three='time',
                                       time_start=time_start,
                                       time_end=time_end)

    melt_31 = get_racmo_time_series(melt_sel,
                                    var_name='snowmeltcorr',
                                    dim_one='lon',
                                    dim_two='lat',
                                    dim_three='time',
                                    time_start=time_start,
                                    time_end=time_end)

    fall_31 = get_racmo_time_series(fall_sel,
                                    var_name='snowfallcorr',
                                    dim_one='lon',
                                    dim_two='lat',
                                    dim_three='time',
                                    time_start=time_start,
                                    time_end=time_end)

    fpath = gdir.dir + '/racmo_data.nc'
    if os.path.exists(fpath):
        os.remove(fpath)

    if smb_31 is None:
        return print('There is no RACMO file for this glacier ' + gdir.rgi_id)
    else:
        with ncDataset(fpath, 'w', format='NETCDF4') as nc:

            nc.createDimension('time', None)

            nc.author = 'B.M Recinos'
            nc.author_info = 'Open Global Glacier Model'

            timev = nc.createVariable('time', 'i4', ('time', ))

            tatts = {'units': 'year'}

            calendar = 'standard'

            tatts['calendar'] = calendar

            timev.setncatts(tatts)
            timev[:] = smb_31.time

            v = nc.createVariable('smb', 'f4', ('time', ))
            v.units = 'mm w.e.'
            v.long_name = 'surface mass balance'
            v[:] = smb_31

            v = nc.createVariable('prcp', 'f4', ('time', ))
            v.units = 'mm w.e.'
            v.long_name = 'total yearly precipitation amount'
            v[:] = prcp_31

            v = nc.createVariable('run_off', 'f4', ('time', ))
            v.units = 'mm w.e.'
            v.long_name = 'total yearly run off amount'
            v[:] = run_off_31

            v = nc.createVariable('snow_melt', 'f4', ('time', ))
            v.units = 'mm w.e.'
            v.long_name = 'total yearly snowmelt amount'
            v[:] = melt_31

            v = nc.createVariable('snow_fall', 'f4', ('time', ))
            v.units = 'mm w.e.'
            v.long_name = 'total yearly snowfall amount'
            v[:] = fall_31