Exemple #1
0
def find_fit(vi, signaturedirectory, image, outputdir, outputfoldername, startdoy, doyinterval, temporalshift,
             threshold, ndvalue, subset, meantype, numberofprocesses, cliptopixelextent, cliptoshapeextent, timebounds,
             xbounds, ybounds):
    """
    Fit the fit of reference temporal signatures to pixels in a multidate image.
    """
    #TODO Docstring
    #TODO Add Parameter Validation Callbacks as necessary

    # validate clip options
    if cliptopixelextent and cliptoshapeextent:
        click.BadParameter("Cannot clip the image to both a shapefile and pixel extent. Choose one or the other.")

    # import required modules
    import os
    from signatureFunctions import get_sigs_in_dir
    from utils import create_output_dir
    from imageFunctions import clip_raster_to_extent, clip_and_mask_raster_with_shapefile
    from fitting import fit_refs_to_image

    signatures = get_sigs_in_dir(signaturedirectory, viname=vi)

    if outputdir is None:
        outputdir = os.path.dirname(image)

    outdir = create_output_dir(outputdir, outputfoldername)

    if cliptoshapeextent:
        imagename, ext = os.path.splitext(os.path.basename(image))
        outimage = os.path.join(outdir, imagename + "_clip" + ext)
        imagetoprocess = clip_and_mask_raster_with_shapefile(image, cliptoshapeextent, outimage)
    elif cliptopixelextent:
        imagename, ext = os.path.splitext(os.path.basename(image))
        outimage = os.path.join(outdir, imagename + "_clip" + ext)
        imagetoprocess = clip_raster_to_extent(image, outimage, cliptopixelextent[0], cliptopixelextent[1],
                                               cliptopixelextent[2], cliptopixelextent[3])
    else:
        imagetoprocess = image

    fit_refs_to_image(imagetoprocess, outdir, signatures, startdoy, doyinterval,
                               temporalshift, threshold=threshold, ndvalue=ndvalue, subset=subset, meantype=meantype,
                               workers=numberofprocesses, timebounds=timebounds, xbounds=xbounds, ybounds=ybounds)
Exemple #2
0
def extract_signatures(image, shapefiledirectory, startdoy, doyinterval, outputdir, filelabel, plotsigs):
    """
    Extracts temporal signatures for a set of point geometry shapefiles in a specified directory and outputs them to a
    set of .ref files in an output directory.
    """
    import os
    from plotting import SignaturePlot
    from utils import find_files, create_output_dir, unique_name
    from signatureFunctions import get_sigs_in_dir, get_reference_curves

    if outputdir is None:
        outputdir = create_output_dir(os.path.dirname(image), "signatures", usetime=True)

    shapefiles = find_files(shapefiledirectory, ".shp", recursive=False)

    #TODO: Need a method to find only valid shapefiles in the directory

    get_reference_curves(image, shapefiles, startdoy, doyinterval, outdir=outputdir, filepostfix=filelabel)

    if plotsigs:
        path = unique_name(outputdir, "signaturePlot", ext=".pdf")
        sigs = get_sigs_in_dir(outputdir)
        plot = SignaturePlot(outputdir, os.path.basename(path))
        plot.plot_collection(sigs)