fatiando / harmonica

Forward modeling, inversion, and processing gravity and magnetic data
https://www.fatiando.org/harmonica
BSD 3-Clause "New" or "Revised" License
208 stars 68 forks source link

Filter reduction_to_pole works only with "northing", "easting" coordinate names #439

Closed zaarcvon closed 1 week ago

zaarcvon commented 11 months ago

My first issue on GitHub. Sorry if something is wrong:-)

I found that most filters are insensitive to xarray coordinates names; only the order is important. But filter reduction_to_pole works only if coordinates have names "northing" and "easting". Otherwise error "'freq_northing' is not a valid dimension or coordinate" appears.

So maybe it could be useful to change row 475 in _filters.py from: da_filter.loc[dict(freq_northing=0, freq_easting=0)] = 0 to: da_filter.loc[{freq_northing.name:0, freq_easting.name:0}] = 0

The current version generates dict with string keys: "freq_northing" and "freq_easting" while the suggested one generates keys according to the initial coordinate names.

leouieda commented 9 months ago

Hi @zaarcvon thank you for reporting this! Good catch! You'll see that in the rest of the function we avoid using the dimension names precisely for this reason but that line must have slipped past our tests.

The fix you suggests would work and so would something like:

da_filter.loc[{dims[0]=0, dims[1]=0}] = 0

Would you be interested in contributing this fix? If so, have a look at our Contributing Guide. A good test for this would be to change the name the coordinates in one of our test datasets and then run the filter to make sure it doesn't produce an error.