I have a NetCDF file (gridded data) with a landsea mask. I would like to determine, for the coastal grid-cells, what the orientation of the coastline is. I need to do this in order to calculate the angle between incident wind direction and the coastline at each coastal grid cell.

For example, if at a certain location the coastline is zonal (east to west) and the land is to the south, and the sea to the north, the orientation would be 0°:

enter image description here

If the coast is zonal but the position of land and ocean are inverted, the orientation of the coast would be 180°.

enter image description here

If the coast is 45° with the land to the south, the angle is 45°. With the land to the north, the orientation is 135°... you get the idea.

enter image description here enter image description here

Any suggestions on how to get this information from the landsea mask grid?

Thank you in advance.

  • 3
    $\begingroup$ Gridded data is orthogonal by definition, so you either have 0/180° or 90/270°. $\endgroup$ – Erik Jul 12 '19 at 7:35
  • $\begingroup$ There are sometimes curvilinear grids, like those with 3 poles or 2 poles and one over Greenland. $\endgroup$ – ouranos May 14 '20 at 7:13
  • $\begingroup$ Perhaps it may be best to take like a regional linear average of the coast and then calculate as Baroclinic suggested? Perhaps use a running mean over a handful of data points. But of course that means transferring to something "vector" instead of "raster"? I don't know, thinking out loud, I was considering this challenge a bit years ago for hurricanes, but never got to it. $\endgroup$ – JeopardyTempest Jun 9 at 4:08

It should be noted that NetCDF data just describes the format that the data is in. One dataset that I know of (IBTrACS) contains data that is not gridded data, and also contains a landmask. But this is besides your question.

To rephrase your question: How can I determine the orientation of the coastline in a gridded dataset?

Well, one way is using mathematics. Let's call the boolean landmask variable $L$, where $L=\{^{0 \text{ if land}}_{1\text{ if water}}$ Then the gradient is $$\nabla L =\{^{<\frac{\delta L}{\delta x},\frac{\delta L}{\delta y}> \text{ at the coastline}}_{\vec{0} \text{ not at the coastline}}$$ Let's look at just the coastline. The angle is $\arctan2(\frac{\delta L}{\delta x},\frac{\delta L}{\delta y})$.

Now if you want to find out the angle difference between the coast and the wind, then you can use the properties of the dot product to find the angle difference. That is $$\delta \phi=\arccos\left(\frac{\nabla L \cdot \vec{v}}{|\nabla L||\vec{v}|}\right)=\arccos\left(\frac{u\frac{\delta L}{\delta x}+v\frac{\delta L}{\delta y}}{\sqrt{u^2+v^2}\sqrt{\left(\frac{\delta L}{\delta x}\right)^2+\left(\frac{\delta L}{\delta y}\right)^2}}\right)$$

  • $\begingroup$ Thank you for your answer. I really like your idea of doing the gradient of L. I must say though, that I find it awkward the part of your answer that reads "Well, one way is using mathematics." -- was this really necessary? It reads to me a bit like "Well, use your brain". As if "using mathematics" had not occurred to me. This is not encouraging for people to ask further questions. But thank you for the good answer again. $\endgroup$ – ouranos Jun 9 at 6:43
  • 1
    $\begingroup$ @ouranos I am 100 % sure that BaroclinicCplusplus meant nothing of the sort. He was not being condescending at all. "Well one way is using mathematics" is just an expression that says I am going to be using some Math to explain my answer. That's it. $\endgroup$ – gansub Jun 9 at 9:21
  • $\begingroup$ Thanks @gansub. Yes, I initially was going to say 'vector calculus', but at some point changed it to just 'mathematics' since there isn't actual calculus (the use of infinitesimals) involved. I'm fairly certain there are other ways to do it, not using strict mathematics. GIS may have one solution, for example. $\endgroup$ – BarocliniCplusplus Jun 9 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.