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

Add function to regrid Sv data #726

Open
leewujung opened this issue Jun 15, 2022 · 12 comments · May be fixed by #1291
Open

Add function to regrid Sv data #726

leewujung opened this issue Jun 15, 2022 · 12 comments · May be fixed by #1291
Assignees

Comments

@leewujung
Copy link
Member

leewujung commented Jun 15, 2022

It is a pretty common need to regrid Sv data, since different channels (frequencies) may be configured differently to collect data with different sample_interval even if the total range collected is the same.

Proposal: add this to the commongrid subpackage.

@leewujung
Copy link
Member Author

@leewujung will add a link here to a ref implementation from IMR.

@lsetiawan
Copy link
Member

This should be optional... potentially use: https://xesmf.readthedocs.io/en/latest/index.html

@leewujung
Copy link
Member Author

I found my notes from before. Here are two resources, one from IMR and the other pyEcholab.

IMR:

  • it seems that _resampleWeight, _regrid, and regrid_sv are the functions used by IMR here.
  • it also seems that the ditched the resampleWeight thing in this line under regrid_Sv

pyEcholab:

  • grid.py seems to be generating just the grid boundaries
  • integration.py they basically do integration over pixels in linear domain that fall within the grid computed from grid.py, and then converting it to the log domain
  • their grids here are much larger and since it is integration, it corresponds better with NASC, especially because there is "layer" and "interval" in the language, so not really the finer regridding we are discussing here.

@lsetiawan
Copy link
Member

@leewujung Could you point us to a test data for this?

@leewujung
Copy link
Member Author

I haven't generated any datasets for this. I think to generate outputs from the IMR functions and test against it would be the way to go. The input would be Sv with potentially irregular spacing in ping time and depth across channels, and output would be Sv gridded to the same ping time and depth grid across all channels.

@anantmittal
Copy link
Contributor

Explore mock_Sv_dataset_irregular and mock_Sv_dataset_regular fixture in echopype/tests/commongrid/conftest.py

@anantmittal
Copy link
Contributor

anantmittal commented Nov 22, 2023

@leewujung How should we decide the spacing in ping time for regridding?

@anantmittal
Copy link
Contributor

@leewujung How should we decide the spacing in ping time for regridding?

Assuming the regrid function takes ds_Sv, range_bin, and ping_time_bin as arguments.

@leewujung
Copy link
Member Author

@anantmittal : Not sure if I understand the question, but I think in terms of uses, it may be the most useful if users specify ds_Sv, range_wanted, ping_time_wanted as input arguments, and get ds_Sv_out with range_wanted and/or ping_time_wanted as the coordinates across all channels.

One common use case is when different channels have different sizes along the range_sample dimension, and a user wants to align them all according to one of the channels. In that case, the call would look something like:

ds_Sv_out = ep.consolidate.regrid(
   ds_Sv = ds_Sv,
   range_wanted = ds_Sv["range"].isel(channel=0, ping_time=0)  # use range of the first ping in first channel
)

A couple notes:

  • The range values for all pings are very often the same but not always, since for EK echosounders it is something a user can change "on the fly."
  • In the the above case ping_time_wanted is not specified. It is pretty common to have all channels to ping on the same time base, but more recently the instruments are much more flexible so this may not be true. In that case, users may want to specify that also to get ds_Sv_out to align on both range_wanted and ping_time_wanted.

@leewujung leewujung modified the milestones: 0.8.1, 0.8.3 Nov 24, 2023
@anantmittal anantmittal mentioned this issue Dec 7, 2023
@anantmittal
Copy link
Contributor

In the the above case ping_time_wanted is not specified. It is pretty common to have all channels to ping on the same time base, but more recently the instruments are much more flexible so this may not be true. In that case, users may want to specify that also to get ds_Sv_out to align on both range_wanted and ping_time_wanted.

@leewujung: Could you explain this comment a bit more? It's unclear how regridding/interpolation should work when both range_wanted and ping_time_wanted are supplied to the regrid function.

#1241 is my stab at implementation when ping_time_wanted is None.

@leewujung
Copy link
Member Author

@anantmittal @lsetiawan : This following paragraph may be useful to understand the process? It also points to the specific approach they use and references in iris from this Sec. 2.2.2 in this paper.

Screenshot 2023-12-16 at 8 41 34 AM

@lsetiawan
Copy link
Member

xESMF Regrid Methods explanations: http://earthsystemmodeling.org/regrid/#regridding-methods

Actual algorithms in the xESMF Python library: https://xesmf.readthedocs.io/en/latest/notebooks/Compare_algorithms.html

Tutorial on xarray regridding with xESMF: https://xesmf.readthedocs.io/en/latest/notebooks/Dataset.html

@leewujung leewujung removed this from the 0.8.3 milestone Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

3 participants