Open matt-h2o opened 3 months ago
When I run the process and go into the individual components of hte xarray, I can see that latitude is expressed as +/- 90, but longitude is expressed as 0 to 359.75. I need to check if the data for longitudes <180 correspond in the normal way - if so then presumably i can reindex the longitudes > 180
This code fixes the longitudes:
def recalculate_longitude(longitude):
return (longitude + 180) % 360 - 180
dWthrVars = dWthrVars.assign_coords(longitude=recalculate_longitude(dWthrVars.longitude))
dWthrVars = dWthrVars.sortby('longitude')
I think that should be (longitude + 360) % 360
.
Running this:
def recalculate_longitude(longitude):
return (longitude + 180) % 360 - 180
def recalculate_longitude_v2(longitude):
return (longitude + 360) % 360
longitude = -90
print(recalculate_longitude(longitude))
print(recalculate_longitude_v2(longitude))
I get:
-90
270
And I think you want the second one. Is that right?
You might be interested in a new capability I've slowly been working on to extract data at a point. This is in the current main branch, but hasn't been released yet. When I get a chance I'd like to try it out for your case and see if it works, unless you beat me to it
https://herbie.readthedocs.io/en/latest/user_guide/_tutorial_notebooks/pick_points.html
@williamhobbs Thanks Will.
The issue is actually that the longitude dimension as downloaded is only expressed as positive numbers from 0 to 360. So if I try to get the weather variables for Lisbon, at longitude -9, I end up with the variables for somewhere near Valencia, at longitude 0 as the nearest number to a negative value. So my code snipped is intended to turn 270 to -90 so that negative longitudes map correctly.
@blaylockbk Thanks Brian - I came across that but hadn't quite figured out how to use it. I'm now getting a 404 so I imagine you might be updating it! Will come back later and take another look.
@matt-h2o That makes sense - I ran into a similar issue with GEFS, where I was targeting longitudes in the range of -85 to -90 deg E (e.g., Atlanta, GA, USA).
But I ended up with a different conversion. For example, if I use your function:
def recalculate_longitude(longitude):
return (longitude + 180) % 360 - 180
and input -9 (for Lisbon):
longitude = -9
print(recalculate_longitude(longitude))
I get this output:
-9
Alternatively, if you use this as a conversion function:
def recalculate_longitude_v2(longitude):
return (longitude + 360) % 360
and input -9:
longitude = -9
print(recalculate_longitude_v2(longitude))
you get:
351
which I think is what you want.
@williamhobbs Thanks. I've come at this the other direction - I've converted the longitude index in my xarray so that 351 is now -9, and then queried that index for the value at -9. I'd guess we'd end up with the same answer?
Ah! Yes, I was thinking about it in the reverse. I'm converting -9 (conventional coordinates) to 351 (GEFS coordinates) and you are converting 351 (GEFS) to -9 (conventional). We do get the same answers.
Apologies for the confusion, but I guess it's all extra clear now 😉.
Hi - I've been having issues using FastHerbie with GEFS and extracting data for specific locations. Nearest Point fails, so I've just been using .sel method='nearest', which seems to work so long as the longitude isn't negative - for locations in the western hemisphere (Madrid and Lisbon in the example below), it just gives me a longitude of 0. The code seems to work fine otherwise. Any thoughts on what might be going wrong?
thanks! Matt