# Create new folder for resampled rasters, if it doesn't exist already
    folder_gfc_zone = '{}proc/{}/'.format(folder_gfc, zone)
    if not os.path.exists(folder_gfc_zone):
        os.makedirs(folder_gfc_zone)

    # Loop through the six (6) products available, resampling & reprojecting to match the PADDED SRTM raster
    print(' - Resampling all products:', end=' ')
    for dataset in datasets:

        # Find the raster file corresponding to that dataset
        gfc_tile_path = '{}raw/Hansen_GFC-2018-v1.6_{}_{}.tif'.format(
            folder_gfc, dataset, dtm_dict[zone]['loc_string'])

        # Open the GFC raster file for that dataset and extract its coordinate reference system (CRS)
        gfc_proj = get_geotiff_projection(gfc_tile_path)

        # Warp the GFC raster to align with PADDED SRTM (using WGS84 coordinate reference system and appropriate interpolation)
        gfc_resample_path = '{}proc/{}/GFC_{}_{}_Pad44.tif'.format(
            folder_gfc, zone, dataset, zone)
        gfc_resample_method = dataset_dict[dataset]['resample_method']
        gfc_resample_type = dataset_dict[dataset]['resample_type']
        warp_command = [
            gdal_warp, '-overwrite', gfc_tile_path, gfc_resample_path, '-ot',
            gfc_resample_type, '-s_srs', gfc_proj, '-t_srs', 'EPSG:4326',
            '-tr',
            str(srtm_res_x),
            str(-srtm_res_y), '-te',
            str(pad_x_min),
            str(pad_y_min),
            str(pad_x_max),
    # Create zone folder, if it doesn't already exist
    if not os.path.exists('{}proc/{}/'.format(folder_merit, zone)):
        os.mkdir('{}proc/{}/'.format(folder_merit, zone))

    # Read the appropriate SRTM DSM raster into memory & retrieve its properties
    print(' - Analysing zonal SRTM raster to align grids...')
    srtm_filename = '{}proc/{}/SRTM_{}_Z.tif'.format(folder_srtm, zone, zone)
    srtm_proj, srtm_res_x, srtm_res_y, srtm_x_min, srtm_x_max, srtm_y_min, srtm_y_max, srtm_width, srtm_height = extract_projection_info(
        srtm_filename)

    # Resample & clip MERIT DEM so that it matches up with that zone's SRTM grid
    print(' - Warping MERIT DEM')

    # Open the full MERIT DEM raster & extract its coordinate reference system (CRS)
    src_filename = '{}raw/dem_tif_s60e150/s45e170_dem.tif'.format(folder_merit)
    src_proj = get_geotiff_projection(src_filename)

    # Warp the MERIT DEM, padding extra data along each edge, by the number of pixels defined in the "pad" variable
    pad_x_min = srtm_x_min - pad * srtm_res_x
    pad_x_max = srtm_x_max + pad * srtm_res_x
    pad_y_min = srtm_y_min - pad * -srtm_res_y
    pad_y_max = srtm_y_max + pad * -srtm_res_y
    dst_filename_pad = '{}proc/{}/MERIT_{}_Pad44.tif'.format(
        folder_merit, zone, zone)
    warp_command_pad = [
        gdal_warp, '-overwrite', '-ot', 'Float32', src_filename,
        dst_filename_pad, '-s_srs', src_proj, '-t_srs', srtm_proj, '-tr',
        str(srtm_res_x),
        str(-srtm_res_y), '-te',
        str(pad_x_min),
        str(pad_y_min),
Beispiel #3
0
    print(' - Processing NTL datasets available...', end=' ')

    # 2b. Resample VIIRS NTL data, testing a variety of different upsampling approaches

    # Create new folder for resampled rasters, if it doesn't exist already
    folder_viirs_zone = '{}/VIIRS/proc/{}/'.format(folder_ntl, zone)
    if not os.path.exists(folder_viirs_zone):
        os.makedirs(folder_viirs_zone)

    # Define path to selected VIIRS raster
    viirs_path = '{}VIIRS/raw/SVDNB_npp_20180801-20180831_00N060E_vcmcfg_v10_c201809070900.avg_rade9h.tif'.format(
        folder_ntl)

    # Open the VIIRS raster file and extract its coordinate reference system (CRS)
    viirs_proj = get_geotiff_projection(viirs_path)

    # Loop through all resampling options considered, generating an upsampled raster for that VIIRS layer with each
    for resampling in resampling_options:

        # Upsample 500m VIIRS NTL raster to 30m grid matching PADDED SRTM raster (using the selected resampling method)
        viirs_upsample = '{}VIIRS/proc/{}/NTL_VIIRS_{}_{}_Pad44.tif'.format(
            folder_ntl, zone, zone, resampling)
        warp_command = [
            gdal_warp, '-overwrite', viirs_path, viirs_upsample, '-ot',
            'Float32', '-s_srs', viirs_proj, '-t_srs', 'EPSG:4326', '-tr',
            str(srtm_res_x),
            str(-srtm_res_y), '-te',
            str(pad_x_min),
            str(pad_y_min),
            str(pad_x_max),
]  # Low quality filter: also allow medium/high cloud confidence codes (without saturation or shadows)

# Loop through each of the DTM survey zones
for zone in zones:

    print('\nProcessing Landsat 7 imagery for {}...'.format(
        dtm_dict[zone]['label']))

    # Create necessary result folder if it doesn't yet exist
    folder_original_zone = '{}proc/cloudfree/Original/{}/'.format(
        folder_ls7, zone)
    if not os.path.exists(folder_original_zone): os.mkdir(folder_original_zone)

    # Define path to the padded GeoTIFF describing that zone's SRTM coverage
    srtm_tif = '{}proc/{}/SRTM_{}_Z_Pad44.tif'.format(folder_srtm, zone, zone)
    srtm_proj = get_geotiff_projection(srtm_tif)

    # Define which Ls7 WRS path-rows are relevant for that zone
    zone_wrs_prs = dtm_dict[zone]['wrs_prs']

    # Loop through the list of possible query windows
    for query_window in query_windows:

        print(' - Using a {} day search window'.format(query_window))

        # Define the period over which S2 data should be sought (centred on each survey's collection period)
        query_window = datetime.timedelta(days=query_window)

        # Determine search window for tiles, by buffering the start & end dates retrieved above
        query_start = survey_start - (query_window - survey_window) / 2
        query_end = survey_end + (query_window - survey_window) / 2
    pad_y_max = srtm_y_max + pad * -srtm_res_y
    pad_width = srtm_width + 2 * pad
    pad_height = srtm_height + 2 * pad

    # Resample GCH canopy height data (using cubic splines for resampling)

    # Create new folder for resampled rasters, if it doesn't exist already
    folder_gch_zone = '{}proc/{}/'.format(folder_gch, zone)
    if not os.path.exists(folder_gch_zone):
        os.makedirs(folder_gch_zone)

    # Find the raster file corresponding to that dataset
    gch_path = '{}raw/Simard_Pinto_3DGlobalVeg_L3C.tif'.format(folder_gch)

    # Open the GFC raster file for that dataset and extract its coordinate reference system (CRS)
    gch_proj = get_geotiff_projection(gch_path)

    # Upsample 1km canopy height to 30m grid (to match PADDED SRTM raster) using the selected resampling method
    gch_upsample = '{}proc/{}/GCH_{}_cubicspline_Pad44.tif'.format(
        folder_gch, zone, zone)
    warp_command = [
        gdal_warp, '-overwrite', gch_path, gch_upsample, '-ot', 'Float32',
        '-s_srs', gch_proj, '-t_srs', 'EPSG:4326', '-tr',
        str(srtm_res_x),
        str(-srtm_res_y), '-te',
        str(pad_x_min),
        str(pad_y_min),
        str(pad_x_max),
        str(pad_y_max), '-te_srs', 'EPSG:4326', '-r', 'cubicspline',
        '-dstnodata', '-9999'
    ]
Beispiel #6
0
    # Create new folder for resampled rasters, if it doesn't exist already
    folder_gsw_zone = '{}proc/{}/'.format(folder_gsw, zone)
    if not os.path.exists(folder_gsw_zone):
        os.makedirs(folder_gsw_zone)

    # Loop through the six (6) products available, resampling & reprojecting to match the PADDED SRTM raster
    print(' - Resampling all products:', end=' ')
    for dataset in datasets:

        # Find the raster file corresponding to that dataset
        gsw_tile_path = '{}raw/{}_{}_v1_1.tif'.format(
            folder_gsw, dataset, dtm_dict[zone]['loc_string'])

        # Open the GSW raster file for that dataset and extract its coordinate reference system (CRS)
        gsw_proj = get_geotiff_projection(gsw_tile_path)

        # Warp the GSW raster to WGS84 coordinate reference system, matching the PADDED SRTM grid (with the appropriate resolution & alignment)
        gsw_resample_path = '{}proc/{}/GSW_{}_{}_Pad44.tif'.format(
            folder_gsw, zone, dataset, zone)
        gsw_resample_method = dataset_dict[dataset]['resample_method']
        gsw_resample_type = dataset_dict[dataset]['resample_type']
        warp_command = [
            gdal_warp, '-overwrite', gsw_tile_path, gsw_resample_path, '-ot',
            gsw_resample_type, '-s_srs', gsw_proj, '-t_srs', 'EPSG:4326',
            '-tr',
            str(srtm_res_x),
            str(-srtm_res_y), '-te',
            str(pad_x_min),
            str(pad_y_min),
            str(pad_x_max),