I want to change my longitude from -180 degrees to 180 deg format to 0-360 for an array. Is there a way to do this with out using loops or if statements?
lon_04_window = [ 1.39698386e-09 6.53551058e-02 1.30710210e-01 1.96065315e-01 2.61420419e-01 3.26775523e-01 3.92130628e-01 4.57485732e-01 5.22840836e-01 5.88195941e-01 6.53551045e-01 7.18906150e-01 7.84261254e-01 8.49616358e-01 9.14971463e-01 9.80326567e-01 1.04568167e+00 1.11103678e+00 1.17639188e+00 1.24174698e+00 1.30710209e+00 1.37245719e+00 1.43781230e+00 1.50316740e+00 1.56852251e+00 1.63387761e+00 1.69923272e+00 1.76458782e+00 1.82994292e+00 1.89529803e+00 1.96065313e+00 2.02600824e+00 2.09136334e+00 2.15671845e+00 2.22207355e+00 2.28742865e+00 2.35278376e+00 2.41813886e+00 2.48349397e+00 2.54884907e+00 2.61420418e+00 2.67955928e+00 2.74491439e+00 2.81026949e+00]
Loop Code:
for i in range(len(lon)):
if lon[i] < 0:
lon[i] = lon[i]+360
Assuming lon_04_window
is a numpy array AND that you want to go from [0,360] to [-180,180]:
((lon_04_window - 180) % 360) - 180
or
np.mod(lon_04_window - 180.0, 360.0) - 180.0
If you actually want to go from [-180,180] range to [0, 360] as stated in the OP:
lon_04_window % 360
If lon_04_window
is not a numpy
array, make it:
import numpy as np
lon_04_window = np.asarray(lon_04_window)
def rewrap(x):
return (x + 180) % 360 - 180
This can also be applied directly to NumPy arrays, not just scalars.
np.mod(lon_04_window, 360)
正常工作。
In PostgresSQL:
UPDATE table SET lon = lon -360 WHERE lon > 180 ;
If the 0 begins in Greenwich.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.