Skip to content

Commit

Permalink
Finessed the utils.decimal2dms a bit more.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnymaserati committed Jan 6, 2024
1 parent a508c70 commit ad856db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Binary file modified tests/test_data/error_mwdrev5_iscwsa_validation_results.xlsx
Binary file not shown.
11 changes: 9 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import inspect
import sys
import unittest

import numpy as np
Expand Down Expand Up @@ -78,6 +76,15 @@ def test_decimal2dms(self):
np.array((np.array(LAT[:3]), np.array(LON[:3])))
))

dms = decimal2dms(np.array([
(LAT[0] + LAT[1] / 60 + LAT[2] / 3600),
(LON[0] + LON[1] / 60 + LON[2] / 3600)
]), ndigits=4)
assert np.all(np.equal(
dms,
np.array((np.array(LAT[:3]), np.array(LON[:3])))
))

dms = decimal2dms(np.array([
(LAT[0] + LAT[1] / 60 + LAT[2] / 3600, LAT[3]),
(LON[0] + LON[1] / 60 + LON[2] / 3600, LON[3])
Expand Down
11 changes: 8 additions & 3 deletions welleng/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,15 +710,20 @@ def decimal2dms(decimal: tuple | NDArray, ndigits: int = None) -> tuple | NDArra
[[52 4 43.1868 'N']
[4 17 19.6368 'E']]
"""
flag = False
_decimal = np.array(decimal)
if _decimal.dtype == np.float64:
_decimal = _decimal.reshape((-1, 1))
flag = True
try:
dms = np.apply_along_axis(_decimal2dms, -1, decimal, ndigits)
dms = np.apply_along_axis(_decimal2dms, -1, _decimal, ndigits)
except np.exceptions.AxisError:
dms = _decimal2dms(decimal, ndigits)
dms = _decimal2dms(_decimal, ndigits)

if dms.shape == (4,):
return tuple(dms)
else:
return dms
return dms.reshape((-1, 3)) if flag else dms


def _dms2decimal(dms: NDArray, ndigits: int = None) -> NDArray:
Expand Down

0 comments on commit ad856db

Please sign in to comment.