From ad856db55fdd0b2df9be04e518beb92cba74da8a Mon Sep 17 00:00:00 2001 From: jonnymaserati Date: Sat, 6 Jan 2024 17:26:56 +0100 Subject: [PATCH] Finessed the utils.decimal2dms a bit more. --- ...ror_mwdrev5_iscwsa_validation_results.xlsx | Bin 21244 -> 21244 bytes tests/test_utils.py | 11 +++++++++-- welleng/utils.py | 11 ++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/test_data/error_mwdrev5_iscwsa_validation_results.xlsx b/tests/test_data/error_mwdrev5_iscwsa_validation_results.xlsx index 4e134980b19c0ad526d4de01ba6445c9799023af..678c7adcb1d4f2afd96ee9c2ff258ca2c34c14f4 100644 GIT binary patch delta 410 zcmeyfl=06}MxFp~W)=|!1_lm>rEL>=)^aRuQ;Rq;;g83}gYxyh{)Y{C+Ww!KQvG^M z>g0}HaSqnJoSmKud4Z2|ug>CEb$k2IHuI*Hz#WTY?;juE7No5|h5LuhoZ}9<$Brgg zNwro$q_9d^O7gSI4Uu=T29qus%N+17oy6WU>9eSW%1TvFiPo9(d*3X&k`?x= z|AH^mS_W&A3{9tr;swc^_0662WYn2mu)^c2{RErRdQwW-PP`>`4-(druw)oUndrL1* zm0hGKE}%YP!VH#2VwU&BE^Y}-y7KO==jm&W589@9|Ed4?MuWGivv$Gq3)NgXn(N%I zmjy1mpXQ#X&!{AK@@0g|BJYR$`2C7^wJ}%pzW?PAF!d>$%to_Wrap)6=pTEt#$<=a zU-yjkM#lxyWJ+ZmMVQv<)CU)QJl|#+dBX5kt5n-UiEGBw&4fPu`tiX=fBtQ~P46Zc zU6q(3;ZZDq<%?3i)NQtXqO(80SYxuGe=o~jbZaWMl&|1Yn7YDID#EP zbhhUOCLlf8*5^5htL7Wc2;w&TJqB?z{C&XOZ2>m$P@McLz#OE+IM5zMl?1wgs9k}U WAnI!%SWYj<8pO*EasyGDgFFG*Rke%& diff --git a/tests/test_utils.py b/tests/test_utils.py index 61d1e8e..24f981e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,3 @@ -import inspect -import sys import unittest import numpy as np @@ -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]) diff --git a/welleng/utils.py b/welleng/utils.py index 3800faa..9f966ba 100644 --- a/welleng/utils.py +++ b/welleng/utils.py @@ -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: