Ejemplo n.º 1
0
def main(gedi_dir, temp_dir, bounds_file, outfile, nproc, res):

    """
    Main function to execute python script
    """

    nproc = int(nproc) - 1

    attrib = {'BEAM': 'int', 'FILE': 'str', 'YEAR': 'int', 'JDAY': 'int'}

    res = float(res)

    bounds_vec = Vector(bounds_file)
    bounds_wkt = bounds_vec.wktlist[0]

    args_list = list((filename, temp_dir, bounds_wkt, res)
                     for filename in Handler(dirname=gedi_dir).find_all('*.h5'))

    n_files = len(args_list)

    Opt.cprint('Number of files: {}'.format(str(n_files)))

    out_res = {}

    Handler(outfile).file_delete()

    pool = mp.Pool(processes=nproc)

    for file_output, err_str in pool.imap_unordered(get_path, args_list):
        if err_str is None and len(file_output) > 0:
            add_on = ''
            count = 0
            for geom_wkt, attrs in file_output:
                if geom_wkt is not None:
                    write_to_txt(geom_wkt, attrs, outfile)
                    out_res[geom_wkt] = attrs
                    count += 1
            if count > 0:
                add_on = ' - FOUND {} BEAMS'.format(str(count))
            out_str = str(list(set([attr['FILE'] for _, attr in file_output]))[0]) + ' : READ' + add_on
            Opt.cprint(out_str)
        else:
            if err_str is None:
                err_str = 'Unknown File I/O Error'

            Opt.cprint('{}: {}'.format(file_output,
                                       err_str))
    pool.close()

    Opt.cprint(outfile)
Ejemplo n.º 2
0
from geosoup import Vector
import numpy as np

if __name__ == '__main__':

    # file1 = "D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/samples/all_samp_pre_v1.shp"
    file1 = "D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/samples/CAN_PSP/PSP_data/CAN_PSP_v1.shp"
    file2 = "D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/STUDY_AREA/ABoVE_Study_Domain_geo.shp"

    lat_x = 52.0

    vec = Vector(file1)

    vec2 = Vector(file2)

    geom2 = vec2.features[0].GetGeometryRef()

    lonlat = []

    for i in range(vec.nfeat):

        geom = vec.features[i].GetGeometryRef()

        pt = geom.GetPoint()

        lonlat.append(pt[0:2])

    print(len(lonlat))

    uniq, indices, inverse, count = np.unique(ar=lonlat,
                                              axis=0,
    start_year = 2000
    end_year = 2017
    pixel_size = 0.0021  # 250m MODIS resolution

    fire_year_col = 'FireYear'
    fire_id_col = 'FIREID'

    filelist = [
        'D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/FIRE/ak_fire/FireAreaHistory.shp'
    ]
    outfolder = 'D:/temp/fire/'

    for infile in filelist:

        vec = Vector(infile)
        sys.stdout.write(
            '========================\nInput Vector file: {}\n'.format(infile))

        attr = vec.attributes[0]
        attr_dict = dict()
        for k, v in attr.items():
            attr_dict[k] = Vector.string_to_ogr_type(v, 'name')

        order = np.argsort(
            np.array([
                int(attr_dict[fire_year_col]) for attr_dict in vec.attributes
            ])).tolist()

        x_min, x_max, y_min, y_max = vec.layer.GetExtent()
        sys.stdout.write('Extent: {}\n'.format(' '.join(
Ejemplo n.º 4
0
import pandas as pd
import json
from osgeo import ogr
import numpy as np

if __name__ == '__main__':

    infilename = "D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/samples/CAN_PSP/" \
        "CAN_PSPs_Hember-20180207T213138Z-001/CAN_PSPs_Hember/NAFP_L4_SL_ByJur_R16d_ForBrendanRogers1.csv"

    outfilename = "D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/samples/CAN_PSP/" \
        "CAN_PSPs_Hember-20180207T213138Z-001/CAN_PSPs_Hember/NAFP_L4_SL_ByJur_R16d_ForBrendanRogers1_lat52_ABoVE.shp"

    bounds = "D:/Shared/Dropbox/projects/NAU/landsat_deciduous/data/STUDY_AREA/ABoVE_Study_Domain_geo.shp"

    bounds_vec = Vector(bounds)
    bounds_geom = bounds_vec.features[0].GetGeometryRef()

    attr = {'ID_Plot': 'str', 'Lat': 'float', 'Lon': 'float'}

    samp_data = Handler(infilename).read_from_csv(return_dicts=True)

    wkt_list = list()
    attr_list = list()

    spref_str = '+proj=longlat +datum=WGS84'
    latlon = list()
    count = 0
    for row in samp_data:
        print('Reading elem: {}'.format(str(count + 1)))
Ejemplo n.º 5
0
    ls8_1 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
    ls8_2 = ee.ImageCollection("LANDSAT/LC08/C01/T2_SR")

    elevation = ee.Image('USGS/GMTED2010')
    slope = ee.Terrain.slope(elevation)
    aspect = ee.Terrain.aspect(elevation)

    topo_image = elevation.addBands(slope).addBands(aspect).select(
        [0, 1, 2], ['elevation', 'slope', 'aspect'])

    topo_bandlist = ['elevation', 'slope', 'aspect']
    bands = bands + topo_bandlist

    feat_list = list()

    samp_vec = Vector(infile)
    log.lprint('{}: {}'.format(os.path.basename(infile), samp_vec))

    intersect_count = 0

    for i, wkt in enumerate(samp_vec.wktlist):

        if boundary_geom.Intersects(Vector.get_osgeo_geom(wkt)):

            intersect_count += 1

            feat_dict = dict()
            in_dict = samp_vec.attributes[i]
            for k, v in in_dict.items():
                if k in feat_properties:
                    feat_dict[k] = v
Ejemplo n.º 6
0
    ini_outfile = outdir + "all_samp_pre_v1.shp"
    outfile = outdir + "all_samp_postbin_v{}.csv".format(version)
    outshpfile = outdir + "all_samp_postbin_v{}.shp".format(version)

    trn_outfile = outdir + "all_samp_post_v{}_trn_samp.shp".format(version)
    val_outfile = outdir + "all_samp_post_v{}_val_samp.shp".format(version)

    boreal_bounds = "D:/shared/Dropbox/projects/NAU/landsat_deciduous/data/STUDY_AREA/boreal/" \
                    "NABoreal_simple_10km_buffer_geo.shp"

    year_bins = [(1984, 1997), (1998, 2002), (2003, 2007), (2008, 2012),
                 (2013, 2018)]

    # script-----------------------------------------------------------------------------------------------

    boreal_vec = Vector(boreal_bounds)
    boreal_geom = Vector.get_osgeo_geom(boreal_vec.wktlist[0])

    year_samp = list(list() for _ in range(len(year_bins)))
    year_samp_reduced = list(list() for _ in range(len(year_bins)))

    # get data and names
    file_data = Handler(infile).read_from_csv(return_dicts=True)
    header = list(file_data[0])

    print('\nTotal samples: {}'.format(str(len(file_data))))

    boreal_samp_count = 0

    # bin all samples based on sample years using year_bins
    for elem in file_data: