Skip to content

Latest commit

 

History

History
116 lines (90 loc) · 4.48 KB

ISSUE_TEMPLATE.md

File metadata and controls

116 lines (90 loc) · 4.48 KB

Skip the second and minutes assertion errors

I have got a 238 EDI-files last month ago and some second and minutes end up to 60. An error raises everytimes the value equals to 60. To skip this asserion error, I suggest to restart counting. For instance 12:25min:60s ==> 12:26min:00s since it is difficult for users to everytimes convert value manually himself.

Expected Behavior

Skip assertion error and do it automatically

Current Behavior

Possible Solution

restart the counting to avoid multiples Assertion Error especially when we have many sites to process.

Steps to Reproduce (for bugs)

  1. write a helpers functions _restart_count
  2. insert function in function convert_position_str2float
# Paste your code here

def _restart_count(deg_or_min, value):
    """ restart the countdown and skip error if seconds or minutes are equal to 60. 
    
    Commonly seconds and minutes should not end by 60. However, some EDI-files rewritten by some hardwares
    end up minutes and second with 60. To avoid the  AssertionError at everytimes the mtobj is created,
    the second and minutes should restart automatically.   
    """
    return ( deg_or_min + value//60, value%60 )  if float (value) >=60. else (
        deg_or_min, value )  

def convert_position_str2float(position_str):
    """
    Convert a position string in the format of DD:MM:SS to decimal degrees

    :type position_str: string [ 'DD:MM:SS.ms' | 'DD.degrees' ]
    :param position_str: degrees of latitude or longitude

    :rtype: float
    :return: latitude or longitude in decimal degrees

    :Example: ::

        >>> from mtpy.utils import gis_tools
        >>> gis_tools.convert_position_str2float('-118:34:56.3')
        -118.58230555555555

    """

    if position_str in [None, 'None']:
        return None

    if ':' in position_str:
        if position_str.count(':') != 2:
            msg = '{0} not correct format.\n'.format(position_str) +\
                  'Position needs to be DD:MM:SS.ms'
            raise GISError(msg)
        p_list = position_str.split(':')
        #----------------------------------------------
        deg = float(p_list[0])
        minutes = float(p_list[1])
        sec = float(p_list[2])
        minutes, sec = _restart_count(minutes, sec) 
        deg, minutes =  _restart_count(deg, minutes) 
        #--------------------------------------------------
        sign = np.sign(deg)

        position_value = sign * (abs(deg) + minutes / 60. + sec / 3600.)
    else:
        try:
            position_value = float(position_str)
        except ValueError:
            msg = '{0} not correct format.\n'.format(position_str) +\
                  'Position needs to be DD.decimal_degrees'
            raise GISError(msg)

    return position_value

Context

Not easy to nanually modify everytimes the DD:MM:SS in 528 sites everytimes values equals to 60.

Your Environment

  • Operating system:Window10
  • MtPy version: 1.5
  • Python version:3.9
  • Matplotlib version:
  • Matplotlib backend (print(matplotlib.get_backend())):
  • QT version:

Installed Python Packages: use pip freeze or conda list [-n ENVIRONMENT_NAME] to list all the installed libraries.