예제 #1
0
def get_cloud_short_variability(cloud_index, valid_measurements_mask):
    """
    Wrapper returning cloud variability index computed between cloud index maps at step t and step t+1

    :param cloud_index: array (slots, latitudes, longitudes) with cloud index (cli or unbiased difference)
    :param valid_measurements_mask: boolean array (slots, latitudes, longitudes) indicating which measurements are valid
    :return: array (slots, latitudes, longitudes) with cloud variability index between consecutive cloud index maps
    """
    return compute_variability(cloud_index=cloud_index,
                               mask=valid_measurements_mask,
                               step=1)
예제 #2
0
def suspect_snow_classified_pixels(snow, ndsi, mask_input):
    '''
    the "suspect snow" test flagged as cloud the pixels which were supposed to be snowy
     - because they pass the adequate test - but whose ndsi is strangely high
    :param snow:
    :param ndsi:
    :param mask_input:
    :return: boolean matrix (time, latitude, longitude) which is True if the pixel is snowy
    '''
    return snow & ((get_bright_positive_variability_5d(ndsi, mask_input, typical_time_step(), 1) > 0.2) |
                   (get_bright_negative_variability_5d(ndsi, mask_input, typical_time_step(), 1) > 0.2) |
                   (compute_variability(ndsi, mask=mask_input, abs_value=True) > 0.05))
예제 #3
0
def get_bright_positive_variability_5d(index, definition_mask, satellite_step,
                                       slot_step):
    '''
    To recognize some icy clouds (peaks of ndsi)
    NB: we loose information about the first slot (resp the last slot) if night is 1 slot longer during 1 of the 5 days
    :param index:
    :param definition_mask:
    :param satellite_step: the satellite characteristic time step between two slots (10 minutes for Himawari 8)
    :param slot_step: the chosen sampling of slots. if slot_step = n, the sampled slots are s[0], s[n], s[2*n]...
    :return:
    '''
    nb_slots_per_day = get_nb_slots_per_day(satellite_step, slot_step)
    nb_days = np.shape(index)[0] / nb_slots_per_day
    to_return = np.full_like(index, -10)
    if nb_days >= 2:
        var_ndsi_1d_past = compute_variability(cloud_index=index,
                                               mask=definition_mask,
                                               step=nb_slots_per_day,
                                               negative_variation_only=False,
                                               abs_value=False)

        var_ndsi_1d_future = compute_variability(cloud_index=index,
                                                 mask=definition_mask,
                                                 step=-nb_slots_per_day,
                                                 negative_variation_only=False,
                                                 abs_value=False)
        if nb_days == 2:
            to_return[:nb_slots_per_day] = var_ndsi_1d_future[:
                                                              nb_slots_per_day]
            to_return[nb_slots_per_day:] = var_ndsi_1d_past[nb_slots_per_day:]
        else:  # nb_days >=3
            var_ndsi_2d_past = compute_variability(
                cloud_index=index,
                mask=definition_mask,
                step=nb_slots_per_day * 2,
                negative_variation_only=False,
                abs_value=False)
            var_ndsi_2d_future = compute_variability(
                cloud_index=index,
                mask=definition_mask,
                step=-2 * nb_slots_per_day,
                negative_variation_only=False,
                abs_value=False)
            # first day
            to_return[:nb_slots_per_day] = np.minimum(
                var_ndsi_1d_future[:nb_slots_per_day],
                var_ndsi_2d_future[:nb_slots_per_day])
            # last day
            to_return[-nb_slots_per_day:] = np.minimum(
                var_ndsi_1d_past[-nb_slots_per_day:],
                var_ndsi_2d_past[-nb_slots_per_day:])

            if nb_days == 3:
                # second day
                to_return[nb_slots_per_day:2 * nb_slots_per_day] = np.minimum(
                    var_ndsi_1d_past[nb_slots_per_day:2 * nb_slots_per_day],
                    var_ndsi_1d_future[nb_slots_per_day:2 * nb_slots_per_day])
            else:  # nb_days >= 4
                # the day previous the last one
                to_return[-2 * nb_slots_per_day:-nb_slots_per_day] = np.minimum(
                    np.minimum(
                        var_ndsi_1d_past[-2 *
                                         nb_slots_per_day:-nb_slots_per_day],
                        var_ndsi_2d_past[-2 *
                                         nb_slots_per_day:-nb_slots_per_day]),
                    var_ndsi_1d_future[-2 *
                                       nb_slots_per_day:-nb_slots_per_day])
                # second day
                to_return[nb_slots_per_day:2 * nb_slots_per_day] = np.minimum(
                    np.minimum(
                        var_ndsi_1d_future[nb_slots_per_day:2 *
                                           nb_slots_per_day],
                        var_ndsi_2d_future[nb_slots_per_day:2 *
                                           nb_slots_per_day]),
                    var_ndsi_1d_past[nb_slots_per_day:2 * nb_slots_per_day])
                if nb_days >= 5:
                    to_return[2 * nb_slots_per_day:-2 *
                              nb_slots_per_day] = np.minimum(
                                  np.minimum(
                                      var_ndsi_1d_past[2 *
                                                       nb_slots_per_day:-2 *
                                                       nb_slots_per_day],
                                      var_ndsi_2d_past[2 *
                                                       nb_slots_per_day:-2 *
                                                       nb_slots_per_day]),
                                  np.minimum(
                                      var_ndsi_1d_future[2 *
                                                         nb_slots_per_day:-2 *
                                                         nb_slots_per_day],
                                      var_ndsi_2d_future[2 *
                                                         nb_slots_per_day:-2 *
                                                         nb_slots_per_day]))
    to_return[to_return < 0] = 0
    return to_return
예제 #4
0
def get_cloud_index_total_variability_7d(cloud_index, definition_mask,
                                         pre_cloud_mask, satellite_step,
                                         slot_step):
    '''

    :param cloud_index: array (slots, latitudes, longitudes) with cloud index (cli or unbiased difference)
    :param definition_mask: mask points where cloud index is not defined
    :param pre_cloud_mask: mask points where we don't want to compute 5 days variability (eg: obvious water clouds)
    :param satellite_step: the satellite characteristic time step between two slots (10 minutes for Himawari 8)
    :param slot_step: the chosen sampling of slots. if slot_step = n, the sampled slots are s[0], s[n], s[2*n]...
    :return:
    '''

    if pre_cloud_mask is not None:
        mask = definition_mask | pre_cloud_mask
    else:
        mask = definition_mask
    nb_slots_per_day = get_nb_slots_per_day(satellite_step, slot_step)
    nb_days = np.shape(cloud_index)[0] / nb_slots_per_day
    to_return = np.full_like(cloud_index, -10)
    if nb_days >= 2:
        var_cli_1d_past = compute_variability(cloud_index=cloud_index,
                                              mask=mask,
                                              abs_value=True,
                                              step=nb_slots_per_day)

        var_cli_1d_future = compute_variability(cloud_index=cloud_index,
                                                mask=mask,
                                                abs_value=True,
                                                step=-nb_slots_per_day)
        if nb_days == 2:
            to_return[:nb_slots_per_day] = var_cli_1d_future[:nb_slots_per_day]
            to_return[nb_slots_per_day:] = var_cli_1d_past[nb_slots_per_day:]
        else:  # nb_days >=3
            var_cli_2d_past = compute_variability(cloud_index=cloud_index,
                                                  mask=mask,
                                                  abs_value=True,
                                                  step=nb_slots_per_day * 2)
            var_cli_2d_future = compute_variability(cloud_index=cloud_index,
                                                    mask=mask,
                                                    abs_value=True,
                                                    step=-2 * nb_slots_per_day)

            # first day
            to_return[:nb_slots_per_day] = np.minimum(
                var_cli_1d_future[:nb_slots_per_day],
                var_cli_2d_future[:nb_slots_per_day])
            # last day
            to_return[-nb_slots_per_day:] = np.minimum(
                var_cli_1d_past[-nb_slots_per_day:],
                var_cli_2d_past[-nb_slots_per_day:])

            if nb_days == 3:
                # second day
                to_return[nb_slots_per_day:2 * nb_slots_per_day] = np.minimum(
                    var_cli_1d_past[nb_slots_per_day:2 * nb_slots_per_day],
                    var_cli_1d_future[nb_slots_per_day:2 * nb_slots_per_day])
            else:  # nb_days >= 4
                # the day previous the last one
                to_return[-2 * nb_slots_per_day:-nb_slots_per_day] = np.minimum(
                    np.minimum(
                        var_cli_1d_past[-2 *
                                        nb_slots_per_day:-nb_slots_per_day],
                        var_cli_2d_past[-2 *
                                        nb_slots_per_day:-nb_slots_per_day]),
                    var_cli_1d_future[-2 * nb_slots_per_day:-nb_slots_per_day])
                # second day
                to_return[nb_slots_per_day:2 * nb_slots_per_day] = np.minimum(
                    np.minimum(
                        var_cli_1d_future[nb_slots_per_day:2 *
                                          nb_slots_per_day],
                        var_cli_2d_future[nb_slots_per_day:2 *
                                          nb_slots_per_day]),
                    var_cli_1d_past[nb_slots_per_day:2 * nb_slots_per_day])
                if nb_days == 5:
                    to_return[2 * nb_slots_per_day:-2 *
                              nb_slots_per_day] = np.minimum(
                                  np.minimum(
                                      var_cli_1d_past[2 * nb_slots_per_day:-2 *
                                                      nb_slots_per_day],
                                      var_cli_2d_past[2 * nb_slots_per_day:-2 *
                                                      nb_slots_per_day]),
                                  np.minimum(
                                      var_cli_1d_future[2 *
                                                        nb_slots_per_day:-2 *
                                                        nb_slots_per_day],
                                      var_cli_2d_future[2 *
                                                        nb_slots_per_day:-2 *
                                                        nb_slots_per_day]))
                else:  # nb_days >= 6
                    var_cli_3d_past = compute_variability(
                        cloud_index=cloud_index,
                        mask=mask,
                        abs_value=True,
                        step=nb_slots_per_day * 3)

                    var_cli_3d_future = compute_variability(
                        cloud_index=cloud_index,
                        mask=mask,
                        abs_value=True,
                        step=-nb_slots_per_day * 3)
                    # two days previous the last one
                    to_return[-3 * nb_slots_per_day:-2 *
                              nb_slots_per_day] = np.minimum(
                                  np.minimum(
                                      np.minimum(
                                          var_cli_1d_past[-3 *
                                                          nb_slots_per_day:-2 *
                                                          nb_slots_per_day],
                                          var_cli_2d_past[-3 *
                                                          nb_slots_per_day:-2 *
                                                          nb_slots_per_day]),
                                      var_cli_3d_past[-3 *
                                                      nb_slots_per_day:-2 *
                                                      nb_slots_per_day]),
                                  np.minimum(
                                      var_cli_1d_future[-3 *
                                                        nb_slots_per_day:-2 *
                                                        nb_slots_per_day],
                                      var_cli_2d_future[-3 *
                                                        nb_slots_per_day:-2 *
                                                        nb_slots_per_day]))
                    # third day
                    to_return[
                        2 * nb_slots_per_day:3 *
                        nb_slots_per_day] = np.minimum(
                            np.minimum(
                                np.minimum(
                                    var_cli_1d_future[2 * nb_slots_per_day:3 *
                                                      nb_slots_per_day],
                                    var_cli_2d_future[2 * nb_slots_per_day:3 *
                                                      nb_slots_per_day]),
                                var_cli_3d_future[2 * nb_slots_per_day:3 *
                                                  nb_slots_per_day]),
                            np.minimum(
                                var_cli_1d_past[2 * nb_slots_per_day:3 *
                                                nb_slots_per_day],
                                var_cli_2d_past[2 * nb_slots_per_day:3 *
                                                nb_slots_per_day]))
                    if nb_days >= 7:
                        to_return[
                            3 * nb_slots_per_day:-3 *
                            nb_slots_per_day] = np.minimum(
                                np.minimum(
                                    np.minimum(
                                        var_cli_1d_past[3 *
                                                        nb_slots_per_day:-3 *
                                                        nb_slots_per_day],
                                        var_cli_2d_past[3 *
                                                        nb_slots_per_day:-3 *
                                                        nb_slots_per_day]),
                                    var_cli_3d_past[3 * nb_slots_per_day:-3 *
                                                    nb_slots_per_day]),
                                np.minimum(
                                    np.minimum(
                                        var_cli_1d_future[3 *
                                                          nb_slots_per_day:-3 *
                                                          nb_slots_per_day],
                                        var_cli_2d_future[3 *
                                                          nb_slots_per_day:-3 *
                                                          nb_slots_per_day]),
                                    var_cli_3d_future[3 * nb_slots_per_day:-3 *
                                                      nb_slots_per_day]))

    return to_return
예제 #5
0
def get_cloud_index_positive_variability_7d(cloud_index,
                                            definition_mask,
                                            satellite_step,
                                            pre_cloud_mask=None,
                                            slot_step=1,
                                            only_past=False):
    '''
    This function is supposed to help finding small clouds with low positive clouds (in partiular NOT icy clouds)

    :param only_past: MODE of the function. If True, compare one day with the previous days only.
     If False, compare one day both with the previous and the following days.
    :param cloud_index: array (slots, latitudes, longitudes) with cloud index (cli or unbiased difference)
    :param definition_mask: mask points where cloud index is not defined
    :param pre_cloud_mask: mask points where we don't want to compute 5 days variability (eg: obvious water clouds)
    :param satellite_step: the satellite characteristic time step between two slots (10 minutes for Himawari 8)
    :param slot_step: the chosen sampling of slots. if slot_step = n, the sampled slots are s[0], s[n], s[2*n]...
    :return:
    '''
    if pre_cloud_mask is not None:
        mask = definition_mask | pre_cloud_mask
    else:
        mask = definition_mask
    slots_per_day = get_nb_slots_per_day(satellite_step, slot_step)
    nb_days = np.shape(cloud_index)[0] / slots_per_day
    to_return = np.zeros_like(cloud_index)
    if only_past:
        if nb_days >= 2:
            var_cli_1d_past = compute_variability(cloud_index=cloud_index,
                                                  mask=mask,
                                                  step=slots_per_day)
            to_return[slots_per_day:] = var_cli_1d_past[slots_per_day:]

            if nb_days >= 3:
                var_cli_2d_past = compute_variability(cloud_index=cloud_index,
                                                      mask=mask,
                                                      step=slots_per_day * 2)
                # second day
                to_return[slots_per_day:2 * slots_per_day] = np.maximum(
                    var_cli_1d_past[slots_per_day:2 * slots_per_day],
                    var_cli_2d_past[-slots_per_day:2 * slots_per_day])

                if nb_days == 3:
                    # second day
                    to_return[slots_per_day:2 * slots_per_day] = np.maximum(
                        var_cli_1d_past[slots_per_day:2 * slots_per_day],
                        var_cli_1d_future[slots_per_day:2 * slots_per_day])
                else:  # nb_days >= 4
                    # the day previous the last one
                    to_return[-2 * slots_per_day:-slots_per_day] = np.maximum(
                        np.maximum(
                            var_cli_1d_past[-2 * slots_per_day:-slots_per_day],
                            var_cli_2d_past[-2 *
                                            slots_per_day:-slots_per_day]),
                        var_cli_1d_future[-2 * slots_per_day:-slots_per_day])
                    # second day
                    to_return[slots_per_day:2 * slots_per_day] = np.maximum(
                        np.maximum(
                            var_cli_1d_future[slots_per_day:2 * slots_per_day],
                            var_cli_2d_future[slots_per_day:2 *
                                              slots_per_day]),
                        var_cli_1d_past[slots_per_day:2 * slots_per_day])
                    if nb_days >= 5:
                        to_return[2 * slots_per_day:-2 *
                                  slots_per_day] = np.maximum(
                                      np.maximum(
                                          var_cli_1d_past[2 *
                                                          slots_per_day:-2 *
                                                          slots_per_day],
                                          var_cli_2d_past[2 *
                                                          slots_per_day:-2 *
                                                          slots_per_day]),
                                      np.maximum(
                                          var_cli_1d_future[2 *
                                                            slots_per_day:-2 *
                                                            slots_per_day],
                                          var_cli_2d_future[2 *
                                                            slots_per_day:-2 *
                                                            slots_per_day]))
                    else:  # nb_days >= 6
                        var_cli_3d_past = compute_variability(
                            cloud_index=cloud_index,
                            mask=mask,
                            step=slots_per_day * 3)

                        var_cli_3d_future = compute_variability(
                            cloud_index=cloud_index,
                            mask=mask,
                            step=-slots_per_day * 3)
                        # two days previous the last one
                        to_return[
                            -3 * slots_per_day:-2 *
                            slots_per_day] = np.maximum(
                                np.maximum(
                                    np.maximum(
                                        var_cli_1d_past[-3 * slots_per_day:-2 *
                                                        slots_per_day],
                                        var_cli_2d_past[-3 * slots_per_day:-2 *
                                                        slots_per_day]),
                                    var_cli_3d_past[-3 * slots_per_day:-2 *
                                                    slots_per_day]),
                                np.maximum(
                                    var_cli_1d_future[-3 * slots_per_day:-2 *
                                                      slots_per_day],
                                    var_cli_2d_future[-3 * slots_per_day:-2 *
                                                      slots_per_day]))
                        # third day
                        to_return[
                            2 * slots_per_day:3 * slots_per_day] = np.maximum(
                                np.maximum(
                                    np.maximum(
                                        var_cli_1d_future[2 * slots_per_day:3 *
                                                          slots_per_day],
                                        var_cli_2d_future[2 * slots_per_day:3 *
                                                          slots_per_day]),
                                    var_cli_3d_future[2 * slots_per_day:3 *
                                                      slots_per_day]),
                                np.maximum(
                                    var_cli_1d_past[2 * slots_per_day:3 *
                                                    slots_per_day],
                                    var_cli_2d_past[2 * slots_per_day:3 *
                                                    slots_per_day]))
                        if nb_days >= 7:
                            to_return[
                                3 * slots_per_day:-3 *
                                slots_per_day] = np.maximum(
                                    np.maximum(
                                        np.maximum(
                                            var_cli_1d_past[3 *
                                                            slots_per_day:-3 *
                                                            slots_per_day],
                                            var_cli_2d_past[3 *
                                                            slots_per_day:-3 *
                                                            slots_per_day]),
                                        var_cli_3d_past[3 * slots_per_day:-3 *
                                                        slots_per_day]),
                                    np.maximum(
                                        np.maximum(
                                            var_cli_1d_future[
                                                3 * slots_per_day:-3 *
                                                slots_per_day],
                                            var_cli_2d_future[
                                                3 * slots_per_day:-3 *
                                                slots_per_day]),
                                        var_cli_3d_future[3 *
                                                          slots_per_day:-3 *
                                                          slots_per_day]))
    else:
        if nb_days >= 2:
            var_cli_1d_past = compute_variability(cloud_index=cloud_index,
                                                  mask=mask,
                                                  step=slots_per_day)

            var_cli_1d_future = compute_variability(cloud_index=cloud_index,
                                                    mask=mask,
                                                    step=-slots_per_day)
            if nb_days == 2:
                to_return[:slots_per_day] = var_cli_1d_future[:slots_per_day]
                to_return[slots_per_day:] = var_cli_1d_past[slots_per_day:]
            else:  # nb_days >=3
                var_cli_2d_past = compute_variability(cloud_index=cloud_index,
                                                      mask=mask,
                                                      step=slots_per_day * 2)
                var_cli_2d_future = compute_variability(
                    cloud_index=cloud_index,
                    mask=mask,
                    step=-2 * slots_per_day)

                # first day
                to_return[:slots_per_day] = np.maximum(
                    var_cli_1d_future[:slots_per_day],
                    var_cli_2d_future[:slots_per_day])
                # last day
                to_return[-slots_per_day:] = np.maximum(
                    var_cli_1d_past[-slots_per_day:],
                    var_cli_2d_past[-slots_per_day:])

                if nb_days == 3:
                    # second day
                    to_return[slots_per_day:2 * slots_per_day] = np.maximum(
                        var_cli_1d_past[slots_per_day:2 * slots_per_day],
                        var_cli_1d_future[slots_per_day:2 * slots_per_day])
                else:  # nb_days >= 4
                    # the day previous the last one
                    to_return[-2 * slots_per_day:-slots_per_day] = np.maximum(
                        np.maximum(
                            var_cli_1d_past[-2 * slots_per_day:-slots_per_day],
                            var_cli_2d_past[-2 *
                                            slots_per_day:-slots_per_day]),
                        var_cli_1d_future[-2 * slots_per_day:-slots_per_day])
                    # second day
                    to_return[slots_per_day:2 * slots_per_day] = np.maximum(
                        np.maximum(
                            var_cli_1d_future[slots_per_day:2 * slots_per_day],
                            var_cli_2d_future[slots_per_day:2 *
                                              slots_per_day]),
                        var_cli_1d_past[slots_per_day:2 * slots_per_day])
                    if nb_days >= 5:
                        to_return[2 * slots_per_day:-2 *
                                  slots_per_day] = np.maximum(
                                      np.maximum(
                                          var_cli_1d_past[2 *
                                                          slots_per_day:-2 *
                                                          slots_per_day],
                                          var_cli_2d_past[2 *
                                                          slots_per_day:-2 *
                                                          slots_per_day]),
                                      np.maximum(
                                          var_cli_1d_future[2 *
                                                            slots_per_day:-2 *
                                                            slots_per_day],
                                          var_cli_2d_future[2 *
                                                            slots_per_day:-2 *
                                                            slots_per_day]))
                    else:  # nb_days >= 6
                        var_cli_3d_past = compute_variability(
                            cloud_index=cloud_index,
                            mask=mask,
                            step=slots_per_day * 3)

                        var_cli_3d_future = compute_variability(
                            cloud_index=cloud_index,
                            mask=mask,
                            step=-slots_per_day * 3)
                        # two days previous the last one
                        to_return[
                            -3 * slots_per_day:-2 *
                            slots_per_day] = np.maximum(
                                np.maximum(
                                    np.maximum(
                                        var_cli_1d_past[-3 * slots_per_day:-2 *
                                                        slots_per_day],
                                        var_cli_2d_past[-3 * slots_per_day:-2 *
                                                        slots_per_day]),
                                    var_cli_3d_past[-3 * slots_per_day:-2 *
                                                    slots_per_day]),
                                np.maximum(
                                    var_cli_1d_future[-3 * slots_per_day:-2 *
                                                      slots_per_day],
                                    var_cli_2d_future[-3 * slots_per_day:-2 *
                                                      slots_per_day]))
                        # third day
                        to_return[
                            2 * slots_per_day:3 * slots_per_day] = np.maximum(
                                np.maximum(
                                    np.maximum(
                                        var_cli_1d_future[2 * slots_per_day:3 *
                                                          slots_per_day],
                                        var_cli_2d_future[2 * slots_per_day:3 *
                                                          slots_per_day]),
                                    var_cli_3d_future[2 * slots_per_day:3 *
                                                      slots_per_day]),
                                np.maximum(
                                    var_cli_1d_past[2 * slots_per_day:3 *
                                                    slots_per_day],
                                    var_cli_2d_past[2 * slots_per_day:3 *
                                                    slots_per_day]))
                        if nb_days >= 7:
                            to_return[
                                3 * slots_per_day:-3 *
                                slots_per_day] = np.maximum(
                                    np.maximum(
                                        np.maximum(
                                            var_cli_1d_past[3 *
                                                            slots_per_day:-3 *
                                                            slots_per_day],
                                            var_cli_2d_past[3 *
                                                            slots_per_day:-3 *
                                                            slots_per_day]),
                                        var_cli_3d_past[3 * slots_per_day:-3 *
                                                        slots_per_day]),
                                    np.maximum(
                                        np.maximum(
                                            var_cli_1d_future[
                                                3 * slots_per_day:-3 *
                                                slots_per_day],
                                            var_cli_2d_future[
                                                3 * slots_per_day:-3 *
                                                slots_per_day]),
                                        var_cli_3d_future[3 *
                                                          slots_per_day:-3 *
                                                          slots_per_day]))
    # we are interested only in positive cli variations
    to_return[to_return < 0] = 0
    return to_return