Exemplo n.º 1
0
def sza_opencl(scene, time_slot):
    dRightAscension, dDeclination, dGreenwichMeanSiderealTime = sunposIntermediate(
        time_slot.year, time_slot.month, time_slot.day, time_slot.hour,
        time_slot.minute, 0.0)
    scale_x = scene["IR_108"].area.pixel_size_x
    scale_y = scene["IR_108"].area.pixel_size_y
    offset_x = scene["IR_108"].area.pixel_offset_x
    offset_y = scene["IR_108"].area.pixel_offset_y

    band = scene["IR_108"].data.astype(float32)
    outputBand = scipy.zeros_like(band, dtype=float32)

    mf = cl.mem_flags
    ctx = cl.create_some_context()
    outputBuffer = cl.Buffer(ctx,
                             mf.WRITE_ONLY | mf.USE_HOST_PTR,
                             hostbuf=outputBand)
    prg = loadOpenCLProgram("../util/opencl/solarangle.cl", ctx)
    queue = cl.CommandQueue(ctx)

    prg.zenithKernel(queue, band.shape, None, outputBuffer,
                     float32(dGreenwichMeanSiderealTime),
                     float32(dRightAscension), float32(dDeclination),
                     float32(scale_x), float32(scale_y), float32(offset_x),
                     float32(offset_y))

    cl.enqueue_copy(queue, outputBand, outputBuffer)

    plot2dArray(outputBand,
                title="sza_results",
                show=True,
                outputPath="/home/sebastian/Documents/tests_sza123_full.png")

    return
Exemplo n.º 2
0
def stratiformity_opencl(scene,
                         cloudmask,
                         show_plots=False,
                         plot_path="",
                         createPlots=False,
                         cl_ctx=None,
                         cl_queue=None):
    # Mask band with -999.9-values
    noDataValue = -999.9

    band = scipy.where(cloudmask == False, noDataValue,
                       scene["IR_108"].data).astype(numpy.float32)
    outputBand = scipy.zeros_like(band, dtype=numpy.float32)

    mf = cl.mem_flags
    if cl_ctx is None:
        platforms = cl.get_platforms()
        devices = platforms[1].get_devices(device_type=cl.device_type.CPU)
        cl_ctx = cl.Context(devices)
    if cl_queue is None:
        cl_queue = cl.CommandQueue(cl_ctx)

    inputBuffer = cl.Buffer(cl_ctx,
                            mf.READ_ONLY | mf.USE_HOST_PTR,
                            hostbuf=band)
    outputBuffer = cl.Buffer(cl_ctx,
                             mf.WRITE_ONLY | mf.USE_HOST_PTR,
                             hostbuf=outputBand)
    prg = loadOpenCLProgram("../util/opencl/std.cl", cl_ctx)
    prg.calcSTD(cl_queue, band.shape, None, inputBuffer, outputBuffer)
    cl.enqueue_copy(cl_queue, outputBand, outputBuffer)
    outputBand = scipy.where(cloudmask == False, numpy.nan,
                             outputBand).astype(numpy.float32)

    if createPlots:
        plot2dArray(outputBand,
                    title="standard deviations of 10.8band",
                    show=show_plots,
                    outputPath=plot_path + "strat_stds.png")

    #filter clouds of max 3 pixel size
    std_band = scipy.where(outputBand <= 2., 1., 0.).astype(numpy.float32)
    filtered_outputBand = scipy.zeros_like(std_band, dtype=numpy.float32)

    inputBuffer = cl.Buffer(cl_ctx,
                            mf.READ_ONLY | mf.USE_HOST_PTR,
                            hostbuf=std_band)
    outputBuffer = cl.Buffer(cl_ctx,
                             mf.WRITE_ONLY | mf.USE_HOST_PTR,
                             hostbuf=filtered_outputBand)
    prg = loadOpenCLProgram("../util/opencl/std.cl", cl_ctx)
    queue = cl.CommandQueue(cl_ctx)
    prg.filterSmallClouds(queue, band.shape, None, inputBuffer, outputBuffer)
    cl.enqueue_copy(cl_queue, filtered_outputBand, outputBuffer)

    return scipy.where(filtered_outputBand > 0., True, False)
Exemplo n.º 3
0
def stratiformity(scene,
                  cloudmask,
                  show_plots=False,
                  plot_path="",
                  createPlots=False):
    stds = rolling_std(scene["IR_108"].data, cloudmask, 3)
    if createPlots:
        plot2dArray(stds,
                    title="standard deviations of 10.8band",
                    show=show_plots,
                    outputPath=plot_path + "strat_stds.png")
    return scipy.where(stds <= 2., True, False)
Exemplo n.º 4
0
def cloud_phase(scene,
                cloudmask,
                show_plots=False,
                plot_path="",
                createPlots=False):
    test1_data = scipy.where(scene["IR_108"].data < 230., True,
                             False)  # Everything <230K: Ice
    if createPlots:
        plot2dArray(test1_data,
                    title="cloud phase below 230K",
                    show=show_plots,
                    outputPath=plot_path + "clphase_belowTemp.png")
    test4_data = scipy.where(scene["IR_087"].data - scene["IR_108"].data > 0,
                             True, False)  # Where 8.7 - 10.8 > 0: Ice
    if createPlots:
        plot2dArray(test4_data,
                    title="cloud phase: 8.7 > 10.8",
                    show=show_plots,
                    outputPath=plot_path + "clphase_87-108diff.png")
    result = cloudmask & ~(test1_data | test4_data)
    return result
Exemplo n.º 5
0
def snow_identification(scene,
                        show_plots=False,
                        plot_path="",
                        createPlots=False):
    test1_data = scipy.where(scene["VIS008"].data > 0.11, 1.,
                             0.)  # Snow has a minimal reflectance (0.11)
    if createPlots:
        plot2dArray(test1_data,
                    title="snow minrefl",
                    show=show_plots,
                    outputPath=plot_path + "snow_minrefl.png")

    test2_data = scipy.where(
        scene["IR_108"].data > 256., 1.,
        0.)  # Snow has a minimal Brightness Temperature (-17,15′C)
    if createPlots:
        plot2dArray(test2_data,
                    title="snow mintemp",
                    show=show_plots,
                    outputPath=plot_path + "snow_mintemp.png")

    ndsi = (scene["VIS006"].data - scene["IR_016"].data) / (
        scene["VIS006"].data + scene["IR_016"].data)
    ndsi = scipy.where(ndsi != None, ndsi, 0.)
    if createPlots:
        plot2dArray(ndsi,
                    title="NDSI",
                    show=show_plots,
                    outputPath=plot_path + "snow_ndsi.png")

    test3_data = scipy.where(ndsi > 0.4, 1., 0.)  # NDSI > 0.4 --> Snow
    return scipy.where(test1_data + test2_data + test3_data == 3, True,
                       False)  # Where all 3 tests are true: Snow-Pixel!
Exemplo n.º 6
0
def small_droplet_proxy(scene,
                        cloud_mask,
                        not_day_land_mask,
                        not_day_mask,
                        show_plots=False,
                        plot_path="",
                        createPlots=False):
    array = np.ma.array(scene["IR_039"].data)

    if createPlots:
        plot2dArray(array,
                    title="03.9 array",
                    show=show_plots,
                    outputPath=plot_path + "sdp_array.png")
    mask = cloud_mask & not_day_land_mask
    if createPlots:
        plot2dArray(mask,
                    title="sdp mask",
                    show=show_plots,
                    outputPath=plot_path + "sdp_land_cloud_mask.png")
    array.mask = mask

    blocks = block_by_size_generator(array.shape, array.shape[1],
                                     array.shape[0], 0)

    result_blocks = find_block_threshold(array, blocks)
    #print result_blocks
    threshold_array = scipy.empty_like(array)
    blocks_into_threshold_array(result_blocks, threshold_array)
    if createPlots:
        plot2dArray(threshold_array,
                    title="sdp thresholds",
                    show=show_plots,
                    outputPath=plot_path + "sdp_thresholds.png")

    array.mask = 0
    result = (array > threshold_array) & cloud_mask & ~not_day_mask
    if createPlots:
        plot2dArray(result,
                    title="sdp result",
                    show=show_plots,
                    outputPath=plot_path + "sdp_result.png")
    return result
Exemplo n.º 7
0
def very_low_cloud_plausibility(scene,
                                mask_allPreviousSteps,
                                mask_cloudIdentification,
                                dem,
                                lapserate=0.007,
                                plot_path="",
                                show_plots=False):
    nanmask = scipy.where(
        mask_cloudIdentification == True, numpy.nan, 1.
    )  # Converting True/False mask to nan/1. mask (using mask_cloudIdentification because only this mask definitely has NO cloud pixels for "False"
    BT_108_masked = nanmask * scene[
        "IR_108"].data  # Multiplying mask with scene["IR_108"].data so only non-masked pixels keep their values
    dem = scipy.where(dem == -9999, 0.,
                      dem)  # Exchanging nanvalues (-9999) (sea-pixels) with 0
    DEM_masked = nanmask * dem  # Multiplying mask with DEM so only non-masked pixels keep their values

    xsize = len(BT_108_masked[0])
    ysize = len(BT_108_masked)

    cloudTopHeights = numpy.empty(
        (ysize, xsize))  # Initializing the result-2darray...
    cloudTopHeights.fill(numpy.nan)  # ... and filling it with nans

    # For each pixel that is a liquid-smalldroplet-stratiform-nonsnow-cloudy pixel
    # get direct neighbouring pixels and calculate the mean for BT108 and the DEM-values
    # but only for those neighbour pixels where the mask_cloudIdentification shows NO cloud!
    # and calculate the height of the clouds of these pixels...
    for i in range(ysize):
        for j in range(xsize):
            if mask_allPreviousSteps[
                    i, j] == True:  # If the current pixel is a cloud pixel do:
                avSurroundingBT = numpy.nan
                N = 1
                while numpy.isnan(
                        avSurroundingBT
                ):  # as long as no non-cloud-neighbour is found: increase search radius by 1
                    iminus = 0
                    iplus = ysize
                    jminus = 0
                    jplus = xsize
                    if i - N > 0: iminus = i - N
                    if i + N <= ysize: iplus = i + N + 1
                    if j - N > 0: jminus = j - N
                    if j + N <= xsize: jplus = j + N + 1
                    avSurroundingBT = numpy.nanmean(
                        BT_108_masked[iminus:iplus, jminus:jplus])
                    avSurroundingElevation = numpy.nanmean(
                        DEM_masked[iminus:iplus, jminus:jplus])
                    cloudTopHeights[i,
                                    j] = func(avSurroundingBT,
                                              scene["IR_108"].data[i, j],
                                              lapserate,
                                              avSurroundingElevation, dem[i,
                                                                          j])
                    cloudTopHeights[i, j] = func(avSurroundingBT,
                                                 scene["IR_108"].data[i, j],
                                                 lapserate, 0, 0)
                    N += 1

    plot2dArray(cloudTopHeights,
                title="Cloud Top Heights",
                outputPath=plot_path + "vlc_cth.png",
                show=show_plots)
    return scipy.where(cloudTopHeights <= 1000., True, False)
Exemplo n.º 8
0
#write_scene(scene, "/home/sebastian/Documents/")

#plot2dArray(lats,title="lats",show=True, outputPath="/home/sebastian/Documents/tests_sza123_full_lats.png")
#plot2dArray(lons,title="lons",show=True, outputPath="/home/sebastian/Documents/tests_sza123_full_lons.png")

# Correct nodata-value and value type of elevation model:

demWorldclim = gdal.Open(
    "/home/sebastian/git/cloudmask/data/dem/dem_worldclim_fulldisk_noNegativeElevations.tif",
    GA_ReadOnly)
demWorldclim_band = demWorldclim.GetRasterBand(1)
demWorldclim_data = demWorldclim_band.ReadAsArray(0, 0,
                                                  demWorldclim.RasterXSize,
                                                  demWorldclim.RasterYSize)

data = scipy.where(demWorldclim_data < 0., -999., demWorldclim_data)

plot2dArray(data, show=True)

proj = demWorldclim.GetProjection()
xsize = demWorldclim.RasterXSize
ysize = demWorldclim.RasterYSize

driver = gdal.GetDriverByName('GTiff')
dsO = driver.Create("/home/sebastian/Documents/dem_final_nonegativeValues.tif",
                    3712, 3712, 1, gdal.GDT_Int16)
dsO.SetProjection(proj)
dsO.GetRasterBand(1).WriteArray(int16(data))
dsO.FlushCache()  # Write to disk.