Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
3 changes: 0 additions & 3 deletions .idea/GMAT-Python-simple.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/dictionaries/project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from __future__ import annotations
import os

from load_gmat import gmat
import gmat_py_simple as gpy
from gmat_py_simple import gmat as gmat

# Set log and script options
log_path = os.path.normpath(f'{os.getcwd()}/GMAT-Log-example.txt')
Expand Down
3 changes: 2 additions & 1 deletion examples/minimum_propagate_using_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# Set log and script options
log_path = os.path.normpath(f'{os.getcwd()}/GMAT-Log.txt')
gmat.UseLogFile(log_path)
gmat.GmatGlobal.Instance().SetCommandEchoMode(True) # enables "CurrentCommand: [command generating string]" print out in log
gmat.GmatGlobal.Instance().SetCommandEchoMode(
True) # enables "CurrentCommand: [command generating string]" print out in log
gmat.EchoLogFile(False) # set to True to have the log also print to the console as it's written

# Shortcuts for later
Expand Down
6 changes: 4 additions & 2 deletions examples/tutorials/Tut01_SimulatingAnOrbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# Written by William Easdown Babb

from __future__ import annotations
from load_gmat import gmat
import gmat_py_simple as gpy

import os

import gmat_py_simple as gpy
from gmat_py_simple import gmat

log_path = os.path.normpath(f'{os.getcwd()}/GMAT-Log.txt')
gmat.UseLogFile(log_path)
echo_log = False
Expand Down
22 changes: 11 additions & 11 deletions examples/tutorials/Tut02_SimpleOrbitTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

# Targeting sequence to adjust parameters of the two burns (TOI and GOI) to achieve desired final orbit
tg1 = gpy.Target('Hohmann Transfer', dc1, exit_mode='SaveAndContinue', command_sequence=[
# Vary the velocity of the TOI burn to achieve an apoapsis with RMAG = 42165 km
gpy.Vary('Vary TOI', dc1, f'{toi.name}.Element1'),
gpy.Maneuver('Perform TOI', toi, sat),
gpy.Propagate('Prop To Apoapsis', sat, prop, f'{sat.name}.Earth.Apoapsis'),
gpy.Achieve('Achieve RMAG = 42165', dc1, f'{sat.name}.Earth.RMAG', 42164.169, 0.1),

# Vary the velocity of the GOI burn to achieve an eccentricity of 0.005
gpy.Vary('Vary GOI', dc1, f'{goi.name}.Element1', max_step=0.2),
gpy.Maneuver('Perform GOI', goi, sat),
gpy.Achieve('Achieve ECC = 0.005', dc1, f'{sat.name}.Earth.ECC', 0.005, 0.0001)
])
# Vary the velocity of the TOI burn to achieve an apoapsis with RMAG = 42165 km
gpy.Vary('Vary TOI', dc1, f'{toi.name}.Element1'),
gpy.Maneuver('Perform TOI', toi, sat),
gpy.Propagate('Prop To Apoapsis', sat, prop, f'{sat.name}.Earth.Apoapsis'),
gpy.Achieve('Achieve RMAG = 42165', dc1, f'{sat.name}.Earth.RMAG', 42164.169, 0.1),

# Vary the velocity of the GOI burn to achieve an eccentricity of 0.005
gpy.Vary('Vary GOI', dc1, f'{goi.name}.Element1', max_step=0.2),
gpy.Maneuver('Perform GOI', goi, sat),
gpy.Achieve('Achieve ECC = 0.005', dc1, f'{sat.name}.Earth.ECC', 0.005, 0.0001)
])

# Mission Command Sequence
mcs = [
Expand Down
7 changes: 7 additions & 0 deletions gmat_py_simple/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from .import_lib import gmat_path

from .load_gmat import *

# GMAT's built-in library that interfaces to GMAT's source code.
gmat: types.ModuleType = load_gmat.gmat

from .api_funcs import *
from .basics import *
from .burn import *
Expand Down
3 changes: 2 additions & 1 deletion gmat_py_simple/api_funcs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

from load_gmat import gmat
from gmat_py_simple import gmat
import gmat_py_simple as gpy

import os.path


## TODO remove commented code
# def GetObject(name: str) -> gmat.GmatBase:
# try:
# obj: gmat.GmatBase = gmat.GetObject(name)
Expand Down
3 changes: 2 additions & 1 deletion gmat_py_simple/basics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

import gmat_py_simple as gpy
from load_gmat import gmat
# from gmat_py_simple import gmat
from gmat_py_simple.load_gmat import gmat

from datetime import datetime

Expand Down
2 changes: 1 addition & 1 deletion gmat_py_simple/burn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import gmat_py_simple as gpy
from gmat_py_simple.basics import GmatObject

from load_gmat import gmat
from gmat_py_simple import gmat


class Burn(GmatObject):
Expand Down
104 changes: 53 additions & 51 deletions gmat_py_simple/commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
from math import pi

from load_gmat import gmat
from gmat_py_simple import gmat

import gmat_py_simple as gpy
from gmat_py_simple.utils import *
Expand Down Expand Up @@ -211,54 +211,54 @@ def __init__(self, name: str, solver: gpy.DifferentialCorrector | gmat.Different
# # param_type is the final element of the self.variable string, e.g. Periapsis for Sat.Earth.Periapsis
# param_eles = self.variable.split('.')
# param_type = param_eles[-1]
# new_param = gpy.Parameter(param_type, self.variable)
# for ele in param_eles:
# body = 'Earth'
# cs = 'EarthMJ2000Eq'
# if ele in gpy.CelestialBodies(): # a CelestialBody is given, so need to set it as a ref object
# # TODO: test this
# body = ele
#
# if ele in gpy.CoordSystems():
# cs = ele
#
# pass
# new_param.SetRefObjectName(gmat.SPACE_POINT, body)
# new_param.SetRefObjectName(gmat.COORDINATE_SYSTEM, cs)
# new_param.Help()
# print(new_param.gmat_base.GetRefObjectTypeArray())
# new_param.SetRefObjectName(gmat.CELESTIAL_BODY, ele)

# if ele in gpy.CoordSystems(): # a CoordinateSystem is given, so need to set it as a ref object
# # TODO remove (debugging only)
# test_bddot = gmat.Construct('BdotT', 'TestBdotT')
# test_bddot.SetRefObjectName(gmat.SPACECRAFT, 'MAVEN')
# # test_bddot.SetReference(gmat.GetObject('MAVEN'))
# # print(gpy.Moderator().gmat_obj.GetListOfFactoryItems(gmat.PARAMETER))
# # test_bddot.RenameRefObject(gmat.COORDINATE_SYSTEM, 'EarthMJ2000Eq', ele)
# test_bddot.SetRefObjectName(gmat.COORDINATE_SYSTEM, ele)
# cs = gmat.GetObject(ele)
# test_bddot.SetRefObject(cs, gmat.COORDINATE_SYSTEM, cs.GetName())
#
# # test_bddot.SetRefObjectName(gmat.SPACECRAFT, 'MAVEN')
# test_bddot.SetRefObject(gmat.GetObject('MAVEN'), gmat.SPACECRAFT, 'MAVEN')
#
# test_bddot.SetSolarSystem(gmat.GetSolarSystem())
# # gmat.Initialize()
# mod = gpy.Moderator().gmat_obj
# mod.SetParameterRefObject(test_bddot, 'BdotT', cs.GetName(), '', '', 1)
# test_bddot.Help()
# test_bddot.Initialize()
#
# new_param.SetRefObjectName(gmat.COORDINATE_SYSTEM, ele)
# # new_param.SetStringParameter(new_param.GetParameterID('CoordinateSystem'), ele)
# # new_param.SetRefObject(gmat.GetObject(ele), gmat.COORDINATE_SYSTEM)
# new_param.Help()
# pass
#
# for body in gpy.CelestialBodies():
# if body in self.variable:
# new_param.SetRefObject(gmat.Planet(body), gmat.COORDINATE_SYSTEM)
# new_param = gpy.Parameter(param_type, self.variable)
# for ele in param_eles:
# body = 'Earth'
# cs = 'EarthMJ2000Eq'
# if ele in gpy.CelestialBodies(): # a CelestialBody is given, so need to set it as a ref object
# # TODO: test this
# body = ele
#
# if ele in gpy.CoordSystems():
# cs = ele
#
# pass
# new_param.SetRefObjectName(gmat.SPACE_POINT, body)
# new_param.SetRefObjectName(gmat.COORDINATE_SYSTEM, cs)
# new_param.Help()
# print(new_param.gmat_base.GetRefObjectTypeArray())
# new_param.SetRefObjectName(gmat.CELESTIAL_BODY, ele)

# if ele in gpy.CoordSystems(): # a CoordinateSystem is given, so need to set it as a ref object
# # TODO remove (debugging only)
# test_bddot = gmat.Construct('BdotT', 'TestBdotT')
# test_bddot.SetRefObjectName(gmat.SPACECRAFT, 'MAVEN')
# # test_bddot.SetReference(gmat.GetObject('MAVEN'))
# # print(gpy.Moderator().gmat_obj.GetListOfFactoryItems(gmat.PARAMETER))
# # test_bddot.RenameRefObject(gmat.COORDINATE_SYSTEM, 'EarthMJ2000Eq', ele)
# test_bddot.SetRefObjectName(gmat.COORDINATE_SYSTEM, ele)
# cs = gmat.GetObject(ele)
# test_bddot.SetRefObject(cs, gmat.COORDINATE_SYSTEM, cs.GetName())
#
# # test_bddot.SetRefObjectName(gmat.SPACECRAFT, 'MAVEN')
# test_bddot.SetRefObject(gmat.GetObject('MAVEN'), gmat.SPACECRAFT, 'MAVEN')
#
# test_bddot.SetSolarSystem(gmat.GetSolarSystem())
# # gmat.Initialize()
# mod = gpy.Moderator().gmat_obj
# mod.SetParameterRefObject(test_bddot, 'BdotT', cs.GetName(), '', '', 1)
# test_bddot.Help()
# test_bddot.Initialize()
#
# new_param.SetRefObjectName(gmat.COORDINATE_SYSTEM, ele)
# # new_param.SetStringParameter(new_param.GetParameterID('CoordinateSystem'), ele)
# # new_param.SetRefObject(gmat.GetObject(ele), gmat.COORDINATE_SYSTEM)
# new_param.Help()
# pass
#
# for body in gpy.CelestialBodies():
# if body in self.variable:
# new_param.SetRefObject(gmat.Planet(body), gmat.COORDINATE_SYSTEM)

self.value = value
self.SetStringParameter('GoalValue', str(self.value))
Expand All @@ -280,7 +280,8 @@ def SetRefObject(self, obj, type_int: int, obj_name: str = '') -> bool:


class BeginFiniteBurn(GmatCommand):
def __init__(self, burn: gpy.FiniteBurn | gmat.FiniteBurn, spacecraft: gpy.Spacecraft | gmat.Spacecraft, name: str = ''):
def __init__(self, burn: gpy.FiniteBurn | gmat.FiniteBurn, spacecraft: gpy.Spacecraft | gmat.Spacecraft,
name: str = ''):
super().__init__('BeginFiniteBurn', name)

# Assign the user-provided FiniteBurn to this command
Expand All @@ -293,7 +294,8 @@ def __init__(self, burn: gpy.FiniteBurn | gmat.FiniteBurn, spacecraft: gpy.Space
# self.spacecraft.Help()
# print(type(self.spacecraft))
# self.burn.SetSpacecraftToManeuver(gpy.extract_gmat_obj(self.spacecraft)) # update FiniteBurn's associated Spacecraft
gpy.FiniteBurn.SetSpacecraftToManeuver(self.burn, gpy.extract_gmat_obj(self.spacecraft)) # update FiniteBurn's associated Spacecraft
gpy.FiniteBurn.SetSpacecraftToManeuver(self.burn, gpy.extract_gmat_obj(
self.spacecraft)) # update FiniteBurn's associated Spacecraft

self.Initialize()

Expand Down
12 changes: 5 additions & 7 deletions gmat_py_simple/executive.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from __future__ import annotations

import gmat_py_simple as gpy
from load_gmat import gmat
from gmat_py_simple import GmatCommand
from gmat_py_simple import gmat

import sys


def RunMission(mcs: list[GmatCommand]) -> int:
def RunMission(mcs: list[gpy.GmatCommand]) -> int:
# Shortcut for running missions
return gpy.Moderator().RunMission(mcs)

Expand Down Expand Up @@ -199,13 +196,13 @@ def GetFirstCommand(self):
def Initialize(self):
self.gmat_obj.Initialize()

def InsertCommand(self, command_to_insert: GmatCommand, preceding_command: GmatCommand):
def InsertCommand(self, command_to_insert: gpy.GmatCommand, preceding_command: gpy.GmatCommand):
return self.gmat_obj.InsertCommand(command_to_insert, preceding_command)

def RemoveObject(self, obj_type: int, name: str, del_only_if_not_used: bool = True) -> bool:
return self.gmat_obj.RemoveObject(obj_type, name, del_only_if_not_used)

def RunMission(self, mission_command_sequence: list[GmatCommand]) -> int:
def RunMission(self, mission_command_sequence: list[gpy.GmatCommand]) -> int:
"""
Run the mission command sequence

Expand All @@ -214,6 +211,7 @@ def RunMission(self, mission_command_sequence: list[GmatCommand]) -> int:
:param mission_command_sequence:
:return:
"""

def update_command_objs_post_run(command_sequence: list[gpy.GmatCommand | gmat.GmatCommand]):
propagate_commands: list[gpy.Propagate] = [] # start a list of Propagates so their sats can be updated
target_commands: list[gpy.Target] = [] # start a list of Targets for checking convergence
Expand Down
Loading
Loading