Skip to content
Snippets Groups Projects
Commit b50d687d authored by Petrus Hyvönen's avatar Petrus Hyvönen
Browse files

Merge branch 'load-orekit-data-directory' into 'master'

Make setup_orekit_curdir optionally load data from folder

See merge request !3
parents 460ccc42 bbca7902
No related branches found
No related tags found
1 merge request!3Make setup_orekit_curdir optionally load data from folder
......@@ -24,9 +24,10 @@ import shutil
from datetime import datetime
import math
import os
from java.io import File
from orekit import JArray
from org.orekit.data import DataProvidersManager, ZipJarCrawler
from org.orekit.data import DataProvidersManager, ZipJarCrawler, DirectoryCrawler
from org.orekit.time import TimeScalesFactory, AbsoluteDate
from org.orekit.utils import ElevationMask
......@@ -58,22 +59,27 @@ def download_orekit_data_curdir(filename='orekit-data.zip'):
def setup_orekit_curdir(filename='orekit-data.zip'):
"""Setup the java engine with orekit.
This function loads the orekit-data.zip from the current directory
and sets up the Orekit DataProviders to access it.
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.
Then the function sets up the Orekit DataProviders to access it.
The JVM needs to be initiated prior to calling this function:
orekit.initVM()
Args:
filename (str): Name of zip with orekit data. Default filename is 'orekit-data.zip'
filename (str): Name of zip or folder with orekit data. Default filename is 'orekit-data.zip'
"""
DM = DataProvidersManager.getInstance()
datafile = File(filename)
if not datafile.exists():
print('File :', datafile.absolutePath, ' not found')
print('File or folder:', datafile.absolutePath, ' not found')
print("""
The Orekit library relies on some external data for physical models.
......@@ -90,7 +96,12 @@ def setup_orekit_curdir(filename='orekit-data.zip'):
""")
crawler = ZipJarCrawler(datafile)
if os.path.isdir(filename):
crawler = DirectoryCrawler(datafile)
elif os.path.isfile(filename):
crawler = ZipJarCrawler(datafile)
else:
print('filename ', filename, ' is neither a file nor a folder')
DM.clearProviders()
DM.addProvider(crawler)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment