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
174 changes: 174 additions & 0 deletions StkAutomation/Python/AzEl Polar Plots/AzElPolarPlot_comtypes.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Imports\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from comtypes.client import CreateObject"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Open STK, get the IAgSTKObjectRoot\n",
"uiApplication = CreateObject(\"STK12.Application\")\n",
"uiApplication.Visible=True\n",
"stkRoot = uiApplication.Personality2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Import comptypes generated wrappers\n",
"from comtypes.gen import STKObjects\n",
"from comtypes.gen import STKUtil"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Create a new scenario\n",
"stkRoot.NewScenario(\"Python_AER_Polar_Plot\")\n",
"scenario = stkRoot.CurrentScenario\n",
"scenario2 = scenario.QueryInterface(STKObjects.IAgScenario)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Add a satellite\n",
"satellite = scenario.Children.New(STKObjects.eSatellite, \"MySatellite\")\n",
"satellite2 = satellite.QueryInterface(STKObjects.IAgSatellite)\n",
"\n",
"#Set and get the propagator\n",
"satellite2.SetPropagatorType(STKObjects.ePropagatorTwoBody)\n",
"twoBodyProp = satellite2.Propagator.QueryInterface(STKObjects.IAgVePropagatorTwoBody)\n",
"\n",
"#Get initial state and change the inclination\n",
"initialState = twoBodyProp.InitialState.Representation.ConvertTo(STKUtil.eOrbitStateClassical).QueryInterface(STKObjects.IAgOrbitStateClassical)\n",
"initialState.Orientation.Inclination = 60\n",
"\n",
"#Assign initial state and propagate\n",
"twoBodyProp.InitialState.Representation.Assign(initialState)\n",
"twoBodyProp.Propagate()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Add a default facility\n",
"facility = scenario.Children.New(STKObjects.eFacility, \"MyFacility\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Compute access\n",
"access = facility.GetAccessToObject(satellite)\n",
"access.ComputeAccess()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Get all the access interval start and stop times\n",
"accessReport = access.DataProviders.Item(\"Access Data\").QueryInterface(STKObjects.IAgDataPrvInterval)\n",
"accessIntervals = accessReport.ExecElements(scenario2.StartTime, scenario2.Stoptime, [\"Access Number\",\"Start Time\", \"Stop Time\"])\n",
"accessIntervals = list(accessIntervals.DataSets.ToArray())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Get Az El data for each access interval\n",
"aerData = []\n",
"for accessInterval in accessIntervals:\n",
" aerReport = access.DataProviders.GetDataPrvInfoFromPath(\"AER Data/Default\").QueryInterface(STKObjects.IAgDataPrvTimeVar).ExecElements(accessInterval[1], accessInterval[2], 20, [\"Azimuth\", \"Elevation\"])\n",
" aerData.append(list(aerReport.DataSets.ToArray()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Plot Az El for each interval on a polar plot with North up.\n",
"figure = plt.figure(figsize=(12,7.5))\n",
"axes = plt.axes(projection=\"polar\")\n",
"axes.set_theta_zero_location(\"N\")\n",
"axes.set_theta_direction(-1) #Theta increase clockwise\n",
"axes.set_rgrids(range(-90,1,15), labels=[\"\",\"75\"+u\"\\u00b0\",\"60\"+u\"\\u00b0\",\"45\"+u\"\\u00b0\",\"30\"+u\"\\u00b0\",\"15\"+u\"\\u00b0\"], angle=90) #Custom ticks\n",
"axes.set_rlim(-90,0) #set hard limits on r values\n",
"axes.set_title(\"Az El Polar Plot MyFacility-MySatellite\")\n",
"for aer, accessInterval in zip(aerData, accessIntervals):\n",
" aer = np.array(aer)\n",
" az = np.deg2rad(aer[:,0]) #convert azimuth from deg to rad\n",
" el = -aer[:,1] #plot the negative of elevation\n",
" \n",
" axes.plot(az[0],el[0], 'g^', markersize=15, clip_on=False) #mark rise location with green up\n",
" axes.plot(az[1:-1],el[1:-1], label=f\"{accessInterval[1][:-10]} - {accessInterval[2][:-10]}\", linewidth=4)\n",
" axes.plot(az[-1],el[-1], 'rv', markersize=15, clip_on=False) #mark set location with red down\n",
"\n",
"legend = figure.legend()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
161 changes: 161 additions & 0 deletions StkAutomation/Python/AzEl Polar Plots/AzElPolarPlot_win32com.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Imports\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import win32com.client"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Open STK, get the IAgSTKObjectRoot\n",
"uiApplication = win32com.client.Dispatch(\"STK12.Application\")\n",
"uiApplication.Visible=True\n",
"stkRoot = uiApplication.Personality2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Create a new scenario\n",
"stkRoot.NewScenario(\"Python_AER_Polar_Plot\")\n",
"scenario = stkRoot.CurrentScenario"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Add a satellite\n",
"satellite = scenario.Children.New(18, \"MySatellite\") #eSatellite\n",
"\n",
"#Set and get the propagator\n",
"satellite.SetPropagatorType(7) #ePropagatorTwoBody)\n",
"twoBodyProp = satellite.Propagator\n",
"\n",
"#Get initial state and change the inclination\n",
"initialState = twoBodyProp.InitialState.Representation.ConvertTo(1) #eOrbitStateClassical\n",
"initialState.Orientation.Inclination = 60\n",
"\n",
"#Assign initial state and propagate\n",
"twoBodyProp.InitialState.Representation.Assign(initialState)\n",
"twoBodyProp.Propagate()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Add a default facility\n",
"facility = scenario.Children.New(8, \"MyFacility\") #eFacility"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Compute access\n",
"access = facility.GetAccessToObject(satellite)\n",
"access.ComputeAccess()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Get all the access interval start and stop times\n",
"accessReport = access.DataProviders.Item(\"Access Data\")\n",
"accessIntervals = accessReport.ExecElements(scenario.StartTime, scenario.Stoptime, [\"Access Number\",\"Start Time\", \"Stop Time\"])\n",
"accessIntervals = list(accessIntervals.DataSets.ToArray())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Get Az El data for each access interval\n",
"aerData = []\n",
"for accessInterval in accessIntervals:\n",
" aerReport = access.DataProviders.GetDataPrvInfoFromPath(\"AER Data/Default\").ExecElements(accessInterval[1], accessInterval[2], 20, [\"Azimuth\", \"Elevation\"])\n",
" aerData.append(list(aerReport.DataSets.ToArray()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Plot Az El for each interval on a polar plot with North up.\n",
"figure = plt.figure(figsize=(12,7.5))\n",
"axes = plt.axes(projection=\"polar\")\n",
"axes.set_theta_zero_location(\"N\")\n",
"axes.set_theta_direction(-1) #Theta increase clockwise\n",
"axes.set_rgrids(range(-90,1,15), labels=[\"\",\"75\"+u\"\\u00b0\",\"60\"+u\"\\u00b0\",\"45\"+u\"\\u00b0\",\"30\"+u\"\\u00b0\",\"15\"+u\"\\u00b0\"], angle=90) #Custom ticks\n",
"axes.set_rlim(-90,0) #set hard limits on r values\n",
"axes.set_title(\"Az El Polar Plot MyFacility-MySatellite\")\n",
"for aer, accessInterval in zip(aerData, accessIntervals):\n",
" aer = np.array(aer)\n",
" az = np.deg2rad(aer[:,0]) #convert azimuth from deg to rad\n",
" el = -aer[:,1] #plot the negative of elevation\n",
" \n",
" axes.plot(az[0],el[0], 'g^', markersize=15, clip_on=False) #mark rise location with green up\n",
" axes.plot(az[1:-1],el[1:-1], label=f\"{accessInterval[1][:-10]} - {accessInterval[2][:-10]}\", linewidth=4)\n",
" axes.plot(az[-1],el[-1], 'rv', markersize=15, clip_on=False) #mark set location with red down\n",
"\n",
"legend = figure.legend()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
5 changes: 5 additions & 0 deletions StkAutomation/Python/AzEl Polar Plots/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Az El Polar Plot

A basic example that demonstrates automating STK with python via either comtypes or win32com. The script creates a scenario, inserts a satellite and facility. Then access is calculated and azimuth and elevation data is extrated for each of the computed access intervals. This data is then plotted on a polar plot.

To run this example you will need: either comtypes or win32com, numpy, and matplotlib.