Closed juntyr closed 2 weeks ago
I investigated some more, and here is the main culprit:
No matter what, an axis of an xarray shouldn't just be changed here.
If I patch the method to be
@property
def x_values(self):
super().x_values
return self.data[self._x].values
instead, it works fine.
If using the contourf
maps plot, a white line on the prime meridian appears. https://stackoverflow.com/a/56348755 seems to have a solution for that, but this would need to be fixed deep in the plotting code, and I don't have further time to investigate right now. I'll just submit a PR for the first issue.
What happened?
I am plotting a temperature field. Before calling the
earthkit.plots.quickmap.plot
function, the longitude of the data ranges from 0 to 360. After plotting, the xarray.DataArray's own longitude has changed (!) to -180 to 180, and the plot itself is wrong, with the map lines and axis labels using the -180 to 180 range, but the data still assuming that everything is in 0 to 360 (e.g. South America's temperatures are plotted on the map lines of Australia).What are the steps to reproduce the bug?
I think this issue relates to xarray's indices being mutable: https://github.com/pydata/xarray/issues/7463. Somewhere in the plotting, I assume there is some code to standardize the longitude to the -180 to 180 range, which assumes it's operating on a copy of the data. However, it is able to mutate the actual longitude index. When later code checks, it sees that the longitude index is correct (even though the temperature data has not been shifted yet), and so doesn't do anything else. As a result, after plotting, the plot is wrong and the data array has been changed.
Version
0.2.3
Platform (OS and architecture)
Emscripten WebAssembly (lab.climet.eu)
Relevant log output
No response
Accompanying data
https://a3s.fi/compression.lab.climet.eu/era5_t2m_2012_12_01_14:00.nc
Organisation
University of Helsinki