Unidata / thredds

THREDDS Data Server v4.6
https://www.unidata.ucar.edu/software/tds/v4.6/index.html
265 stars 179 forks source link

Constructing Gaussian latitude axis in GdsHorizCoordSys #627

Closed rschmunk closed 8 years ago

rschmunk commented 8 years ago

A Panoply user wrote to complain that a map plot of temperature data on a Gaussian grid was displayed inverted. I found that IDV also plotted the data upside down. In the dataset in question, the 880 latitude values are supposed to run from negative to positive, from -89.844 to 89.844.

Poking around in the NJ code to determine how the values of the latitude axis were being calculated, I found something a bit suspicious.

The method setGaussianLats in ucar.nc2.grib.GdsHorizCoordSys seems to be where the action is, and I do see that it is receiving parameters la1 -89.844, la2 89.844. The first pass at determining bestStartIndex and bestEndIndex values comes up with 879 and 0 respectively

Where things look flaky is the ensuing if statement.

if (Math.abs(bestEndIndex - bestStartIndex + 1) != nyRaw) {

In the case in question, where bestStartIndex > bestEndIndex, the inequality condition is going to be satisfied and in the ensuing if clause, bestStartIndex and bestEndIndex get flipped. In the loop after that, the values for the lat axis end up running from positive to negative.

So what I'm getting around to asking is, shouldn't the above if statement instead read

if (Math.abs(bestEndIndex - bestStartIndex) + 1 != nyRaw) {

I'm pretty unfamiliar with GRIB internals and Gaussian grids, so I'm checking here for confirmation on my suspicion rather than simply filing a pull request.

lesserwhirls commented 8 years ago

Hmmm...that does look suspicious. Would you happen to have a copy of that file that I could take a look at? I just want to make sure I am going to the correct parts of the correct GRIB spec to see what it says.

rschmunk commented 8 years ago

The particular file I was working with is at https://dl.dropboxusercontent.com/u/18229899/test.grb

rschmunk commented 8 years ago

Posted pull request #639 to fix this.

lesserwhirls commented 8 years ago

Hi @msdsoftware - I've scratched my head a bit, and I am leaning towards what you have done. Would it be ok if I used the test file you uploaded to write a test?

rschmunk commented 8 years ago

Sure. It's a test file that someone else passed on to me to demonstrate a problem, and he did label it "test". As long as it looks like valid GRIB to you, I'd say go for it.