forked from mdmzero0/JSatTrak
-
Notifications
You must be signed in to change notification settings - Fork 2
/
noGUIscript.bsh
176 lines (142 loc) · 7.36 KB
/
noGUIscript.bsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Shawn Gano
// 13 Nov 2008
// example onetime run script
// to run: java -splash:none -jar JSatTrak.jar noGUIscript.bsh
// or: java -splash:none -jar JSatTrak.jar "full/path/to/noGUIscript.bsh"
import jsattrak.objects.*;
import jsattrak.gui.*;
import javax.swing.Icon;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.*;
import name.gano.file.SaveImageFile;
// time is auto set to current system time -- so we don't have to worry about that (rounded to nearest second)
// REMOVE ISS!!! (it is added at the start by default)
jsattrak.getSatHash().remove("ISS (ZARYA) ");
// add the satellite desired (use exact name specified in TLE with extra spaces if needed, total length = 24 chars)
jsattrak.addSat2ListByName("EGP ");
AbstractSatellite sat = jsattrak.satHash.get("EGP "); // get satellite object
// create and add a Ground station
String gsName = "Ground Station";
double[] lla = new double[] {47.0,8.0,1596.0}; // latitude (deg), longitude (deg), altitude (me) of ground station
GroundStation gs = new GroundStation(gsName,lla,jsattrak.getCurrentJulianDate().getJulianDate());
jsattrak.getGsHash().put(gsName, gs); // add the ground station
//======================================================================================
// get the sats current lat/lon/alt and output to a file ===============================
//======================================================================================
double lat = sat.getLatitude()*180.0/Math.PI; // deg
double lon = sat.getLongitude()*180.0/Math.PI; // deg
double alt = sat.getAltitude(); // meters
try {
//PrintWriter txtWriter = new PrintWriter(new FileWriter("CurrentLLA.txt")); // file name and path of text file
BufferedWriter txtWriter = new BufferedWriter(new FileWriter("CurrentLLA.txt"));
txtWriter.write(sat.getName());
txtWriter.newLine();
txtWriter.write(jsattrak.getCurrentJulianDate().getDateTimeStr());
txtWriter.newLine();
txtWriter.write("" + lat);
txtWriter.newLine();
txtWriter.write("" + lon);
txtWriter.newLine();
txtWriter.write("" + alt);
txtWriter.newLine();
txtWriter.close();
}catch(Exception e){ System.err.println(e.toString);}
//======================================================================================
// 2D image - setup and save to a file =================================================
//======================================================================================
// image size (width = 2* height) pixels
int height = 333;
// create a 2D panel that can be used for offscreen rendering
J2DEarthPanel earthPanel = jsattrak.getNonDisplayed2DEarthPanel(height);
// 2D drawing Options
earthPanel.setTwoDMap("data/pixmaps/Earth_PE_b.jpg"); // change the default background (goes better with the night lights)
earthPanel.setShowLatLonLines(false); // show or not lat/lon lines
earthPanel.setDrawSun(false); // turn off standard darkness drawing
earthPanel.setShowEarthLightsMask(true); // turn on fancy earth lights and darkness drawing (time intensive)
// satellite and ground station display options
sat.setSatColor(Color.WHITE); // color used in plotting
gs.setStationColor(Color.GREEN);
// paint image
BufferedImage buff = earthPanel.offScreenRender();
// save image
String fileName = "TEST"; // do not add extension
String imageExtension = "jpg"; // can be png, jpg, gif -- make change on next line too (compression parameter only effects jpg), png looks best but is large
String imagePath = ""; // absolute path (include final "/"), if blank defaults to JSatTrak root directory
File file = new File(imagePath+fileName+"."+imageExtension);
Exception e = SaveImageFile.saveImage(imageExtension, file, buff, 0.9f); // the last one is the compression quality (1=best)
if(e != null)
{
System.err.println("Error Saving 2D Image:" + e.toString() );
}
//======================================================================================
// Pass predictions and Polar Plot Generation for each Pass ============================
//======================================================================================
// open tracking tool and get its handle
JTrackingPanel trackPanel = jsattrak.openTrackingToolSelectorWindow();
// since there is only one sat and ground station they are automatically used, but to be sure and to be explicit
trackPanel.setGroundStation(gs);
trackPanel.setSatellite(sat);
// solver settings
trackPanel.setTimeSpanDays(10);
trackPanel.setTimeStepSec(60);
trackPanel.setVisibleOnlyFilter(false); // set to true if you want only visible pass results
// run solver
trackPanel.runPassPrediction();
// write results to a file
txtWriter = new BufferedWriter(new FileWriter("PassPredictions.txt"));
// data[rows][column] columns = pass number, time/date pass starts, time/date pass ends, pass durration (sec), pass type
String[][] data = trackPanel.getPredictionTableData();
try
{
for(String[] d : data)
{
for(String d2 : d)
{
txtWriter.write(d2 + " ");
}
txtWriter.newLine();
}
txtWriter.close();
}
catch(Exception e){ System.err.println(e.toString);}
// polar plot settings
int polarWidth = 350;
int polarHeight = polarWidth;
trackPanel.getPolarPlotLabel().setDisplayTime(true);
trackPanel.getPolarPlotLabel().setShowLeadLagData(true);
trackPanel.getPolarPlotLabel().setDisplayNames(false);
String polarFileName = "polar"; // do not add extension
String polarImageExtension = "gif"; // can be png, jpg, gif -- make change on next line too (compression parameter only effects jpg)
String polarImagePath = "polar/"; // absolute path (include final "/"), if blank defaults to JSatTrak root directory
int maxFuturePassPlotsCreated = 5; // to save time only create this many future pass plots (set to a high number like 1000 if all plots are wanted)
// get current polar plot, save to file
buff = trackPanel.getPolarPlotLabel().renderPolarPlotOffScreen(polarWidth, polarHeight);
boolean success = (new File(polarImagePath)).mkdir(); // TEMP!! This may need to be removed not using this directory structure
File polarFile = new File(polarImagePath+polarFileName+"_current."+polarImageExtension);
Exception e = SaveImageFile.saveImage(polarImageExtension, polarFile, buff, 0.9f); // the last one is the compression quality (1=best)
if(e != null)
{
System.err.println("Error Saving polar Image:" + e.toString() );
}
// run through all passes and save polar plot
// Careful files are appended with the pass number not the pass count, this might be different if visible pass filter is used
int passCount = 0;
for(String[] d : data) // for each row of pass data
{
trackPanel.go2pass(passCount); // changes sim time to be the mid point of pass
buff = trackPanel.getPolarPlotLabel().renderPolarPlotOffScreen(polarWidth, polarHeight); // render image
// save image
polarFile = new File(polarImagePath+polarFileName+"_pass"+d[0].toString()+"."+polarImageExtension);
Exception e = SaveImageFile.saveImage(polarImageExtension, polarFile, buff, 0.9f); // the last one is the compression quality (1=best)
if(e != null)
{
System.err.println("Error Saving polar Image:" + e.toString() );
}
passCount++;
if(passCount >= maxFuturePassPlotsCreated)
{
break;
}
}