From 51cf86a0f25ab5403cb3297e453f7ced08e1fb18 Mon Sep 17 00:00:00 2001 From: Drew Camron Date: Tue, 25 Jun 2024 14:08:41 -0600 Subject: [PATCH] Refactor from pair-programming session --- src/metpy/io/text.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/metpy/io/text.py b/src/metpy/io/text.py index 4a379e3cf0..a922f34cbd 100644 --- a/src/metpy/io/text.py +++ b/src/metpy/io/text.py @@ -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):