Skip to main content

A sample project with checkerboard functionality

Project description

CheckmateSample

This Python module provides a function to generate a checkerboard pattern using NumPy. The function make_checkerboard creates a 2D NumPy array representing a checkerboard with customizable board size and square (and rectangle) sizes. Can be used for geospatial ML problems to try and combat autocorrelation. The functions can export two (testing/training) and three (testing/training/validation) checkerboard patterns

Parameters

board_size (tuple[int, int]): Size of the board in (rows, columns).

square_size (tuple[int, int]): Size of each square in (rows, columns).

separation_size (int): Size of separation distance in pixels between squares.

validation (bool): If True, use a ternary (0, 1, 2) pattern; if False, use a binary (0, 1) pattern

verbose flag: True / False

an example of this is:

checkerboard_01 = make_checkerboard(board_size=(70,70), square_size=(10,10), separation_size=2)

xarray only:

dim_names (dict): Dictionary specifying the names of x and y dimensions da (xr.DataArray): Input DataArray to apply the checkerboard pattern to

an example of this:

ds = xr.tutorial.load_dataset('air_temperature')

air_temp = ds.air.isel(time=0)

square_size = (7, 5)  # 7x5 pixel squares
checkerboard_temp_0 = make_checkerboard_xr(air_temp, square_size, separation_size=3, keep_pattern=0, validation=False)

Dependencies

numpy and xarray

Useage

Create a NumPy checkerboard

checkerboard = make_checkerboard((10, 10), (2, 2))

Create an xarray DataArray

da = xr.DataArray(np.random.rand(100, 100), dims=['lat', 'lon'])

Apply checkerboard pattern to DataArray

result = make_checkerboard_xr(da, (10, 10), keep_pattern=1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

checkmatesample-0.4.1.post0.tar.gz (837.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

checkmatesample-0.4.1.post0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file checkmatesample-0.4.1.post0.tar.gz.

File metadata

  • Download URL: checkmatesample-0.4.1.post0.tar.gz
  • Upload date:
  • Size: 837.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for checkmatesample-0.4.1.post0.tar.gz
Algorithm Hash digest
SHA256 bf53a67c78b4ddc8fed32ea45d536ad5147f50f35e7de90625ab0ff4699d6cfb
MD5 e1cb4e900f38ac6d3c0395dadbe87cb5
BLAKE2b-256 361a999b0e6dee4c47fbc57f9cd67f6c3c5246b17b1a03716ef8e2cf5db41f47

See more details on using hashes here.

File details

Details for the file checkmatesample-0.4.1.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for checkmatesample-0.4.1.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 2df4436f748147358d17d71d419863e39441484489e5cc1c76b74e48ee814f5a
MD5 4b6673bfeef99d3215f1e7d017a83faf
BLAKE2b-256 dbc556d3fbe301d191a3db35d9920442a878b708d84174e7c9ae3c6840c41e71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page