Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor python API #8

Closed
perrygeo opened this issue Jul 28, 2016 · 2 comments
Closed

Refactor python API #8

perrygeo opened this issue Jul 28, 2016 · 2 comments

Comments

@perrygeo
Copy link
Contributor

We should build a pure function (data-in, data-out, no IO) that we can unit test easily. This might take some refactoring to accomplish.

I'm thinking of a function with a signature like:

def pansharpen(vis, vis_transform, pan, pan_transform, method="Brovey"):
    """Pansharpen a lower-resolution visual band

    Parameters
    =========
    vis: ndarray, 3D with shape == (3, vh, vw)
        Visual band array with RGB bands
    vis_transform: Affine
        affine transform defining the georeferencing of the vis array
    pan: ndarray, 2D with shape == (ph, pw)
        Panchromatic band array
    pan_transform: Affine
        affine transform defining the georeferencing of the pan array
    method: string
        Algorithm for pansharpening; default Brovey

    Returns:
    ======
    pansharp: ndarray, 3D with shape == (3, ph, pw)
        pansharpened visual band
        affine transform is identical to `pan_transform`
    """
@virginiayung
Copy link
Collaborator

virginiayung commented Aug 1, 2016

These are the current steps I am taking to refactor the current worker script in the refactor_api branch and PR #13

  • Renaming current pansharpen function to calculate_landsat_pansharpen. This function handles:
  • reading, updating input meta data
  • writing the result of pansharpening (derived by _pansharpen_worker) into each window respectively via riomucho.
  • _pansharpen_worker function is the riomucho worker for pansharpening. It is responsible for:
    • Reading panchromatic band data, determines the datatype for the panchromatic band from meta data
    • Determining RGB window sizes (includes padding)
    • Determining affines for pan, RGB windows
    • Reading RGB data
    • Passing necessary arguments to the new pansharpen function to perform pansharpening
    • rescaling pansharpened array to destination datatype
  • new pansharpen is the pansharpening python API (data-in, data-out, no IO) that performs pansharpening operations:
    • Takes ndarrays (RGB bands, pan band), and arguments (Affine transforms) etc
    • Creates a mask of pixels where any channel is 0 (nodata)
    • Apply the mask to each of the RGB bands
    • Perform pansharpening using the specified algorithm. Default is Brovey.
    • Returns ndarray, 3D with shape == (3, panband_height, panband_width)

The biggest advantage for refactoring the current pansharpening script into a pure function, separating IO from array operations is so that we can easily write unit tests that specifically test for array operations:

def test_create_apply_mask(arr):
  .
  .
def test_upsample(masked_arr, pan.shape, pan.shape, rgb_affine, r_crs, pan_affine, dst_crs)
  .
  .
def test_Brovey(arr1, arr2, weight, dtype):
  .
  .
def test_rescale(arr):
  .
  .

cc @dnomadb @perrygeo @celoyd @mapbox/satellite

@virginiayung virginiayung mentioned this issue Aug 1, 2016
3 tasks
@virginiayung
Copy link
Collaborator

🚢 in PR #13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants