-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conservative regridding of DataArray, N+1 dim issue #14
Comments
You can use either numpy arrays or |
Thank you that is working now using a Dataset. However, I am getting the below ESMF_REGRID error (in PET0.ESMF_LogFile) when using the conservative option to regrid some GFDL output on a tri-polar grid to a stereo projection over the north pole. The bilinear options works fine. I have double checked the lat_b and lon_b, and they look right. Have you run into this ESMF error before? Or have any suggestions on what to try? (I will try to set up a repeatable example shortly).
|
No I haven't encountered this error before. Is the "tri-polar grid" still quadrilateral? |
Also, are you using GFDL ocean models? I thought all GFDL atmospheric models use the cubedsphere grid... |
Yes, I am looking at sea ice output (grid info: http://nomads.gfdl.noaa.gov/CM2.X/oceangrid.html) and the grid is quadrilateral. |
OK I've seen FIG. 7 in Murray (1996) and know how the grid looks like. Maybe ESMF doesn't like the 2 singularities in the bipolar grid. Does the error still exist if you discard the 2 singularities? Say, subset the coordinate by |
Ok, I think your are right, the conservative option works when I try to remove the singularities. Here is a reproducible snippet: https://github.com/NicWayand/regrid_test/blob/master/Test_Conservative_Regridding.ipynb `` |
Glad that it works. The singularities are on the land so they should be masked anyway and shouldn't affect your results? Closing this issue. Feel free to reopen if any bug occurs. |
Well, when I remove the top row to remove the singularity points it removes the whole row, so there is a gap across the "seam" between the two poles, which is not good. I don't know of a way to just remove the singularities. Reading a bit in the ESMF documentation, it should be able to handle the singularities at poles, but maybe an option needs to be specified? |
Shouldn't only the leftmost/rightmost "row" is removed, which is almost as small as a single cell? Taken from Figure 4.6 in the technical guide: Also, in your code you seem to crop
I believe the "polar singularity" there means the longitude can be periodic. It knows to connect -180 and 180. But if the longitude actually has the same value along the entire row then ESMF will get confused. |
The actual grid I have is a combination of the regular grid (below 65N) and the bipolar grid (as pictured in Fig 4.6). Below is the ds_in grid. Red is the full grid. Blue dots are the top row removed. Yes my slicing was too big for both datasets. I have updated the code to show just slicing the top "row" of ds_in. I actually don't understand why I need to slice the stereo projected ds_target. If there are no input cells over the singularities/poles, I would expect xesmf to map missing to the new grid at those locations (or otherwise handle it fine). However, it only works when I remove the surrounding "edge" cells... which is strange. I checked the the longitudes are not the same, so should "wrap" fine. |
Ah I see! Although your grid has multiple "tiles", it is stored as a single 2D numpy array! I was thinking about cubedsphere-like layout that multiple tiles are stored separately as multiple arrays. Then it is totally expected that ESMF will fail with the two singularities, as they are singularities in the middle of the array that will screw up the grid searching. On the other hand, singularities at corners (like the normal polar singularity) should be fine. If you break your grid into two separate arrays, one for the bipolar tile and one for the normal lat-lon grid, I believe the conservative regridding will work just fine. If the error still occurs, you can just remove one row in the bi-polar tile. The removed cells will be localized near the singularities and will not span over a long line. If you slice the original 2-tile grid, the normal lat-lon tile will be affected. |
Thanks for the suggestion! Upon splitting up the grid I realized I incorrectly made my lat_b and lon_b, which may be the underlying issue. The problem is I start with bounds per grid cell (i.e. lat_corners = (Ngrids, 4 corners) and need to convert it to the N+1 format xesmf requires. I thought this step would be trivial but its hard to generalize as each of my different input/target grids have different assumptions about the orientation of the "4 corners". Is there any way to pass in the (Ngrids, 4 corners) format of bounds to xesmf by chance? |
This would be very tricky. I know that the CF convention uses
To be safe, I would suggest calculating
As you said, there are many possible orientations, so the bound indices I use here ( |
Thanks @JiaweiZhuang, I hope xgcm will handle this conversion in the future! That is the way I am calculating it now. With correct bounds, the conservative option IS running on the bipolar grid... but its not handeling the seam between the two poles correctly (values of sea ice concentration range from 0 to 1, but its setting cells within this seam to values > 1 for some reason. Maybe this is related to #15? Bilinear also has issues in the "seam" Nearest source to destination works as I expected it to: https://github.com/NicWayand/regrid_test/blob/master/Test_Tri_Poler_Regridding.ipynb |
Hmm this is weird... Do you have the |
Also the tile you are regridding is the bipolar grid? Then you should set |
Sorry, I uploaded the required nc files and the esio.py module. Everything should be there to run https://github.com/NicWayand/regrid_test/blob/master/Test_Tri_Poler_Regridding.ipynb now. But let me know if something is missing. Hmm the GFDL model is global, I am just regridding to the north pole region, so I thought because the longitude wraps around the earth it is periodic? Regardless, you get missing "seams" when Thanks for your help! |
I've fixed your problem in this notebook (really took me a while!): https://github.com/JiaweiZhuang/regrid_test/blob/master/debug_bipolar_grid.ipynb The problem is your source grid is not a legal, single-tile quadrilateral grid. First, the polar tile had better be extracted out. Second, the polar tile itself has a buggy layout -- the numpy array contains 2 disconnected parts. By rearranging the two part correctly there is no missing "seam" any more. My notebook has detailed explanations. In general, the grid object fed to |
Thank you so much @JiaweiZhuang!! That is a strange way to lay out the grid, there most be some computational reason why it was so. I was able to use the same method on the lat/lon bounds and got the conservative regridding working as expected, so closing this issue. |
Add ESMPy v8 to requirements, fixes JiaweiZhuang#13
Is there a temporary workaround to regridding DataArrays using the conservative method that avoids the issue raised here (pydata/xarray#1475) of DataArrays not being able to store N+1 lat_b/lon_b variables? Drop down to numpy arrays?
The text was updated successfully, but these errors were encountered: