Skip to content

Commit

Permalink
Merge pull request #2 from ennehekma/add_departure_epoch_loop
Browse files Browse the repository at this point in the history
Add departure epoch loop in lambert_scanner and update plot script.
  • Loading branch information
kartikkumar committed Mar 10, 2016
2 parents b65df19 + 0a97391 commit fbb44df
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 244 deletions.
3 changes: 3 additions & 0 deletions config/lambert_scanner.json.empty
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
// If departure_epoch array is left empty, the TLE epoch for the departure object is assumed.
"departure_epoch" : [],

// Set departure epoch grid: [range (s), # of steps].
"departure_epoch_grid" : [,],

// Set time-of-flight grid: [min (s), max (s), # of steps].
"time_of_flight_grid" : [,,],

Expand Down
44 changes: 28 additions & 16 deletions include/D2D/lambertScanner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ struct LambertScannerInput
* Constructs data struct based on verified input parameters.
*
* @sa checkLambertScannerInput, executeLambertScanner
* @param[in] aCatalogPath Path to TLE catalog
* @param[in] aDatabasePath Path to SQLite database
* @param[in] aDepartureEpoch Departure epoch for all transfers
* @param[in] aTimeOfFlightMinimum Minimum time-of-flight [s]
* @param[in] aTimeOfFlightMaximum Maximum time-of-flight [s]
* @param[in] someTimeOfFlightSteps Number of steps to take in time-of-flight grid
* @param[in] aTimeOfFlightStepSize Time-of-flight step size (derived parameter) [s]
* @param[in] progradeFlag Flag indicating if prograde transfer should be computed
* (false = retrograde)
* @param[in] aRevolutionsMaximum Maximum number of revolutions
* @param[in] aShortlistLength Number of transfers to include in shortlist
* @param[in] aShortlistPath Path to shortlist file
* @param[in] aCatalogPath Path to TLE catalog
* @param[in] aDatabasePath Path to SQLite database
* @param[in] aDepartureEpochInitial Departure epoch grid initial epoch
* @param[in] someDepartureEpochSteps Number of steps to take in departure epoch grid
* @param[in] aDepartureEpochStepSize Departure epoch grid step size (derived parameter) [s]
* @param[in] aTimeOfFlightMinimum Minimum time-of-flight [s]
* @param[in] aTimeOfFlightMaximum Maximum time-of-flight [s]
* @param[in] someTimeOfFlightSteps Number of steps to take in time-of-flight grid
* @param[in] aTimeOfFlightStepSize Time-of-flight step size (derived parameter) [s]
* @param[in] progradeFlag Flag indicating if prograde transfer should be computed
* (false = retrograde)
* @param[in] aRevolutionsMaximum Maximum number of revolutions
* @param[in] aShortlistLength Number of transfers to include in shortlist
* @param[in] aShortlistPath Path to shortlist file
*/
LambertScannerInput( const std::string& aCatalogPath,
const std::string& aDatabasePath,
const DateTime& aDepartureEpoch,
const DateTime& aDepartureEpochInitial,
const double someDepartureEpochSteps,
const double aDepartureEpochStepSize,
const double aTimeOfFlightMinimum,
const double aTimeOfFlightMaximum,
const double someTimeOfFlightSteps,
Expand All @@ -78,7 +82,9 @@ struct LambertScannerInput
const std::string& aShortlistPath )
: catalogPath( aCatalogPath ),
databasePath( aDatabasePath ),
departureEpoch( aDepartureEpoch ),
departureEpochInitial( aDepartureEpochInitial ),
departureEpochSteps( someDepartureEpochSteps ),
departureEpochStepSize( aDepartureEpochStepSize ),
timeOfFlightMinimum( aTimeOfFlightMinimum ),
timeOfFlightMaximum( aTimeOfFlightMaximum ),
timeOfFlightSteps( someTimeOfFlightSteps ),
Expand All @@ -95,8 +101,14 @@ struct LambertScannerInput
//! Path to SQLite database to store output.
const std::string databasePath;

//! Departure epoch.
const DateTime departureEpoch;
//! Initial departure epoch.
const DateTime departureEpochInitial;

//! Number of departure epoch steps.
const double departureEpochSteps;

//! Departure epoch grid step size.
const double departureEpochStepSize;

//! Minimum time-of-flight [s].
const double timeOfFlightMinimum;
Expand Down
145 changes: 79 additions & 66 deletions python/plot_lambert_scan_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
print "------------------------------------------------------------------"
print " D2D "
print " 0.0.2 "
print " Copyright (c) 2015, K. Kumar ([email protected]) "
print " Copyright (c) 2015-2016, K. Kumar ([email protected]) "
print " Copyright (c) 2016, E.J. Hekma ([email protected]) "
print "------------------------------------------------------------------"
print ""

Expand Down Expand Up @@ -73,75 +74,87 @@
print "Error %s:" % e.args[0]
sys.exit(1)

# Fetch scan data.
map_order = "departure_" + config['map_order']
scan_data = pd.read_sql("SELECT departure_object_id, arrival_object_id, min(transfer_delta_v) \
FROM lambert_scanner_results \
GROUP BY departure_object_id, arrival_object_id;", \
database)
scan_data.columns = ['departure_object_id','arrival_object_id','transfer_delta_v']
scan_map = scan_data.pivot(index='departure_object_id', \
columns='arrival_object_id', \
values='transfer_delta_v')
scan_order = pd.read_sql("SELECT DISTINCT departure_object_id, " + map_order + " \
FROM lambert_scanner_results \
ORDER BY " + map_order + " ASC", \
database)
scan_map = scan_map.reindex(index=scan_order['departure_object_id'], \
columns=scan_order['departure_object_id'])

# Close SQLite database if it's still open.
if database:
database.close()

print "Plotting heat map ..."

# Plot heat map.

# Set up color map.
bins = np.linspace(scan_data['transfer_delta_v'].min(), scan_data['transfer_delta_v'].max(), 10)
groups = scan_data['transfer_delta_v'].groupby(np.digitize(scan_data['transfer_delta_v'], bins))
levels = groups.mean().values
cmap_lin = plt.get_cmap(config['colormap'])
cmap = nlcmap(cmap_lin, levels)

# Plot heat map.
ax1 = plt.subplot2grid((15,15), (2, 0),rowspan=13,colspan=14)
heatmap = ax1.pcolormesh(scan_map.values, cmap=cmap, \
vmin=scan_data['transfer_delta_v'].min(), \
vmax=scan_data['transfer_delta_v'].max())
ax1.set_xticks(np.arange(scan_map.shape[1] + 1)+0.5)
ax1.set_xticklabels(scan_map.columns, rotation=90)
ax1.set_yticks([])
ax1.tick_params(axis='both', which='major', labelsize=config['tick_label_size'])
ax1.set_xlim(0, scan_map.shape[1])
ax1.set_ylim(0, scan_map.shape[0])
ax1.set_xlabel('Departure object',fontsize=config['axis_label_size'])
ax1.set_ylabel('Arrival object',fontsize=config['axis_label_size'])

# Plot axis ordering.
ax2 = plt.subplot2grid((15,15), (0, 0),rowspan=2,colspan=14,sharex=ax1)
ax2.plot(scan_order[str(map_order)],'k',linewidth=2.0)
ax2.get_yaxis().set_major_formatter(plt.FormatStrFormatter('%.2e'))
ax2.tick_params(axis='both', which='major', labelsize=config['tick_label_size'])
plt.setp(ax2.get_xticklabels(), visible=False)
ax2.set_ylabel(config['map_order_axis_label'],fontsize=config['axis_label_size'])

# Plot color bar.
ax3 = plt.subplot2grid((15,15), (0, 14), rowspan=15)
color_bar = plt.colorbar(heatmap,cax=ax3)
color_bar.ax.get_yaxis().labelpad = 20
color_bar.ax.set_ylabel(r'Total transfer $\Delta V$ [km/s]', rotation=270)

plt.tight_layout()

# Save figure to file.
plt.savefig(config["output_directory"] + "/" + config["scan_figure"] + ".pdf", \
dpi=config["figure_dpi"])
departure_epochs = pd.read_sql("SELECT DISTINCT departure_epoch \
FROM lambert_scanner_results;", \
database)
for i in xrange(0,departure_epochs.size):
c = departure_epochs['departure_epoch'][i]
print "Plotting scan map with departure epoch: ",c,"Julian Date"

# Fetch scan data.
map_order = "departure_" + config['map_order']
scan_data = pd.read_sql("SELECT departure_object_id, arrival_object_id, \
min(transfer_delta_v), "+ map_order + " \
FROM lambert_scanner_results \
WHERE departure_epoch BETWEEN " + str(c-0.00001) + " \
AND "+str(c+0.00001) +" \
GROUP BY departure_object_id, arrival_object_id;", \
database)
scan_data.columns = ['departure_object_id','arrival_object_id', \
'transfer_delta_v',str(map_order)]
scan_order = scan_data.sort_values(str(map_order)) \
.drop_duplicates('departure_object_id')[ \
['departure_object_id',str(map_order)]]

scan_map = scan_data.pivot(index='departure_object_id', \
columns='arrival_object_id',
values='transfer_delta_v')
scan_map = scan_map.reindex(index=scan_order['departure_object_id'], \
columns=scan_order['departure_object_id'])

# Set up color map.
bins = np.linspace(scan_data['transfer_delta_v'].min(), \
scan_data['transfer_delta_v'].max(), 10)
groups = scan_data['transfer_delta_v'].groupby( \
np.digitize(scan_data['transfer_delta_v'], bins))
levels = groups.mean().values
cmap_lin = plt.get_cmap(config['colormap'])
cmap = nlcmap(cmap_lin, levels)

# Plot heat map.
ax1 = plt.subplot2grid((15,15), (2, 0),rowspan=13,colspan=14)
heatmap = ax1.pcolormesh(scan_map.values, cmap=cmap, \
vmin=scan_data['transfer_delta_v'].min(), \
vmax=scan_data['transfer_delta_v'].max())
ax1.set_xticks(np.arange(scan_map.shape[1] + 1)+0.5)
ax1.set_xticklabels(scan_map.columns, rotation=90)
ax1.set_yticks([])
ax1.tick_params(axis='both', which='major', labelsize=config['tick_label_size'])
ax1.set_xlim(0, scan_map.shape[1])
ax1.set_ylim(0, scan_map.shape[0])
ax1.set_xlabel('Departure object',fontsize=config['axis_label_size'])
ax1.set_ylabel('Arrival object',fontsize=config['axis_label_size'])

# Plot axis ordering.
ax2 = plt.subplot2grid((15,15), (0, 0),rowspan=2,colspan=14,sharex=ax1)
ax2.step(np.arange(0.5,scan_map.shape[1]+.5),scan_order[str(map_order)],'k',linewidth=2.0)
ax2.get_yaxis().set_major_formatter(plt.FormatStrFormatter('%.2e'))
ax2.tick_params(axis='both', which='major', labelsize=config['tick_label_size'])
plt.setp(ax2.get_xticklabels(), visible=False)
ax2.set_ylabel(config['map_order_axis_label'],fontsize=config['axis_label_size'])

# Plot color bar.
ax3 = plt.subplot2grid((15,15), (0, 14), rowspan=15)
color_bar = plt.colorbar(heatmap,cax=ax3)
color_bar.ax.get_yaxis().labelpad = 20
color_bar.ax.set_ylabel(r'Total transfer $\Delta V$ [km/s]', rotation=270)

plt.tight_layout()

# Save figure to file.
plt.savefig(config["output_directory"] + "/" + config["scan_figure"] + "_"+str(i+1) + \
".png", dpi=config["figure_dpi"])
plt.close()
print "Figure ",i+1," generated successfully...."

print "Figure generated successfully!"
print ""

# Close SQLite database if it's still open.
if database:
database.close()

# Stop timer
end_time = time.time( )

Expand All @@ -152,4 +165,4 @@
print "------------------------------------------------------------------"
print " Exited successfully! "
print "------------------------------------------------------------------"
print ""
print ""
2 changes: 1 addition & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
commentjson==0.4
matplotlib==1.4.2
pandas==0.15.2
pandas==0.17.1
scipy==0.14.1
Loading

0 comments on commit fbb44df

Please sign in to comment.