Skip to content

Commit

Permalink
Refactor from pair-programming session
Browse files Browse the repository at this point in the history
  • Loading branch information
dcamron committed Jun 25, 2024
1 parent d077b1e commit 51cf86a
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/metpy/io/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,23 @@ def _decode_coords(coordinates):
(-119.3, 47.3)
"""
# Based on the number of digits, find the correct place to split between lat and lon
# Hires bulletins provide 7 digits for coordinates; regular bulletins provide 4 or 5 digits
# Define latitude orientation
flip = 1

if coordinates[0] == '-':
coordinates = coordinates[1:]
split_pos = int(len(coordinates) / 2)
lat, lon = coordinates[:split_pos], coordinates[split_pos:]

# Insert decimal point at the correct place and convert to float
lat = -float(f'{lat[:2]}.{lat[2:]}')
lon = -float(f'{lon[:3]}.{lon[3:]}')
return lon, lat

if coordinates[0] != '-':
split_pos = int(len(coordinates) / 2)
lat, lon = coordinates[:split_pos], coordinates[split_pos:]

# Insert decimal point at the correct place and convert to float
lat = float(f'{lat[:2]}.{lat[2:]}')
lon = -float(f'{lon[:3]}.{lon[3:]}')
return lon, lat
# Flip latitude to Southern Hemisphere
flip = -1

# Based on the number of digits, find the correct place to split between lat and lon
# Hires bulletins provide 7 digits for coordinates; regular bulletins provide 4 or 5 digits
split_pos = int(len(coordinates) / 2)
lat, lon = coordinates[:split_pos], coordinates[split_pos:]

# Insert decimal point at the correct place and convert to float
lat = float(f'{lat[:2]}.{lat[2:]}') * flip
lon = -float(f'{lon[:3]}.{lon[3:]}')
return lon, lat


def _regroup_lines(iterable):
Expand Down

0 comments on commit 51cf86a

Please sign in to comment.