Beispiel #1
0
                hours, minutes = total_minutes / 60, total_minutes % 60
                if len(str(hours)) == 1:
                    hours = '0' + str(hours)
                if len(str(minutes)) == 1:
                    minutes = '0' + str(minutes)
                filename = pre_pattern + str(hours) + str(minutes) + '00-' + label_type + suffixe
                content = Dataset(str(os.path.join(dir_, filename)))
                if keep_holes:
                    to_return[real_slot] = \
                        content.variables[var_][lat_beginning_ind: lat_ending_ind, lon_beginning_ind:lon_ending_ind]
                else:
                    to_return.append(
                        content.variables[var_][lat_beginning_ind: lat_ending_ind, lon_beginning_ind:lon_ending_ind])
                selected_slots.append(real_slot)
            except Exception as e:
                # the data for this slot does not exist or has not been load
                print e
                pass
    print to_return[to_return != -10]
    return asarray(to_return), selected_slots


if __name__ == '__main__':
    seed = 1

    dfb_begin, dfb_end, latitude_begin, latitude_end, longitude_begin, longitude_end = typical_input(seed=seed)
    print dfb_begin, dfb_end
    print_date_from_dfb(dfb_begin, dfb_end)
    visualize_map_time(read_labels('CSP', latitude_begin, latitude_end, longitude_begin, longitude_end,
                                   dfb_begin, dfb_end)[0], typical_bbox(seed))
    bb = get_bbox(latitudes[0], latitudes[-1], longitudes[0], longitudes[-1])
    # visualize_map_time(snow, bb, vmin=0, vmax=1)
    dmask = dawn_day_test(get_zenith_angle(get_times_utc(begin, end, read_satellite_step(), 1), latitudes, longitudes))
    if method == 'tomas':
        cloud = (reduce_tomas_2_classes(get_tomas_outputs(
            begin, end, latitudes[0], latitudes[-1], longitudes[0], longitudes[-1]
        )) == 1)
        snow = snow[~cloud]
        # visualize_map_time(cloud, bb)
    elif method == 'ped':
        classes = reduce_classes(get_classes_v1_point(
            latitudes, longitudes, begin, end
        ))
        cloud = (reduce_two_classes(classes) == 1)
        # visualize_map_time(cloud, bb)
        del classes
        snow = snow[~cloud]
    snow = snow[dmask & (snow > -9)]
    visualize_hist(snow.flatten(), 'level of snow', precision=100)
    # visualize_hist(var.flatten(), 'level of snow', precision=100)


if __name__ == '__main__':
    slot_step = 1
    beginning, ending, latitude_beginning, latitude_end, longitude_beginning, longitude_end = typical_input()
    lat, lon = get_latitudes_longitudes(latitude_beginning, latitude_end,
                                        longitude_beginning, longitude_end)
    check_gaussian_hypothesis(lat, lon, beginning, ending, 'none')
    # check_gaussian_hypothesis(lat, lon, beginning, ending, 'tomas')
    check_gaussian_hypothesis(lat, lon, beginning, ending, 'ped')
Beispiel #3
0
def prepare_angles_features_ped_labels(seed, keep_holes=True):
    '''

    :param latitude_beginning:
    :param latitude_end:
    :param longitude_beginning:
    :param longitude_end:
    :param beginning:
    :param ending:
    :param output_level:
    :param seed:
    :param keep_holes:
    :return:
    '''
    beginning, ending, latitude_beginning, latitude_end, longitude_beginning, longitude_end = typical_input(
        seed)

    latitudes, longitudes = get_latitudes_longitudes(latitude_beginning,
                                                     latitude_end,
                                                     longitude_beginning,
                                                     longitude_end)
    if keep_holes:
        labels, selected_slots = read_labels_keep_holes(
            'csp', latitude_beginning, latitude_end, longitude_beginning,
            longitude_end, beginning, ending)
    else:
        labels, selected_slots = read_labels_remove_holes(
            'csp', latitude_beginning, latitude_end, longitude_beginning,
            longitude_end, beginning, ending)

    angles, vis, ndsi, mask = get_features('visible',
                                           latitudes,
                                           longitudes,
                                           beginning,
                                           ending,
                                           output_level='ndsi',
                                           slot_step=1,
                                           gray_scale=False)
    a, b, c = angles.shape
    nb_features_ = 8
    features = np.empty((a, b, c, nb_features_))

    test_angles = dawn_day_test(angles)
    land_mask = typical_land_mask(seed)
    ndsi[((test_angles | land_mask) | mask)] = -10
    features[:, :, :, 5] = test_angles
    features[:, :, :, 6] = land_mask
    features[:, :, :, 3] = vis
    features[:, :, :, 4] = ndsi
    del vis, ndsi

    cli_mu, cli_epsilon, mask_input_cli = get_features('infrared',
                                                       latitudes,
                                                       longitudes,
                                                       beginning,
                                                       ending,
                                                       output_level='cli',
                                                       slot_step=1,
                                                       gray_scale=False)
    mask = ((test_angles | land_mask) | mask)
    cli_mu[mask] = -10
    cli_epsilon[mask] = -10
    features[:, :, :, 0] = cli_mu
    features[:, :, :, 1] = cli_epsilon
    del mask, test_angles, land_mask, cli_mu, cli_epsilon

    features[:, :, :, 2] = get_features('infrared',
                                        latitudes,
                                        longitudes,
                                        beginning,
                                        ending,
                                        output_level='channel',
                                        slot_step=1,
                                        gray_scale=False)[:, :, :, 1]

    if selected_slots is not None:
        features[selected_slots, :, :, 7] = labels
        return angles[selected_slots], features[selected_slots], selected_slots
    else:
        features[:, :, :, 7] = labels
        return angles, features, selected_slots
Beispiel #4
0
def prepare_angles_features_bom_labels(seed, selected_slots):
    beginning, ending, latitude_beginning, latitude_end, longitude_beginning, longitude_end = typical_input(
        seed)
    times = get_times_utc(beginning,
                          ending,
                          read_satellite_step(),
                          slot_step=1)
    latitudes, longitudes = get_latitudes_longitudes(latitude_beginning,
                                                     latitude_end,
                                                     longitude_beginning,
                                                     longitude_end)
    a, b, c = len(times), len(latitudes), len(longitudes)
    nb_features_ = 8
    features = np.empty((a, b, c, nb_features_))
    angles, vis, ndsi, mask = get_features('visible',
                                           latitudes,
                                           longitudes,
                                           beginning,
                                           ending,
                                           output_level='ndsi',
                                           slot_step=1,
                                           gray_scale=False)
    test_angles = dawn_day_test(angles)
    land_mask = typical_land_mask(seed)
    mask = ((test_angles | land_mask) | mask)
    ndsi[mask] = -10
    features[:, :, :, 5] = test_angles
    features[:, :, :, 6] = land_mask
    del test_angles, land_mask, mask
    features[:, :, :, 3] = vis
    features[:, :, :, 4] = ndsi
    del vis, ndsi
    features[:, :, :, :3] = get_features('infrared',
                                         latitudes,
                                         longitudes,
                                         beginning,
                                         ending,
                                         output_level='abstract',
                                         slot_step=1,
                                         gray_scale=False)[:, :, :, :3]
    features[:, :, :, 7] = (typical_static_classifier(seed) >= 2)
    if selected_slots is not None:
        return angles[selected_slots], features[selected_slots], selected_slots
    return angles, features, selected_slots
Beispiel #5
0
def prepare_angles_features_classes_bom(seed=0, keep_holes=True):
    beginning, ending, latitude_beginning, latitude_end, longitude_beginning, longitude_end = typical_input(
        seed)

    if keep_holes:
        classes, selected_slots = read_labels_keep_holes(
            'csp', latitude_beginning, latitude_end, longitude_beginning,
            longitude_end, beginning, ending)
    else:
        classes, selected_slots = read_labels_remove_holes(
            'csp', latitude_beginning, latitude_end, longitude_beginning,
            longitude_end, beginning, ending)

    # the folowing function returns a tuple (angles, features, selected slots)
    angles, features, selected_slots = prepare_angles_features_bom_labels(
        seed, selected_slots)
    return angles, features, classes
Beispiel #6
0
def prepare_angles_features_classes_ped(seed=0,
                                        keep_holes=True,
                                        method_labels='static'):
    '''

    :param seed:
    :param keep_holes:
    :param method_labels: 'static' [recommended], 'on-point', 'otsu-2d', 'otsu-3d', 'watershed-2d', 'watershed-3d'
    :return:
    '''

    angles, features, selected_slots = prepare_angles_features_ped_labels(
        seed, keep_holes)
    if selected_slots is not None:
        print 'SELECTED SLOTS'
        dict = {}
        for k, slot in enumerate(selected_slots):
            dict[str(k)] = slot
        print dict
    beginning, ending, latitude_beginning, latitude_end, longitude_beginning, longitude_end = typical_input(
        seed)
    latitudes, longitudes = get_latitudes_longitudes(latitude_beginning,
                                                     latitude_end,
                                                     longitude_beginning,
                                                     longitude_end)
    print_date_from_dfb(beginning, ending)
    print beginning, ending
    print 'NS:', latitude_beginning, latitude_end, ' WE:', longitude_beginning, longitude_end
    from time import time
    t_begin = time()
    print method_labels
    assert method_labels in [
        'on-point', 'otsu-2d', 'otsu-3d', 'watershed-2d', 'watershed-3d',
        'static'
    ], 'unknown label method'
    if method_labels == 'static':
        classes = typical_static_classifier(seed)
    elif method_labels == 'on-point':
        # not really used anymore
        classes = get_classes_v1_point(latitudes, longitudes, beginning,
                                       ending, slot_step)
        classes = reduce_classes(classes)
    elif method_labels in [
            'otsu-2d', 'otsu-3d', 'watershed-2d', 'watershed-3d'
    ]:
        # not really used anymore
        classes = get_classes_v2_image(latitudes, longitudes, beginning,
                                       ending, slot_step, method_labels)
        classes = reduce_classes(classes)
    t_classes = time()
    print 'time classes:', t_classes - t_begin

    if selected_slots is not None:
        restricted_classes_in_time = classes[selected_slots, :, :]
        print 'SELECTED SLOTS'
        dict = {}
        for k, slot in enumerate(selected_slots):
            dict[str(k)] = slot
        print dict
        return angles, features, restricted_classes_in_time

    return angles, features, classes
Beispiel #7
0
                                        gray_scale=False)[:, :, :, 1]

    if selected_slots is not None:
        features[selected_slots, :, :, 7] = labels
        return angles[selected_slots], features[selected_slots], selected_slots
    else:
        features[:, :, :, 7] = labels
        return angles, features, selected_slots


if __name__ == '__main__':
    slot_step = 1
    coef_randomization = 4
    path_ = read_satellite_model_path()

    beginning_testing, ending_testing, lat_beginning_testing, lat_ending_testing, lon_beginning_testing, lon_ending_testing = typical_input(
        seed=0)

    testing_angles, testing_inputs, testing_classes = prepare_angles_features_classes_ped(
        seed=0, keep_holes=True)

    inputs, labs = restrict_pools(testing_angles, testing_inputs,
                                  testing_classes)
    sl, la, lo, fe = testing_inputs.shape
    inputs = inputs.reshape(((1. * len(inputs)) / la / lo, la, lo, fe))
    # print (inputs[:, 15, 15, 4]>0).mean()
    # print (testing_inputs[:, 15, 15, 4]>0).mean()
    print(inputs[:, 15, 15, 3] > -10).mean()
    print(testing_inputs[:, 15, 15, 3] > -10).mean()
    visualize_map_time(inputs, typical_bbox())

    learn_new_model = True