diff --git a/.devcontainer/dev-conda-environment.yaml b/.devcontainer/dev-conda-environment.yaml index 5bca6a6482defedd7ad745c756901fb8a462dae0..4c95063e580a03a66a54c09f649eefb16f7ce302 100644 --- a/.devcontainer/dev-conda-environment.yaml +++ b/.devcontainer/dev-conda-environment.yaml @@ -24,8 +24,5 @@ dependencies: - flake8-builtins - flake8-use-pathlib - flake8-noqa - -# # In case you want to install packages from PyPI which aren't on Conda-Forge, -# # uncomment this block and add them as follows: -# - pip: -# - flake8-noqa # Example +- pip: + - "git+https://gitlab.orekit.org/yzokras/orekit-data.git" diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..0e3c6e84f131f20e527d60959363a2f2f67f1525 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Description + +Orekit (ORbit Extrapolation KIT) is a free java library providing basic space dynamics objects and services. + +This repository contains examples and some additional scripts. + +# Licensing + +Orekit is licensed under the Apache License Version 2.0. +A copy of this license is provided in the LICENSE.txt file. + +# Content + +The python-wrapper project allows using orekit in a python environment. This repository contains some key files if building the wrapper from scratch. For many applications it is recommended to use pre-built conda packages through the conda-forge python system. See the [wiki](https://gitlab.orekit.org/orekit-labs/python-wrapper/-/wikis/home) for more details. + +# Building from source + +The sources for the java classes that allows Python subclassing are no longer in a separate package but integrated in a modified orekit source fork. + +This fork is available at https://github.com/petrushy/Orekit + +A compiled jar and some other artifacts are available at https://github.com/petrushy/orekit_python_artifacts + +Build scripts for the automated conda package builds are at https://github.com/conda-forge/orekit-feedstock/tree/main/recipe + +# Support + +For additional support please see the [orekit forum](https://forum.orekit.org/latest) diff --git a/README.txt b/README.txt deleted file mode 100644 index 9119b18d75a772dca4212efd8f61702d57b50d67..0000000000000000000000000000000000000000 --- a/README.txt +++ /dev/null @@ -1,32 +0,0 @@ -Orekit (ORbit Extrapolation KIT) is a free java library -providing basic space dynamics objects and services. - -This repository contains examples and some additional scripts. - -Orekit is licensed under the Apache License Version 2.0. -A copy of this license is provided in the LICENSE.txt file. - -The python-wrapper project allows using orekit in a -python environment. This repository contains some key files -if building the wrapper from scratch. For many applications -it is recommended to use pre-built conda packages through -the conda-forge python system. See the wiki for more details, - -https://gitlab.orekit.org/orekit-labs/python-wrapper/-/wikis/home - - -The sources for the java classes that allows Python subclassing are no longer in a separate package -but integrated in a modified orekit source fork. - -This fork is available at: -https://github.com/petrushy/Orekit - -A compiled jar and some other artifacts are available at: -https://github.com/petrushy/orekit_python_artifacts - -build scripts for the automated conda package builds are at: -https://github.com/conda-forge/orekit-feedstock/tree/main/recipe - -For additional support please see the orekit forum: -https://forum.orekit.org/latest - diff --git a/environment.yml b/environment.yml index 1c684ac4c2f7a087a3e06c866d705d4e826f0166..6041f63b080b3533535c46ddd382cb5400afcfe4 100644 --- a/environment.yml +++ b/environment.yml @@ -13,5 +13,6 @@ dependencies: - scipy - jupyterlab - ipython - - + - pip + - pip: + - "git+https://gitlab.orekit.org/yzokras/orekit-data.git" diff --git a/python_files/pyhelpers.py b/python_files/pyhelpers.py index ba4bc1850ea3846d81a71a5452a77450cc307a24..90921575c03acc7a447ef252fa1b1b11386228b5 100644 --- a/python_files/pyhelpers.py +++ b/python_files/pyhelpers.py @@ -50,18 +50,21 @@ def download_orekit_data_curdir(filename='orekit-data.zip'): url = "https://gitlab.orekit.org/orekit/orekit-data/-/archive/master/orekit-data-master.zip" # Download the orekit-data file and store it locally - with urlrequest.urlopen(url) as response, open("orekit-data.zip", 'wb') as out_file: + with urlrequest.urlopen(url) as response, open(filename, 'wb') as out_file: print('Downloading file from:', url) 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) diff --git a/python_files/test/OrekitDataLoadTest.py b/python_files/test/OrekitDataLoadTest.py new file mode 100644 index 0000000000000000000000000000000000000000..9f01e49bfe8c48119c8fd45a3ab3fd0414737b48 --- /dev/null +++ b/python_files/test/OrekitDataLoadTest.py @@ -0,0 +1,23 @@ +import os +import orekit +from orekit.pyhelpers import setup_orekit_curdir, download_orekit_data_curdir +from org.orekit.utils import Constants + +def test_load_data_from_library(): + orekit.initVM() + setup_orekit_curdir(from_pip_library=True) + assert(Constants.WGS84_EARTH_EQUATORIAL_RADIUS == 6378137.0) + +def test_download_and_load_data(): + orekit.initVM() + + orekit_data_zip = 'orekit-data.zip' + if os.path.isfile(orekit_data_zip): + os.remove(orekit_data_zip) + + download_orekit_data_curdir(filename=orekit_data_zip) + setup_orekit_curdir(filename=orekit_data_zip) + assert(Constants.WGS84_EARTH_EQUATORIAL_RADIUS == 6378137.0) + + if os.path.isfile(orekit_data_zip): + os.remove(orekit_data_zip) diff --git a/python_files/test/pytest.ini b/python_files/test/pytest.ini index e0bdf3d18bc3b8d18f63bcce21b2a05e770b389e..384f471b1997ff3020857c6ff194f3818f5ef651 100644 --- a/python_files/test/pytest.ini +++ b/python_files/test/pytest.ini @@ -4,3 +4,5 @@ [pytest] python_files=*.py +filterwarnings = + ignore::DeprecationWarning