# Shifting longitude domain from [-280, 80] to [0, 360]

Now sure where should I post this, technical or COSIMA?

I am looking for this code, but couldn’t find in the cookbook.

ContributedExamples/u_seasonal_cycle_ind_eq.ipynb

I guess this is the one for Kiss’ paper Figure 26

Cheers,

Arnold

Hi @ars599. I’m curious why you think that recipe should exist? You’re right that it’s not in the cosima-recipes repo.

It was moved to the sandbox quite a while ago, and then probably deleted at some point. Here’s a relevant commit in the history: Add plots of the seasonal cycle of SST (or temperature at any depth) · COSIMA/cosima-recipes@7710687 · GitHub

Note this is 3 years ago, so very likely things don’t work properly…

I chucked this string into GitHub search and came up with this

I assume that all of Kiss’s plots have corresponding scripts for users to follow. My question is what is the replacement function for “shiftgrid” from the “Basemap” module. Or, how can I shift the longitude from -280 to 80 to 0 to 360? So far I got this from AI, I will give a try:

``````import numpy as np

# assume your data is stored in a variable called 'data'
# assume your longitude coordinates are stored in a variable called 'lon'

# shift the longitudes from -280 to 80 to 0 to 360
lon_shifted = np.roll(lon, len(lon)//2)

# make sure the longitude values are between 0 and 360
lon_shifted[lon_shifted<0] += 360
``````

Something like the following should do the trick:

``````lon_shifted = (lon + 360)  % 360
``````

Or if you’re using xarray objects and want to update the “lon” coordinate:

``````ds = ds.assign_coords({"lon": (ds["lon"] + 360)  % 360})
``````
2 Likes

If you are sure it was in the `cosima-recipes` at some point then you can always go back in the commit history and find everything. Github saves all the history of everything.

But, as others have already commented, if it was deleted there was a reason. Probably because it was not working any more…

Btw, `basemap` is also out of business – nobody is maintaining it. So we converted all our examples to use the current Cartopy.

AI gave you this piece of code with comments?

I’m gonna tell AI to go through all the scripts in the `cosima-recipes` and submit PRs…

If @dougiesquire’s solution works for you @ars599 can you mark it as the one resolving the discussion? Also, should we rename the topic of this discussion to “Shifting longitude domain from [-280, 80] to [0, 360]”? I presume others will have this question – I know I had it at the past.

Yes, I understand. Previously, I thought the solution was working, but it turned out that it didn’t. That’s why I posted again. The second post contains the correct solution.

ok, I didn’t follow the discussion… I just saw two post that seem related

so from what I understand the other post has the solution. I’m archiving this one.