@@ -74,21 +74,35 @@ of `X` with shift `l`. If `wrap = true` the longitudes are wrapped to (-180, 180
74
74
using the modulo operation.
75
75
76
76
If `l` is not given, it is as much as necessary so that all longitudes > 180 are
77
- wrapped.
77
+ circshifted (and also wrapped if `wrap`).
78
+
79
+ If `X` has a `CoordinateSpace`, then no circshift is happening (the lon-lat
80
+ are one dimension), but the longitude is still shifted.
78
81
"""
79
82
function longitude_circshift (X:: ClimArray , l = nothing ; wrap = true )
80
- if isnothing (l); l = count (≥ (180 ), dims (X, Lon). val); end
81
- isnothing (l) && return X
83
+ hasdim (X, Coord) && return longitude_circshift_coord (X, wrap)
84
+ if isnothing (l); l = count (≥ (180 ), dims (X, Lon)); end
85
+ l == 0 && return X
82
86
shifts = map (d -> d isa Lon ? l : 0 , dims (X))
83
87
shifted_data = circshift (X. data, shifts)
84
- shifted_lon = circshift (dims (X, Lon). val , l)
88
+ shifted_lon = circshift (gnv ( dims (X, Lon)) , l)
85
89
if wrap; shifted_lon = wrap_lon .(shifted_lon); end
86
90
shifted_lon = vector2range (shifted_lon)
87
91
shifted_dim = Lon (shifted_lon; metadata = DimensionalData. metadata (dims (X, Lon)))
88
92
new_dims = map (d -> d isa Lon ? shifted_dim : d, dims (X))
89
93
return ClimArray (shifted_data, new_dims; name = X. name, attrib = X. attrib)
90
94
end
91
95
96
+ # this is just longitude wrapping
97
+ function longitude_circshift_coord (X, wrap = true )
98
+ ! wrap && return X
99
+ coords = dims (X, Coord)
100
+ lons = getindex .(coords, 1 )
101
+ wlons = wrap_lon .(lons)
102
+ newcoords = [SVector (wlons[i], coords[i][2 ]) for i in eachindex (coords)]
103
+ return DimensionalData. set (X, Coord => newcoords)
104
+ end
105
+
92
106
# ########################################################################
93
107
# averaging functions over space or time
94
108
# ########################################################################
0 commit comments