pydata / pydata/xarray

User defined function to deal with Merge Conflicts

Open
#6,846 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Is your feature request related to a problem?

When merging data with overlapping values at the same coordinates, the only current option to avoid a MergeError is to select the variable from the first dataset or to remove the offending areas.

This does not work when an element wise merge is desired, where the outcoming data is a result of an operation on the overlapping data.

An example is two heatmap datasets with an overlap, where it is desired for that overlap to be an average of the two seperate datasets.

Describe the solution you'd like

To allow expansion and customisability of this feature, I would see an ability to provide a user defined function that can receive the overlapping region element wise, and return a single value to be merged into the final variable.

import math
import xarray

def average_overlap(*values):
     return math.mean(values)

xarray.merge([data_1, data_2], merge_func = average_overlap) 
# Where data_1 & data_2 contain overlapping data

My concern for this feature is it's scalability for large overlapping regions and it's integration into the current merge code structure.

Describe alternatives you've considered

I've looked into implementing this myself within xarray, but cannot find the place to insert this feature.

As the data I am using is netcdf, xarray remains an excellent tool to use, and I would rather not use another method.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the xarray.merge entry point and trace how overlapping values currently produce MergeError. Determine how a user-supplied element-wise function could define the merged value, including behavior and scalability for large overlaps; done means documented, tested support for the requested averaging-style merge.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.