`SwathDef.aggregate` bugs and enhancements
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 385
- Forks
- 102
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 9
Description
Problem description
SwathDef.aggregate currently works only if SwathDefinition is defined by passing lons/lats xr.DataArray with lons and lats dimensions and dask arrays.
Code Sample
import numpy as np
import dask.array as da
import xarray as xr
from pyresample.geometry import SwathDefinition
lons = np.arange(-179.75, 179.75 + 0.5, 0.5)
lats = np.arange(-89.75, 0.5, 0.5)
lons, lats = np.meshgrid(lons, lats)
# BUG: This does not work. It expects an xr.DataArray
swath_def = SwathDefinition(lons=lons, lats=lats)
swath_def.aggregate(x=2, y=1) # Downsample by factor of 2 along x
# BUG: This does not work. It expects a chunked dask array.
lons_da = xr.DataArray(lons, dims=("lats","lons"))
lats_da = xr.DataArray(lats, dims=("lats","lons"))
swath_def = SwathDefinition(lons=lons_da, lats=lats_da)
swath_def.aggregate(x=2, y=1) # Downsample by factor of 2 along x
# This works to coarse the data
lons = da.from_array(lons)
lats = da.from_array(lats)
lons_da = xr.DataArray(lons, dims=("lats","lons"))
lats_da = xr.DataArray(lats, dims=("lats","lons"))
swath_def = SwathDefinition(lons=lons_da, lats=lats_da)
swath_def.aggregate(x=2, y=1) # Downsample by factor of 2 along x
Limitations & Consistency
AreaDef.aggregate enables to also upsampling (downscaling) the area by providing x, y dimensions < 1
swath_def.aggregate(x=1/2, y=1/2) # Split each pixel in 4 pixels
In contrast, SwathDef.aggregate is able to just coarse the grid by averaging geocentric x, y, z coordinates, as dask.array coarsen accepts only accepts only x, y integers >= 1.
swath_def.aggregate(x=1/2, y=1)
swath_def.aggregate(x=1/2, y=1)
Suggested improvements
- Enable
swath_def.aggregateto work also with lons/lats defined in numpy arrays - Add method
area_def.upsample(straighforward) - Add method
swath_def.upsample - Switch name from
aggregatetodownsample?
This would address also issue https://github.com/pytroll/pyresample/issues/28
Implementation idea for swath_def.upsample
- Conversion of lons/lats to geocentric x,y,z
- Infer current "pixel" corners in x,y,z
- Define new pixel centroids in x,y,z
- Backconversion to lats/lons
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the SwathDefinition.aggregate and AreaDef.aggregate entry points, then reproduce the NumPy and non-chunked DataArray examples from the issue. Compare the existing downsampling behavior with the proposed upsampling approach and issue #28. Done means the requested SwathDefinition operations work for the stated inputs and match the documented AreaDef behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100