oas_dev/util/collocate/collocate.py
def collocate_dataset(var_name, ds, locations=constants.collocate_locations):
    """
    Collocate by method 'nearest' to locations
    :param var_name:
    :param ds:
    :param locations:
    :return:
    """
    # %%
    # maxDiameter = 39.6  # 23.6 #e-9
    # minDiameter = 5.0  # e-9
    # s = SizedistributionSurface('PD_SECT_CHC7_diur_ricc',  '2008-01-01',
    #                            '2009-01-01', [minDiameter, maxDiameter],
    #                            True, 'month')
    # ds = s.get_sizedist_var()
    # var_name = 'dNdlogD'
    da = ds[var_name]
    # da
    ds_tmp = xr.Dataset()
    # locations = constants.collocate_locations
    for loc in locations:
        lat = locations[loc]['lat']
        lon = locations[loc]['lon']
        ds_tmp[loc] = da.sel(lat=lat, lon=lon, method='nearest', drop=True)
        # print(lat, lon)
    da_out = ds_tmp.to_array(dim='location', name=var_name)
    for at in da.attrs:
        if at not in da_out.attrs:
            da_out.attrs[at] = da.attrs[at]
    del ds_tmp

    return da_out

    Collocate by method 'nearest' to locations
    :param var_name:
    :param ds:
    :param locations:
    :return:
    
Collocate by method 'nearest' to locations
Collocate by method ' nearest ' to locations
def collocate_dataset(var_name, ds, locations=constants.collocate_locations):
    da = ds[var_name]
    ds_tmp = xr.Dataset()
    for loc in locations:
        lat = locations[loc]['lat']
        lon = locations[loc]['lon']
        ds_tmp[loc] = da.sel(lat=lat, lon=lon, method='nearest', drop=True)
    da_out = ds_tmp.to_array(dim='location', name=var_name)
    for at in da.attrs:
        if at not in da_out.attrs:
            da_out.attrs[at] = da.attrs[at]
    del ds_tmp
    return da_out
def collocate_dataset ( var_name , ds , locations = constants . collocate_locations ) : da = ds [ var_name ] ds_tmp = xr . Dataset ( ) for loc in locations : lat = locations [ loc ] [ 'lat' ] lon = locations [ loc ] [ 'lon' ] ds_tmp [ loc ] = da . sel ( lat = lat , lon = lon , method = 'nearest' , drop = True ) da_out = ds_tmp . to_array ( dim = 'location' , name = var_name ) for at in da . attrs : if at not in da_out . attrs : da_out . attrs [ at ] = da . attrs [ at ] del ds_tmp return da_out
Collocate by method 'nearest' to locations
Collocate by method ' nearest ' to locations
"""
    Collocate by method 'nearest' to locations
    :param var_name:
    :param ds:
    :param locations:
    :return:
    """ # %% # maxDiameter = 39.6  # 23.6 #e-9 # minDiameter = 5.0  # e-9 # s = SizedistributionSurface('PD_SECT_CHC7_diur_ricc',  '2008-01-01', #                            '2009-01-01', [minDiameter, maxDiameter], #                            True, 'month') # ds = s.get_sizedist_var() # var_name = 'dNdlogD' # da # locations = constants.collocate_locations # print(lat, lon)
None
var_name
None
ds
None
locations
None