Exemplo n.º 1
0
def create_color_map(scene_path=''):
    '''
    Uses the rgb bands to reconstruct a 'true color' satellite image
    :param scene_path:
    :return:
    '''
    scene_data, image_shape, valid = get_feature_array_L57(scene_path)

    color_img = np.zeros((image_shape[0], image_shape[1], 3))
    color_img[:, :, 0] = scene_data[:, 0].reshape(image_shape)  # blue - band 1
    color_img[:, :, 1] = scene_data[:, 1].reshape(image_shape)  # green - band 2
    color_img[:, :, 2] = scene_data[:, 2].reshape(image_shape)  # red - band 3

    # scale values
    color_img = color_img * 255. / 4000.

    all_imgs = lgd.get_scene_imgs(scene_path)
    scene_name = lgd.get_scene_name(all_imgs[0])
    cv2.imwrite('../figures/color_map_{}.jpg'.format(scene_name), color_img)
Exemplo n.º 2
0
def create_spm_map(theta=None, scene_path='', log_spm_flag=False, color_flag=True):
    # TODO add actual spm values to legend
    '''
    For info on sr_cloud_qa and sr_land_water_qa image values
    http://landsat.usgs.gov/landsat_climate_data_records_quality_calibration.php
    cloud: 255 = cloud, water: 255 = water

    :param theta: theta for the linear model
    :param scene_path: full path to the scene folder
    :param log_spm_flag: flag for whether to map spm or log(spm), true means log(spm)
    :return:
    '''
    if (theta is None):
        theta = create_model()
    else:
        print('Using given theta. Creating predicted SPM map')

    scene_data, image_shape, valid = get_feature_array_L57(scene_path)

    predicted_spm_log = np.dot(scene_data, theta)
    predicted_spm = np.exp(predicted_spm_log)

    # map spm map to -1 to 1 range
    if (log_spm_flag):
        spm_map = predicted_spm_log.reshape(image_shape)

        # high log(spm) values are around 4 so map (-1)-4 to -1-1
        spm_map = np.interp(spm_map, (-1, 4), (-1, 1))
    else:
        spm_map = predicted_spm.reshape(image_shape)

        # high spm values are around 50
        # map 0-50 to -1 to 1
        spm_map = np.interp(spm_map, (0, 50), (-1, 1))

    print('Done creating predicted SPM map')

    # map spm to jet color scale, exclude the alpha channel
    spm_map = plt.cm.jet(spm_map)[:, :, 0:3]

    # color code the map: make land black, make cloud white
    spm_map = color_map_by_land_water(spm_map, scene_path)

    print 'Done color coding map'

    # create figure
    dpi = 400
    plt.figure(dpi=dpi)
    plt.imshow(spm_map, interpolation='nearest')
    c = plt.colorbar(ticks=[0, 1.0])

    # add labels depending on log or not
    if (log_spm_flag):
        c.set_ticklabels(['ln(SPM) < -1', 'ln(SPM) > 4'])
    else:
        c.set_ticklabels(['SPM < 0', 'SPM > 50'])

    # figure out the name
    all_imgs = lgd.get_scene_imgs(scene_path)
    scene_name = lgd.get_scene_name(all_imgs[0])
    log_str = ('log_' if log_spm_flag else '')
    folder = log_str + 'colormap_spm'

    datetime = lgd.get_datetime_from_metadata(lgd.get_metadata_path(scene_path))

    # Add title
    plt.title('Map of SPM in SF Bay: ' + str(scene_name) + '\n' + str(datetime) + ' GMT')

    # save figure
    plt.savefig('../figures/{}/{}{}.jpg'.format(folder, log_str, scene_name), dpi=dpi)
    print 'Done saving map\n'