コード例 #1
0
ファイル: test_geoio.py プロジェクト: yusuftas/uncover-ml
def array_image_src(request):

    res_x = 1000
    res_y = 500
    x_range = (50, 80)
    y_range = (-40, -30)

    pixsize_x = (x_range[1] - x_range[0]) / res_x
    pixsize_y = (y_range[1] - y_range[0]) / res_y

    A = Affine(pixsize_x, 0, x_range[0],
               0, -pixsize_y, y_range[1])

    lons = np.array([(x, 0) * A for x in np.arange(res_x)])[:, 0]
    lats = np.array([(0, y) * A for y in np.arange(res_y)])[:, 1]

    channel_1 = lons[:, np.newaxis] * np.ones((res_x, res_y))
    channel_2 = lats[np.newaxis, :] * np.ones((res_x, res_y))
    data = np.concatenate((channel_1[:, :, np.newaxis],
                           channel_2[:, :, np.newaxis]), axis=2)
    masked_array = np.ma.MaskedArray(data=data, mask=False)
    im_src = geoio.ArrayImageSource(masked_array,
                                    (x_range[0], y_range[0]),
                                    crs,
                                    (pixsize_x, pixsize_y))
    return im_src
コード例 #2
0
ファイル: test_geoio.py プロジェクト: yusuftas/uncover-ml
def test_array_image_src():
    res_x = 1000
    res_y = 500
    data = np.transpose(np.mgrid[0:res_x, 0:res_y], axes=(1, 2, 0))
    masked_array = np.ma.array(data=data, mask=False)
    pix_size = (1., 1.)
    origin = (0., 0.)
    src = geoio.ArrayImageSource(masked_array, origin, crs, pix_size)
    x_min = 0
    x_max = 10
    y_min = 1
    y_max = 20
    data_new = src.data(x_min, x_max, y_min, y_max)
    data_orig = masked_array[x_min:x_max, :][:, y_min:y_max]
    assert np.all(data_new.data == data_orig.data)
    assert np.all(data_new.mask == data_orig.mask)
コード例 #3
0
ファイル: test_geoio.py プロジェクト: yusuftas/uncover-ml
def make_image(pix_size_single, origin_point,
               is_flipped, num_chunks, chunk_position):

    data = np.random.rand(32, 24, 1)
    masked_array = np.ma.array(data=data, mask=False)
    pix_size = (pix_size_single, pix_size_single)
    if is_flipped:
        pix_size = (pix_size_single, -1 * pix_size_single)
    # origin needs to change as well
    origin = (origin_point, origin_point)
    src = geoio.ArrayImageSource(masked_array, origin, crs, pix_size)

    if num_chunks > 1:
        if chunk_position == 'start':
            chunk_index = 0
        elif chunk_position == 'end':
            chunk_index = num_chunks - 1
        else:
            chunk_index = round(num_chunks/2)
        ispec = Image(src, chunk_idx=chunk_index, nchunks=num_chunks)
    else:
        ispec = Image(src)
    return ispec