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

Zonal or area averaging w/o rasterizing #9

Open
adamkemberling opened this issue Aug 1, 2024 · 2 comments
Open

Zonal or area averaging w/o rasterizing #9

adamkemberling opened this issue Aug 1, 2024 · 2 comments

Comments

@adamkemberling
Copy link
Collaborator

The functionality of getting a regional average might exist in the package already, and/or be accomplishable via rasterizing then using crop.

But for the sake of consistency with the team producing FVCOM, this is the suggested methodology I received from Dr. Wang via email correspondence on the topic:

Regarding the calculation of the regional mean using FVCOM results, the area of each triangle needs to be considered because the resolution is different spatially. For example, here is the process to calculate the regional mean bottom temperature for the GOM3 domain:

  1. Interpolate the bottom temperature from node to cell (the function "f_interp_node2cell.m" in matFVCOM toolbox).
  2. Calculate the area of each triangle (the function "calc_area.m" in matFVCOM toolbox).
  3. Compute the sum of the product of temperature and area for all the triangles and divide it by the total area of GOM3 domain. This gives the regional mean bottom temperature for the GOM3 domain.

For calculating the vertical mean, the function "f_mean_column.m" in matFVCOM can do that.

This is the matFVCOM toolbox mentioned:
https://github.com/SiqiLiOcean/matFVCOM

@adamkemberling
Copy link
Collaborator Author

This one feels like a combination of: using sf::st_intersection() to clip the mesh to an area we want the zonal summaries for. Then use sf::st_area() to get the size of each triangle (or remaining area of triangles that get clipped).

Then when assigning the values for each of the triangles' fills, it seems like they assign the average of the three node values to the location coordinates of "nele"

Somebody who knows matlab better than I should confirm, but line 22 from the link below looks like a simple average of the three values.
https://github.com/SiqiLiOcean/matFVCOM/blob/098ab42dba0c64663520da7501e6e99a237709ee/f_interp_node2cell.m

Then a weighted average would get you the mean across the whole area.

@btupper
Copy link
Member

btupper commented Aug 1, 2024

I think you are correct. They are just taking the mean of the three vertices' values. That's probably fine, and I agree that to aggregate multiple elements (facets?, triangles?) each should be weighted.

weighted_mean = (mean1/area1 + mean2/area2 + ...) * (area1 + area2 + ...)

or something like that.

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

No branches or pull requests

2 participants