diff --git a/python_files/pyhelpers.py b/python_files/pyhelpers.py index 555e21d50dac5f6fe5ce52dd22a9d08fd0f03b41..90921575c03acc7a447ef252fa1b1b11386228b5 100644 --- a/python_files/pyhelpers.py +++ b/python_files/pyhelpers.py @@ -55,13 +55,16 @@ def download_orekit_data_curdir(filename='orekit-data.zip'): shutil.copyfileobj(response, out_file) -def setup_orekit_curdir(filename='orekit-data.zip'): +def setup_orekit_curdir(filename='orekit-data.zip', from_pip_library=False): """Setup the java engine with orekit. This function loads the Orekit data from either: - A zip in the current directory (by default orekit-data.zip), - A folder, - depending on whether `filename` is the path to a file or to a folder. + - From the `orekitdata` Python library, installable via pip (see below) + depending on whether `filename` is the path to a file or to a folder, and whether from_pip_library is True or False + + The `orekitdata` library is installable with `pip install git+https://gitlab.orekit.org/orekit/orekit-data.git` Then the function sets up the Orekit DataProviders to access it. @@ -71,30 +74,48 @@ def setup_orekit_curdir(filename='orekit-data.zip'): Args: filename (str): Name of zip or folder with orekit data. Default filename is 'orekit-data.zip' - + from_pip_library (bool), default False: if True, will first try to load the data from the `orekitdata` python library """ DM = DataContext.getDefault().getDataProvidersManager() - datafile = File(filename) - if not datafile.exists(): - print('File or folder:', datafile.getAbsolutePath(), ' not found') - print(""" - - The Orekit library relies on some external data for physical models. - Typical data are the Earth Orientation Parameters and the leap seconds history, - both being provided by the IERS or the planetary ephemerides provided by JPL. - Such data is stored in text or binary files with specific formats that Orekit knows - how to read, and needs to be provided for the library to work. - - You can download a starting file with this data from the orekit gitlab at: - https://gitlab.orekit.org/orekit/orekit-data - - or by the function: - orekit.pyhelpers.download_orekit_data_curdir() - """) - return + data_load_from_library_sucessful = False + if from_pip_library: + try: + import orekitdata + datafile = File(orekitdata.__path__[0]) + if not datafile.exists(): + print(f"""Unable to find orekitdata library folder, + will try to load Orekit data using the folder or filename {filename}""") + else: + filename = orekitdata.__path__[0] + data_load_from_library_sucessful = True + except ImportError: + print(f"""Failed to load orekitdata library. + Install with `pip install git+https://gitlab.orekit.org/orekit/orekit-data.git` + Will try to load Orekit data using the folder or filename {filename}""") + + if not data_load_from_library_sucessful: + datafile = File(filename) + if not datafile.exists(): + print('File or folder:', datafile.getAbsolutePath(), ' not found') + print(""" + + The Orekit library relies on some external data for physical models. + Typical data are the Earth Orientation Parameters and the leap seconds history, + both being provided by the IERS or the planetary ephemerides provided by JPL. + Such data is stored in text or binary files with specific formats that Orekit knows + how to read, and needs to be provided for the library to work. + + You can download a starting file with this data from the orekit gitlab at: + https://gitlab.orekit.org/orekit/orekit-data + + or by the function: + orekit.pyhelpers.download_orekit_data_curdir() + + """) + return if os.path.isdir(filename): crawler = DirectoryCrawler(datafile)