<commit_before>from pynmea.streamer import NMEAStream
from fractions import Fraction
from itertools import groupby
from math import modf
from common import *
try:
    import ogr
except ImportError:
    from osgeo import ogr
    
def fraction_to_rational(fra):
    """
    Take a fraction and return a stupid Rational to make stupid damned 
    pyexiv2 happy. If it's not a fraction, just hand it back and hope
    for the best.
    """
    from pyexiv2.utils import Rational
    if fra.__class__.__name__=='Fraction':
        return Rational(fra.limit_denominator().numerator,fra.limit_denominator().denominator)
    else:
        return fra    

class coord(object):
    """
    Store a latitude or a longitude and provide some methods for converting to
    various formats. Coord will be reclassed by latitude and longitude classes
    that will provide methods specific to those types of coordinates.
    """
    def __init__(self,degrees,minutes):
        # Apparently all my type checking is bad form for python. Maybe 
        # I will take it out at some point but probably not
        if degrees == None:
            self.degrees = None
        elif int(degrees) <> degrees:
            raise ValueError( "The value of %s changes when cast to an integer so it can not be used for degrees" % str(degrees) )
        elif abs(degrees) > 180:
            raise ValueError( "Degrees can not exceed 180." )
        else:
            self.degrees = int(degrees)
        
        if minutes == None:
            self.minutes = None
        elif not 0 <= float(minutes) < 60:
            raise ValueError( "Minutes must be between 0 and 60." )
        else:
            self.minutes = float(minutes)
            
    def __setattr__(self,name,value):
        if name=='degrees':
            if int(value) <> value:
                raise ValueError( "The value of %s changes when cast to an integer so it can not be used for degrees" % str(degrees) )
            elif abs(value) > 180:
                raise ValueError( "Degrees can not exceed 180." )
            else:
                super(coord,self).__setattr__(name,value)
        elif name=='minutes':
            if not 0 <= float(value) < 60:
                raise ValueError( "Minutes must be between 0 and 60." )
            else:
                super(coord,self).__setattr__(name,value)
                
    def __repr__(self):
        return "%i %g" % (self.degrees,self.minutes)
        
    def __unicode__(self):
        return u'%i\u00B0 %g\'' % (self.degrees,self.minutes)
        
    def __str__(self):
        return unicode(self).encode('utf-8')
        
    @property
    def dms(self):
        """
        Return coordinates in a tuple of degrees,minutes,seconds.
        """
        seconds = 60 * modf( self.minutes )[0]
        return (self.degrees,int(self.minutes),seconds)
        
    @property
    def decimal_degrees(self):
        """
        Return the coordinate in decimal degrees.
        """
        from math import copysign as cps
        return self.degrees + cps(self.minutes,self.degrees) / 60.0
        
    @property
    def nmea_string(self):
        """
        Return coordinates in a nmea style string.
        """
        return str(abs(self.degrees)) + str(self.minutes)
    
    @property
    def exif_coord(self):
        """
        Return the coordinate in the format that can be used to assign to an
        exif tag using the pyexiv2 library.
        """<commit_msg>Fixing a pretty major bug that only shows up when a coordinate's minutes are less than 10.<commit_after>from pynmea.streamer import NMEAStream
from fractions import Fraction
from itertools import groupby
from math import modf
from common import *
try:
    import ogr
except ImportError:
    from osgeo import ogr
    
def fraction_to_rational(fra):
    """
    Take a fraction and return a stupid Rational to make stupid damned 
    pyexiv2 happy. If it's not a fraction, just hand it back and hope
    for the best.
    """
    from pyexiv2.utils import Rational
    if fra.__class__.__name__=='Fraction':
        return Rational(fra.limit_denominator().numerator,fra.limit_denominator().denominator)
    else:
        return fra    

class coord(object):
    """
    Store a latitude or a longitude and provide some methods for converting to
    various formats. Coord will be reclassed by latitude and longitude classes
    that will provide methods specific to those types of coordinates.
    """
    def __init__(self,degrees,minutes):
        # Apparently all my type checking is bad form for python. Maybe 
        # I will take it out at some point but probably not
        if degrees == None:
            self.degrees = None
        elif int(degrees) <> degrees:
            raise ValueError( "The value of %s changes when cast to an integer so it can not be used for degrees" % str(degrees) )
        elif abs(degrees) > 180:
            raise ValueError( "Degrees can not exceed 180." )
        else:
            self.degrees = int(degrees)
        
        if minutes == None:
            self.minutes = None
        elif not 0 <= float(minutes) < 60:
            raise ValueError( "Minutes must be between 0 and 60." )
        else:
            self.minutes = float(minutes)
            
    def __setattr__(self,name,value):
        if name=='degrees':
            if int(value) <> value:
                raise ValueError( "The value of %s changes when cast to an integer so it can not be used for degrees" % str(degrees) )
            elif abs(value) > 180:
                raise ValueError( "Degrees can not exceed 180." )
            else:
                super(coord,self).__setattr__(name,value)
        elif name=='minutes':
            if not 0 <= float(value) < 60:
                raise ValueError( "Minutes must be between 0 and 60." )
            else:
                super(coord,self).__setattr__(name,value)
                
    def __repr__(self):
        return "%i %g" % (self.degrees,self.minutes)
        
    def __unicode__(self):
        return u'%i\u00B0 %g\'' % (self.degrees,self.minutes)
        
    def __str__(self):
        return unicode(self).encode('utf-8')
        
    @property
    def dms(self):
        """
        Return coordinates in a tuple of degrees,minutes,seconds.
        """
        seconds = 60 * modf( self.minutes )[0]
        return (self.degrees,int(self.minutes),seconds)
        
    @property
    def decimal_degrees(self):
        """
        Return the coordinate in decimal degrees.
        """
        from math import copysign as cps
        return self.degrees + cps(self.minutes,self.degrees) / 60.0
        
    @property
    def nmea_string(self):
        """
        Return coordinates in a nmea style string.
        """
        return str(abs(self.degrees)) + "{:011.8f}".format( self.minutes )
    
    @property
    def exif_coord(self):
        """
        Return the coordinate in the format that can be used to assign to an
        exif tag using the pyexiv2 library.
        """
{'fraction_non_alphanumeric': 0.08510940608127308, 'fraction_numerical': 0.011366865586814436, 'mean_word_length': 2.0684394071490844, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2233610', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1926, 'n_words': 695}