Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
orekit_jpype
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Orekit
orekit_jpype
Commits
d938189b
Commit
d938189b
authored
1 year ago
by
Petrus Hyvönen
Browse files
Options
Downloads
Patches
Plain Diff
WIP pyhelpers
parent
1a0e9a8b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
orekit_jpype/__init__.py
+2
-1
2 additions, 1 deletion
orekit_jpype/__init__.py
orekit_jpype/pyhelpers.py
+73
-9
73 additions, 9 deletions
orekit_jpype/pyhelpers.py
with
75 additions
and
10 deletions
orekit_jpype/__init__.py
+
2
−
1
View file @
d938189b
from
.orekit_jpype
import
initVM
from
jpype
import
JArray
,
JDouble
from
jpype
import
JArray
,
JDouble
,
JByte
,
JShort
,
JInt
,
JLong
,
JFloat
,
JChar
,
JBoolean
,
JString
,
JObject
,
JClass
from
jpype
import
JException
# JArray_double = JArray(JDouble)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
orekit_jpype/pyhelpers.py
+
73
−
9
View file @
d938189b
...
...
@@ -22,6 +22,8 @@ from datetime import datetime
import
math
import
os
from
typing
import
List
,
Union
# JVM needs to have been started before importing these, run initVM prior to the imports!
from
java.io
import
File
from
org.orekit.data
import
DataProvidersManager
,
ZipJarCrawler
,
DirectoryCrawler
,
DataContext
,
LazyLoadedDataContext
from
org.orekit.time
import
TimeScalesFactory
,
AbsoluteDate
...
...
@@ -57,7 +59,13 @@ def download_orekit_data_curdir(filename='orekit-data.zip'):
print
(
'
Downloading file from:
'
,
url
)
shutil
.
copyfileobj
(
response
,
out_file
)
def
clear_data_context
(
dpm
:
DataProvidersManager
):
"""
Clear the data context for the provided data Provider manager
"""
dpm
.
clearProviders
()
dpm
.
clearLoadedDataNames
()
dpm
.
resetFiltersToDefault
()
dpm
.
clearLoadedDataNames
()
def
clear_factory_maps
(
factory_class
):
for
field
in
factory_class
.
getDeclaredFields
():
...
...
@@ -72,6 +80,37 @@ def clear_factories():
clear_factory_maps
(
FramesFactory
.
class_
)
def
add_orekitdata_library
(
dpm
:
DataProvidersManager
):
try
:
import
orekitdata
datafile
=
File
(
orekitdata
.
__path__
[
0
])
if
not
datafile
.
exists
():
print
(
f
"""
Unable to find orekitdata module library folder
"""
)
raise
ImportError
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
}
"""
)
raise
ImportError
crawler
=
DirectoryCrawler
(
datafile
)
dpm
.
addProvider
(
crawler
)
def
add_orekit_file_or_folder
(
dp
:
DataProvidersManager
,
filename
:
str
):
"""
Add a file or folder to the data providers manager
"""
if
os
.
path
.
isdir
(
filename
):
crawler
=
DirectoryCrawler
(
File
(
filename
))
elif
os
.
path
.
isfile
(
filename
):
crawler
=
ZipJarCrawler
(
File
(
filename
))
else
:
print
(
'
filename
'
,
filename
,
'
is neither a file nor a folder
'
)
raise
FileNotFoundError
dp
.
addProvider
(
crawler
)
def
setup_orekit_curdir
(
filename
:
str
=
'
orekit-data.zip
'
,
from_pip_library
:
bool
=
False
):
...
...
@@ -97,7 +136,7 @@ s
"""
DM
=
DataContext
.
getDefault
().
getDataProvidersManager
()
DM
:
DataProvidersManager
=
DataContext
.
getDefault
().
getDataProvidersManager
()
data_load_from_library_sucessful
=
False
if
from_pip_library
:
...
...
@@ -142,16 +181,29 @@ s
crawler
=
ZipJarCrawler
(
datafile
)
else
:
print
(
'
filename
'
,
filename
,
'
is neither a file nor a folder
'
)
DM
.
clearProviders
()
DM
.
clearLoadedDataNames
()
DM
.
resetFiltersToDefault
()
clear_data_context
(
DM
)
DM
.
addProvider
(
crawler
)
def
setup_orekit_data
(
filenames
:
Union
[
str
,
List
[
str
],
None
]
=
None
,
from_pip_library
:
bool
=
Tru
e
)
->
None
:
def
setup_orekit_data
(
filenames
:
Union
[
str
,
List
[
str
],
None
]
=
None
,
from_pip_library
:
bool
=
Fals
e
)
->
None
:
"""
Sets up the orekit data from a file, folder or list of files/folders.
Can also load the data from the `orekitdata` python library. (default)
A convenience function that:
- Clear old orekit data
- Sets up the orekit data from file, folder(s) and list of files/folders
- Can also load the data from the `orekitdata` python library.
If several arguments are given, they are all loaded.
This function can load the orekit data from a common orekit-data.zip format that is downloaded with the
conviencience function `download_orekit_data_curdir()`
The filenames can be a string or a list of strings. If a list is given, all files/folders are loaded.
In order to install the orekitdata python package, use the following command:
`pip install git+https://gitlab.orekit.org/orekit/orekit-data.git`
The JVM needs to be initiated prior to calling this function with the .initVM() method.
Args:
filenames (Union[str, List[str]]): Name of zip or folder with orekit data. Default filename is
'
orekit-data.zip
'
...
...
@@ -159,8 +211,20 @@ def setup_orekit_data(filenames: Union[str, List[str], None] = None, from_pip_li
"""
setup_orekit_curdir
(
filename
=
filenames
,
from_pip_library
=
from_pip_library
)
dpm
=
DataContext
.
getDefault
().
getDataProvidersManager
()
clear_data_context
(
dpm
)
if
filenames
is
not
None
:
if
isinstance
(
filenames
,
str
):
filenames
=
[
filenames
]
for
filename
in
filenames
:
add_orekit_file_or_folder
(
dpm
,
filename
)
if
from_pip_library
:
add_orekitdata_library
(
dpm
)
def
absolutedate_to_datetime
(
orekit_absolutedate
:
AbsoluteDate
)
->
datetime
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment