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

**URL:** <https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642>\
**Category:** Ocean\
**Tags:** python, longitude\
**Created:** [30 March 2023 06:26 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642 "2023-03-30T06:26:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ars599](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/ars599/32/821_2.png) [@ars599](https://forum.access-hive.org.au/u/ars599)\
**Post date:** [30 March 2023 06:26 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/1 "2023-03-30T06:26:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dougiesquire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/dougiesquire/32/16_2.png) [@dougiesquire](https://forum.access-hive.org.au/u/dougiesquire)\
**Post date:** [30 March 2023 10:30 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/2 "2023-03-30T10:30:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![angus-g](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/angus-g/32/89_2.png) [@angus-g](https://forum.access-hive.org.au/u/angus-g)\
**Post date:** [30 March 2023 22:44 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/3 "2023-03-30T22:44:21Z")

</div>

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](https://github.com/COSIMA/cosima-recipes/commit/7710687c8157d987028974ebac70e3455d5cd880)

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

---

<div class="post-metadata">

**Author:** ![Aidan](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/aidan/32/42_2.png) [@Aidan](https://forum.access-hive.org.au/u/Aidan)\
**Post date:** [30 March 2023 22:45 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/4 "2023-03-30T22:45:23Z")

</div>

> [@ars599](#):
>
> u\_seasonal\_cycle\_ind\_eq.ipynb

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

> <https://github.com/COSIMA/cosima-recipes/commit/7710687c8157d987028974ebac70e3455d5cd880>
>
> and zonal velocity compared to WOA13 and the global drifter data set
> along the E…quator in the Pacific.
> 
> This replaces the functionality in previous scripts:
> seasonal\_cycle\_eq.ipynb
> and
> u\_seasonal\_cycle\_ind\_eq.ipynb
> 
> Although the later has been moved to sandbox since it contains plots
> of the Indian ocean rather than the Equatorial Pacific (however, this
> new script can eassily be adapted to do this plot).

---

<div class="post-metadata">

**Author:** ![ars599](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/ars599/32/821_2.png) [@ars599](https://forum.access-hive.org.au/u/ars599)\
**Post date:** [30 March 2023 23:43 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/5 "2023-03-30T23:43:20Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![dougiesquire](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/dougiesquire/32/16_2.png) [@dougiesquire](https://forum.access-hive.org.au/u/dougiesquire)\
**Post date:** [31 March 2023 02:00 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/6 "2023-03-31T02:00:16Z")

</div>

Something like the following should do the trick:

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

```

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

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

```

---

<div class="post-metadata">

**Author:** ![navidcy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/navidcy/32/101_2.png) [@navidcy](https://forum.access-hive.org.au/u/navidcy)\
**Post date:** [31 March 2023 09:10 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/7 "2023-03-31T09:10:34Z")

</div>

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](https://matplotlib.org/basemap/index.html) – nobody is maintaining it. So we converted all our examples to use the current Cartopy.

---

<div class="post-metadata">

**Author:** ![navidcy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/navidcy/32/101_2.png) [@navidcy](https://forum.access-hive.org.au/u/navidcy)\
**Post date:** [31 March 2023 09:13 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/8 "2023-03-31T09:13:25Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![navidcy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/navidcy/32/101_2.png) [@navidcy](https://forum.access-hive.org.au/u/navidcy)\
**Post date:** [31 March 2023 09:16 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/9 "2023-03-31T09:16:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navidcy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/navidcy/32/101_2.png) [@navidcy](https://forum.access-hive.org.au/u/navidcy)\
**Post date:** [19 June 2023 22:59 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/10 "2023-06-19T22:59:58Z")

</div>

perhaps this is related: [Selecting the Indian Ocean region (which includes the seam) from ACCESS-OM ocean model output - #3 by ars599](https://forum.access-hive.org.au/t/selecting-the-indian-ocean-region-which-includes-the-seam-from-access-om-ocean-model-output/809/3)

---

<div class="post-metadata">

**Author:** ![ars599](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/ars599/32/821_2.png) [@ars599](https://forum.access-hive.org.au/u/ars599)\
**Post date:** [20 June 2023 07:44 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/11 "2023-06-20T07:44:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navidcy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/navidcy/32/101_2.png) [@navidcy](https://forum.access-hive.org.au/u/navidcy)\
**Post date:** [20 June 2023 07:55 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/12 "2023-06-20T07:55:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![navidcy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/navidcy/32/101_2.png) [@navidcy](https://forum.access-hive.org.au/u/navidcy)\
**Post date:** [20 June 2023 08:03 UTC](https://forum.access-hive.org.au/t/shifting-longitude-domain-from-280-80-to-0-360/642/13 "2023-06-20T08:03:54Z")

</div>


