PKL6 !midgard/__init__.py"""Midgard, the Python Geodesy library Midgard is a collection of useful Python utilities used by the Geodetic institute at the Norwegian Mapping Authority (Kartverket). Although some of these are geodesy-specific, many are also useful in more general settings. Note: Midgard is still in pre-alpha status. Its functionality will change, and it should not be depended on in any production-like setting. Midgard comes organized into different subpackages: {list_subpackages} Look for help inside each subpackage: >>> from midgard import subpackage >>> help(subpackage) Authors: -------- {list_authors} """ # Standard library imports from datetime import date as _date from collections import namedtuple as _namedtuple from pathlib import Path as _Path # Version of Midgard. # # This is automatically set using the bumpversion tool __version__ = '0.1.1' # Authors of Midgard. _Author = _namedtuple('_Author', ['name', 'email', 'start', 'end']) _Author.__new__.__defaults__ = ('', '', _date(2018, 4, 1), _date.max) _AUTHORS = sorted([ _Author('Geir Arne Hjelle', 'geir.arne.hjelle@kartverket.no'), ], key=lambda a: a.name.split()[-1]) # Sort on last name __author__ = ', '.join(a.name for a in _AUTHORS if a.start < _date.today() < a.end) __contact__ = ', '.join(a.email for a in _AUTHORS if a.start < _date.today() < a.end) # Copyright of the library __copyright__ = f'2018 - {_date.today().year} Norwegian Mapping Authority' # Update doc with info about subpackages and authors def _update_doc(doc): """Add information to module doc-string Args: doc (str): The doc-string to format as the module doc-string. """ # Subpackages subpackage_paths = _Path(__file__).parent.iterdir() subpackages = [p.name for p in subpackage_paths if p.is_dir() and not p.name.startswith('_')] list_subpackages = '\n'.join(f'+ {p}' for p in subpackages) # Authors authors = [f'+ {a.name} <{a.email}>' for a in _AUTHORS if a.start < _date.today() < a.end] list_authors = '\n'.join(authors) # Add to module doc-string return doc.format(list_subpackages=list_subpackages, list_authors=list_authors) __doc__ = _update_doc(__doc__) PKkLX/_midgard/collections/enums.py"""Framework for working with enumerations Description: ------------ Custom enumerations used for structured names. """ # Midgard imports from midgard.dev import exceptions # Dictionary of Enumerations. Populated by the @register_enum-decorators. _ENUMS = dict() def get_enum(name=None): """Return a named Enumeration Names are defined by the @register_enum-decorator. If the name-parameter is not given, the function will raise an UnknownEnumError and list the available enumerations. Args: name (String): Name used for Enumeration. Returns: Enum: Enumeration with the given name. """ try: return _ENUMS[name] except KeyError: valid_enums = ', '.join(e for e in _ENUMS) raise exceptions.UnknownEnumError(f"Enumeration '{name}' is not defined. " f'Available enumerations are {valid_enums}.') from None def get_value(name, value): """Return the value of a named Enumeration Names are defined by the @register_enum-decorator. Args: name (String): Name used for Enumeration. value (String): Value of Enumeration. Returns: Enum: Value of enumeration with the given name. """ try: return get_enum(name)[value] except KeyError: valid_values = ', '.join(v.name for v in get_enum(name)) raise ValueError(f"Value '{value}' is not valid for a {name}-enumeration. " f'Valid values are {valid_values}.') from None def register_enum(name): """Register a named Enumeration This allows for getting Enumerations with the get_enum-function. Args: name (String): Name used for Enumeration. Returns: Decorator: Decorator that registers an Enumeration. """ def register_decorator(func): _ENUMS[name] = func return func return register_decorator PKwL&midgard/collections/dataset/dataset.pyPKzL$midgard/collections/dataset/table.pyPK첐Lmidgard/config/config.pyPKҲLmidgard/config/constant.pyPKԲLmidgard/config/unit.pyPKLmidgard/coords/position.pyPK=Lmidgard/coords/time.pyPKαLmidgard/dev/cache.pyPKұLmidgard/dev/console.pyPK5Lmidgard/dev/exceptions.py"""Definition of Midgard-specific exceptions Description: ------------ Custom exceptions used by Midgard for more specific error messages and handling. """ class MidgardException(Exception): pass class MidgardExit(SystemExit, MidgardException): pass class InitializationError(MidgardException): pass class FieldExistsError(MidgardException): pass class FieldDoesNotExistError(MidgardException): pass class MissingDataError(MidgardException): pass class UnknownEnumError(MidgardException): pass class UnknownPluginError(MidgardException): pass class UnitError(MidgardException): pass PKuLmidgard/dev/interactive.pyPK`Lȶimidgard/dev/library.py"""Python wrapper around C-libraries Description: ------------ Loads a C-library. If a library is missing, a mock library is returned. If this mock is used for anything, a warning will be printed. This is done to avoid dependencies to all the C/C++-libraries for Python programs only using some of them. """ # Standard library imports import ctypes as c from ctypes import util as c_util import sys def load_name(library_name, func_specs=None, name_patterns=None): """Load the given shared C-library See `load_path` for an explanation of the `func_specs` and `name_patterns`-arguments. Args: library_name (String): The name of the library. func_specs (Dict): Specification of types in lib (see load_path). name_patterns (List): Name mangling patterns (see load_path). Returns: ctypes.CDLL: Representation of the shared library. """ library_path = c_util.find_library(library_name) return load_path(library_path, func_specs=func_specs, name_patterns=name_patterns) def load_path(library_path, func_specs=None, name_patterns=None): """Load the given shared C-library The optional func_specs-dictionary can be used to specify argument and return types of functions in the library (see the ctypes documentation for information about argtypes and restype). The dictionary should be on the form:: func_spec = {'func_1': dict(func_name='name_of_func_1_in_lib', argtypes=[ ... argtypes of func_1 ... ], restype=... restype of func_1 ...), 'func_2': ... } If the library is not found, a mock library is returned instead. The mock library will print a warning if it is used. For some libraries, name mangling is used and this might be different depending on operating system and how the library is compiled. For instance, in a Fortran library the function `Test` might be represented as `__Test` on a Windows system and `test_` (with lower-case `t`) on a Linux system. This can be handled by providing a list of possible patterns. The above example can be handled by:: name_patterns = ('__{func_name}', '{func_name_lower}_') In this case, each function in func_specs is looked up by testing each pattern in turn until a match is found. Args: library_path (String): The path to the library. func_specs (Dict): Specification of types in library (see above). name_patterns (List): Name mangling patterns (see above). Returns: ctypes.CDLL: Representation of the shared library. """ library_handle = c.cdll.LoadLibrary(library_path) # Return a Mock object if the library is not found if library_handle._name is None: mock = SimpleMock(name=library_path) return mock # Handle name mangling if name_patterns is None: def mangled_name(name): return name else: def mangled_name(name): for pattern in name_patterns: full_name = pattern.format(func_name=name, func_name_lower=name.lower()) if hasattr(library_handle, full_name): return full_name return name # Set argument and return types on functions if func_specs: for name, spec in func_specs.items(): if 'func_name' in spec: func_name = mangled_name(spec['func_name']) else: func_name = mangled_name(name) func = getattr(library_handle, func_name) delattr(library_handle, func_name) if 'argtypes' in spec: func.argtypes = spec['argtypes'] if 'restype' in spec: func.restype = spec['restype'] setattr(library_handle, name, func) return library_handle class SimpleMock: """Class that can stand in for any other object The SimpleMock is used to stand in for any library that can not be imported. The mock object simply returns itself whenever it is called, or any attributes are looked up on the object. This is done, to avoid ImportErrors when a library is imported, but never used (typically because a plugin is loaded but never called). Instead the ImportError is raised when the SimpleMock is used in any way. The ImportError will only be raised once for any SimpleMock-object (which is only important if the ImportError is caught and the program carries on). """ def __init__(self, name, raise_error=True): """Initialize SimpleMock object Args: name (String): Name of SimpleMock-object. raise_error (Bool): Should ImportError be raised when using object. """ self._name = name self._children = dict() self._raise_error = raise_error def _raise_import_error(self): """Raise an import error when the SimpleMock object is used The ImportError is only raised the first time the object is used. """ # Only raise the error once if self._raise_error: self._raise_error = False else: return # Find calling function caller = sys._getframe() while caller.f_code.co_filename == __file__: caller = caller.f_back func_name = caller.f_code.co_name line_no = caller.f_lineno file_name = caller.f_code.co_filename # Raise ImportError with a helpful message raise ImportError("The library '{}' is not installed, but is used by" "'{}' on line {} of {}" ''.format(self._name, func_name, line_no, file_name)) def __call__(self, *args, **kwargs): """Return the same SimpleMock-object when it is called An ImportError is raised the first time the object is used. Returns: SimpleMock: Itself. """ self._raise_import_error() return self def __getattr__(self, key): """Create a child-SimpleMock-object and return it. The same child object is returned if the same attribute is gotten several times. An ImportError is raised the first time the SimpleMock-object is used. Additional errors are not raised for the children. Args: key (String): Name of attribute. Returns: SimpleMock: A child-SimpleMock-object. """ self._raise_import_error() if key not in self._children: self._children[key] = type(self)('{}.{}'.format(self._name, key), raise_error=self._raise_error) setattr(self, key, self._children[key]) return self._children[key] def __repr__(self): """String representation of the SimpleMock-object Returns: String: Simple representation of the SimpleMock-object. """ return "{}('{}')".format(self.__class__.__name__, self._name) def __str__(self): """Convert to the empty string Returns: String: An empty string. """ return '' PKױLmidgard/dev/log.pyPK۱Lmidgard/dev/optional.pyPK᱐Lmidgard/dev/plugins.pyPK豐Lmidgard/dev/profiler.pyPKLmidgard/dev/timer.pyPKLmidgard/dev/util.pyPKqLRRDmidgard/files/dates.py"""Convenience functions for working with dates Description: ------------ Formats and converters that can be used for convenience and consistency. """ # Formats that can be passed to datetime.strftime, see http://strftime.org/ FMT_date = '%Y-%m-%d' FMT_datetime = '%Y-%m-%d %H:%M:%S' FMT_dt_file = '%Y%m%d-%H%M%S' def date_vars(date): """Construct a dict of date variables From a given date, construct a dict containing all relevant date variables. This dict can be used to for instance replace variables in file names. Examples: >>> from datetime import date >>> date_vars = date_vars(date(2009, 11, 2)) >>> sorted(date_vars.items()) # doctest: +NORMALIZE_WHITESPACE [('MMM', 'NOV'), ('ce', '20'), ('d', '2'), ('dd', '02'), ('dow', '1'), ('doy', '306'), ('gpsweek', '1556'), ('m', '11'), ('mm', '11'), ('mmm', 'nov'), ('yy', '09'), ('yyyy', '2009')] Args: date (Date/Datetime): The date. Returns: Dict: Dictionary with date variables for the given date. """ if date is None: return dict() # Create the dict of date variables return dict( yyyy=date.strftime('%Y'), ce=date.strftime('%Y')[:2], yy=date.strftime('%y'), m=str(date.month), mm=date.strftime('%m'), mmm=date.strftime('%b').lower(), MMM=date.strftime('%b').upper(), d=str(date.day), dd=date.strftime('%d'), doy=date.strftime('%j'), dow=date.strftime('%w'), ) PKƱLmidgard/files/dependencies.pyPKLmidgard/files/files.pyPKLmidgard/math/rotation.pyPKLmidgard/parsers/_parser.pyPKL midgard/parsers/_parser_chain.pyPKLmidgard/parsers/_parser_line.pyPKL midgard/parsers/_parser_sinex.pyPKNL|SFFmidgard-0.1.1.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2018 Norwegian Mapping Authority Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIG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l= n| y1-蹮_㒵p@Ņ!g!kxt:韨 .#?T۶lIpyC2wݠe㙀 Ngm@p8MtEw]t&(X6vq!t4midgard/dev/interactive.pyPK`Lȶivmidgard/dev/library.pyPKױLf2midgard/dev/log.pyPK۱L2midgard/dev/optional.pyPK᱐L2midgard/dev/plugins.pyPK豐L2midgard/dev/profiler.pyPKL43midgard/dev/timer.pyPKLf3midgard/dev/util.pyPKqLRRD3midgard/files/dates.pyPKƱL9midgard/files/dependencies.pyPKL:midgard/files/files.pyPKL9:midgard/math/rotation.pyPKLo:midgard/parsers/_parser.pyPKL :midgard/parsers/_parser_chain.pyPKL:midgard/parsers/_parser_line.pyPKL ";midgard/parsers/_parser_sinex.pyPKNL|SFF`;midgard-0.1.1.dist-info/LICENSEPK!HNO?midgard-0.1.1.dist-info/WHEELPK!HXM0J l@midgard-0.1.1.dist-info/METADATAPK!HǕ Emidgard-0.1.1.dist-info/RECORDPK H