示例#1
0
def statistics_func(raster_folder, raster_filename, output_folder, statistical_functions, statistical_args):
    start_time = datetime.now()
    input_raster = os.path.join(raster_folder, raster_filename)
    hdr_file = ""  # input_raster + ".hdr"        # only used for ENVI stacks
    outname = os.path.join(output_folder, raster_filename)
    if outname.find(".tif") != -1:
        outname = outname[0:len(outname) - 4]

    # arr: full size numpy array 3D XxYxZ 200x300x100
    arr = preprocessing.rio_array(input_raster, hdr_file=hdr_file)

    # activate to get list of dates from .hdr file (.hdr file needs to be specified above)
    # dates = arr[1]

    for i, func in enumerate(statistical_functions):
        # creating results with calling wanted algorithm in parallel_apply_along_axis for quick runtime
        result = apply_along_axis.parallel_apply_along_axis(func1d=func, arr=arr[0], axis=0, cores=mp.cpu_count(),
                                                            **statistical_args[i])

        # selecting dtype based on result
        dtype = type(result[0][0])

        func_name_end = str(func).find(" at")
        func_name_start = 10
        func_name = str(func)[func_name_start:func_name_end]

        # exporting result to new raster
        export_arr.functions_out_array(outname=outname + "_" + func_name + str(i), arr=result, input_file=input_raster,
                                       dtype=dtype)
    # print time to this point
    statistics_time = datetime.now()
    print("breakpoint-time = ", statistics_time - start_time, "Hr:min:sec")
示例#2
0
def filter_func(raster_folder, raster_filename, output_folder, filter_functions, filter_args):
    start_time = datetime.now()
    input_raster = os.path.join(raster_folder, raster_filename)
    hdr_file = ""   # only used for ENVI stacks
    outname = os.path.join(output_folder, raster_filename)
    if outname.find(".tif") != -1:
        outname = outname[0:len(outname) - 4]

    # arr: full size numpy array 3D XxYxZ 200x300x100
    arr = preprocessing.rio_array(input_raster, hdr_file=hdr_file)

    # activate to get list of dates from .hdr file (.hdr file needs to be specified above)
    # dates = arr[1]

    for i, func in enumerate(filter_functions):
        kernel_size = str(filter_args[i]['kernel'])
        filtered_arr = apply_along_axis.parallel_apply_along_axis(func1d=func, arr=arr[0], axis=0, cores=mp.cpu_count(),
                                                                  **filter_args[i])
        filtered_arr = np.rollaxis(filtered_arr, 2)
        filtered_arr = np.rollaxis(filtered_arr, 1)
        filtered_arr = np.rollaxis(filtered_arr, 2)

        dtype = type(filtered_arr[0][0][0])
        func_name_end = str(func).find(" at")
        func_name_start = 10
        func_name = str(func)[func_name_start:func_name_end]

        # exporting result to new raster
        export_arr.functions_out_array(outname=outname + "_" + func_name + str(kernel_size), arr=filtered_arr,
                                       input_file=input_raster, dtype=dtype)
    # print time to this point
    filter_time = datetime.now()
    print("filter-time = ", filter_time - start_time, "Hr:min:sec")
示例#3
0
def main():
    ###################################     INPUT    ########################################

    # Input Folder Marlin:
    raster_folder = "C:/Users/marli/Desktop/GEO402_Testdaten/Input_Files/Raster/"
    #shape_folder = "C:/Users/marli/Desktop/GEO402_Testdaten/Input_Files/Shapes/"
    # Input Folder Jonas:
    # raster_folder = "C:/Users/jz199/Documents/Studium/Master/1. Semester\Vorlesungsmitschriften/GEO402 - Ableitung von Landoberflächenparametern/Subset/"

    # Input file name
    raster_filename = "S1_A_VH_agulhas_full_study_site_50m"
    #raster_filename = "SubsetVH.tif"
    # shape_filename = "threshold_VH.shp"

    ###################################     OUTPUT    ########################################

    # Output Folder Marlin:
    output_folder = "C:/Users/marli/Desktop/GEO402_Testdaten/AAA_output/"
    # Output Folder Jonas:
    # output_folder = "C:/Users/jz199/Documents/Studium/Master/1. Semester\Vorlesungsmitschriften/GEO419 - Pythonprogrammierung Habermeyer/GEO402_Output/"

    # Output File Name:
    output_file = raster_filename + "cleaned.tif"

    ######################   NO USER INPUT BEYOND THIS POINT   ###############################

    input_raster = raster_folder + raster_filename
    #input_shape = shape_folder + shape_filename
    outname = output_folder + output_file

    # arr: full size numpy array 3D XxYxZ 200x300x100
    arr = preprocessing.rio_array(input_raster)
    #shp = preprocessing.fiona_shape(shape_path = input_shape)
    #shapes = [feature["geometry"] for feature in shp]
    #shapes1 = [shapes[0]]

    #burn_dates = preprocessing.fiona_burn_date(input_shape)
    #print(burn_dates)


    #time_series_length = arr.shape[0]
    #print(time_series_length)

    #mask_raster.raster_mask_func(raster=input_raster, shape=shapes, output_folder=output_folder)

    #result = tes_local_2.mask_raster_test(outname)
    #export_arr.out_array(outname=outname, arr=result, input_file=input_raster, dtype="float32")

    #result = apply_along_axis.parallel_apply_along_axis(func1d=function.slope_minimum, arr=arr, axis=0, cores=mp.cpu_count())
    result = arr
    #dtype = type(result[0][0])
    export_arr.cleaned_out_array(outname=outname, arr=result, input_file=input_raster, dtype="float32")

    end_time = datetime.now()
    print("end-time = ", end_time-start_time, "Hr:min:sec")
示例#4
0
def main():

    ###################################     INPUT    ########################################

    # Input Folder Marlin:
    raster_folder = "C:/Users/marli/Desktop/GEO402_Testdaten/Input_Files/Raster/"
    # Input Folder Jonas:
    # raster_folder = "C:/Users/jz199/Documents/Studium/Master/1. Semester\Vorlesungsmitschriften/GEO402 - Ableitung von Landoberflächenparametern/Subset/"

    # Input file name
    raster_filename = "S1_A_VH_agulhas_full_study_site_50m"
    # raster_filename = "SubsetVH.tif"

    ###################################     OUTPUT    ########################################

    # Output Folder Marlin:
    output_folder = "C:/Users/marli/Desktop/GEO402_Testdaten/AAA_output/"
    # Output Folder Jonas:
    # output_folder = "C:/Users/jz199/Documents/Studium/Master/1. Semester\Vorlesungsmitschriften/GEO419 - Pythonprogrammierung Habermeyer/GEO402_Output/"



    # Output File Name:
    # output_file = raster_filename[0:len(raster_filename)-4] + "_median_filtered3.tif"
    output_file = raster_filename + "_median_test2.tif"
#simple_edge_detection
    ######################   NO USER INPUT BEYOND THIS POINT   ###############################

    input_raster = raster_folder + raster_filename
    hdr_file = input_raster + ".hdr"
    outname = output_folder + output_file

    # arr: full size numpy array 3D XxYxZ 200x300x100
    arr = preprocessing.rio_array(input_raster, hdr_file=hdr_file)

    dates = arr[1]
    #print(dates)

    # creating filtered array depending on set filter function
    filtered_arr = apply_along_axis.parallel_apply_along_axis(func1d=filter_functions.median_filter11, arr=arr[0], axis=0, cores=mp.cpu_count())
    filtered_arr = np.rollaxis(filtered_arr, 2)
    filtered_arr = np.rollaxis(filtered_arr, 1)
    filtered_arr = np.rollaxis(filtered_arr, 2)
    dtype = type(filtered_arr[0][0][0])
    #print(type(dtype)
    #if type(dtype) == np.float64:
    #    print("lalala")
    # --> change float64 to float32

    export_arr.functions_out_array(outname=outname, arr=filtered_arr, dates=dates, input_file=input_raster, dtype=dtype)


    # creating results with calling wanted algorithm in parallel_apply_along_axis for quick runtime
    #result = apply_along_axis.parallel_apply_along_axis(func1d=function.find_peaks, arr=arr[0], axis=0, cores=mp.cpu_count())

    # selecting dtype based on result
    dtype = np.int32 #type(result[0][0])
    # dtype = type(filtered_arr[0][0])
    # float64 to float32

    # exporting result to new raster
    #export_arr.functions_out_array(outname=outname, arr=result, dates=dates, input_file=input_raster, dtype=dtype)
    # export_arr.functions_out_array(outname=outname, arr=filtered_arr, input_file=input_raster, dtype=dtype)

    end_time = datetime.now()
    print("end-time = ", end_time-start_time, "Hr:min:sec")