Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds in a fix for single digit zones #30

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions snowex_db/interpretation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def convert_cardinal_to_degree(cardinal):

def manage_utm_zone(info):
"""
Maanage the nuance of having a utm zone string sometimes and
Manage the nuance of having a utm zone string sometimes and
then not being in the keys at all. If the utm_zone is in the
dictionary then convert it to an integer. Otherwise add with
assign None
Expand All @@ -177,7 +177,7 @@ def manage_utm_zone(info):
"""
if 'utm_zone' in info.keys():
info['utm_zone'] = int(''.join([c for c in info['utm_zone'] if c.isnumeric()]))
info['epsg'] = int(f"269{info['utm_zone']}")
info['epsg'] = int(f"269{info['utm_zone']:02}")
elif 'epsg' in info.keys():
if info['epsg'] is not None:
info['utm_zone'] = int(str(info['epsg'])[-2:])
Expand Down
2 changes: 1 addition & 1 deletion snowex_db/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def reproject_point_in_dict(info, is_northern=True, zone_number=None):
# Assuming NAD83, add epsg code
if 'utm_zone' in result.keys():
if result['utm_zone'] is not None:
result['epsg'] = int(f"269{result['utm_zone']}")
result['epsg'] = int(f"269{result['utm_zone']:02}")
else:
result['utm_zone'] = None
result['epsg'] = None
Expand Down
15 changes: 10 additions & 5 deletions tests/test_interpretation.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,17 @@ def test_get_InSar_flight_comment(data_name, expected):
assert comment == expected


@pytest.mark.parametrize("info, expected_zone", [
@pytest.mark.parametrize("info, key, expected_zone", [
# Test a string zone is used
({'utm_zone': '12N'}, 12),
({'utm_zone': '12N'}, 'utm_zone', 12),
# Test utm_zone not provided
({}, None),
({}, 'utm_zone', None),
# Test single/double digit zones
({'utm_zone': '6'}, 'epsg', 26906),
({'utm_zone': '11'}, 'epsg', 26911),

])
def test_manage_utm_zone(info, expected_zone):
def test_manage_utm_zone(info, key, expected_zone):
result = manage_utm_zone(info)
assert result['utm_zone'] == expected_zone
assert result[key] == expected_zone

4 changes: 3 additions & 1 deletion tests/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# Confirm we force the zone to zone 12
({'latitude': 39.097464, 'longitude': -107.862476}, 12,
{'northing': 4332280.1658, 'easting': 771338.607, "utm_zone": 12}),
# Test Missing missing longitude
# Test missing longitude
({"utm_zone": "10N", "easting": "757215", "northing": "4288778", "latitude": "38.71025", "longitude": ""}, None,
{"utm_zone": 10, "easting": 757215.0, "northing": 4288778.0, "latitude": 38.71025, "longitude": -120.041884,
'epsg': 26910}, ),
Expand All @@ -34,6 +34,8 @@
{"utm_zone": 10, "latitude": 38.71025, "longitude": -120.041884, 'epsg': 26910},),
# Test moving past when nothing is provided
({}, None, {"utm_zone": None, 'epsg': None},),
# Test single digit zones.
({'easting': 465058.37445, 'northing': 7193480.256156, 'utm_zone': 6}, None, {'epsg':26906})
])
def test_reproject_point_in_dict(info, utm_zone, expected):
"""
Expand Down
Loading