I am currently working with AIS dataset containing fields MMSI, Timestamp, LAT, LON, SOG, COG, etc. Here, COG is course over ground, and supported COG value ranges from 0 to 360 degrees. But the dataset contains negative values in some rows. I like to know is there any formula or rule to convert it into 0-360. Since I am working with python, if someone knows how to do it in Python would be appreciated but any formula could work. For convenience, I have attached a screenshot of a sample dataset.
Asked
Active
Viewed 324 times
2

faring
- 105
- 1
- 10
2 Answers
2
To convert an angle to between 0 and 360, find the modulus of dividing by 360:
df["COG_0_to_360"] = df["COG"]%360
examples:
-10%360 == 350
10%360 == 10

Tom McLean
- 5,583
- 1
- 11
- 36
-
2@faring I also just accepted a job offer for a company who track AIS data :) – Tom McLean Jul 09 '21 at 15:13
-
1Congrats @Tom McLean – faring Jul 09 '21 at 15:15
1
Here is my final code:
def COG_0_To_360(cog):
cog = np.fmod(cog, 360.0)
cog = np.where(cog < 0.0, cog + 360.0, cog)
return np.abs(cog)
df['COG'] = COG_0_To_360(df['COG'])
Example:
values = [-170, -10, -390, -355, 250, -440]
print(COG_0_To_360(values))
[190 350 330 5 250 280]

faring
- 105
- 1
- 10