From e93e549e42c93dfad1bab9dc55d2d523144177c8 Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Wed, 11 May 2016 16:59:29 +0200 Subject: [PATCH 01/10] Bug fix - manual set_axes feature --- python/plot_hist_sgp4Scan.py | 37 +++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index ba19d0b..c96b7db 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -201,9 +201,9 @@ def plotComponents( errorX, errorY, errorZ, print "Using user defined axes limits" print "" plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) xLegend = mlines.Line2D( [], [], color=xcolor, label=xlegend ) yLegend = mlines.Line2D( [], [], color=ycolor, label=ylegend ) @@ -279,6 +279,10 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesLowerLimit = config['set_axes_velocity'][ 2 ] yAxesUpperLimit = config['set_axes_velocity'][ 3 ] + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + if xAxesLowerLimit != 0 \ or xAxesUpperLimit != 0 \ or yAxesLowerLimit != 0 \ @@ -288,10 +292,6 @@ def plotComponentsMarkers( errorX, errorY, errorZ, ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) - xmin, xmax, ymin, ymax = ax.axis('auto') - ax.set_xlim( xmin, xmax ) - ax.set_ylim( ymin, ymax ) - plt.legend( ) plt.grid( True ) @@ -405,6 +405,17 @@ def plotComponentsMarkers( errorX, errorY, errorZ, n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ normed=False, color=j2CurveColor, alpha=1, label='J2' ) + if xAxesLowerLimit != 0 \ + or xAxesUpperLimit != 0 \ + or yAxesLowerLimit != 0 \ + or yAxesUpperLimit != 0: + print "Using user defined axes limits" + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) + j2Legend = mlines.Line2D( [], [], color=j2CurveColor, label='J2' ) magnitudeLegend = mpatches.Patch( color=figureColor, label='Magnitude' ) lines = [ magnitudeLegend, j2Legend ] @@ -413,6 +424,18 @@ def plotComponentsMarkers( errorX, errorY, errorZ, else: n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ facecolor=figureColor, alpha=1, label='Magnitude' ) + + if xAxesLowerLimit != 0 \ + or xAxesUpperLimit != 0 \ + or yAxesLowerLimit != 0 \ + or yAxesUpperLimit != 0: + print "Using user defined axes limits" + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) + # plt.legend( ) # Select appropriate unit and title for the error type From 91dd961d3374cdf99137ffed787af3a420690a16 Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Wed, 11 May 2016 18:15:18 +0200 Subject: [PATCH 02/10] Add manual set axes feature for position/velocity magnitude/component --- config/plot_hist_sgp4Scan.json.empty | 48 ++++++--- python/plot_hist_sgp4Scan.py | 150 ++++++++++++++++----------- 2 files changed, 121 insertions(+), 77 deletions(-) diff --git a/config/plot_hist_sgp4Scan.json.empty b/config/plot_hist_sgp4Scan.json.empty index 027fdf0..6f00f31 100644 --- a/config/plot_hist_sgp4Scan.json.empty +++ b/config/plot_hist_sgp4Scan.json.empty @@ -5,56 +5,70 @@ // See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT { // Path to SQLite database containing scan data. - "database" : "", + "database" : "", // Directory where the histogram is stored. // Do not add a '/' at the end of the output dierectory. - "output_directory" : "", + "output_directory" : "", // Filename for histogram. // Do not mention error type in the file name, it will automatically be included by the python // plotting script. - "histogram_figure" : "", + "histogram_figure" : "", // Add or remove j2 analysis curve in position and velocity error histogram plots. // Put True to add the j2 curve, else False. - "add_j2" : "", + "add_j2" : "", // Set reference frame for histogram plot of the error components. // For Earth-Centered Inertial, use "ECI". // For Radial-Tangen-Normal reference frame, use "RTN" - "frame" : "", + "frame" : "", // Set plot style for error component plots // Set to "True" for plot with lines and markers // Set to "False" for a histogram step plot with small bin size - "component_marker" : "", + "component_marker" : "", // Set output format for the figure (example: ".pdf", ".png") - "figure_format" : "", + "figure_format" : "", // Add or remove figure title. // To add a title to the figure, put True otherwise False. - "add_title" : "", + "add_title" : "", // Check for GUI // If user machine has a display/GUI then put True, else False - "display" : "", + "display" : "", // Set colortype for the figures. // For grayscale, put True otherwise False - "grayscale" : "", + "grayscale" : "", - // Set axes limit for the position and velocity error component's histogram plot + // Choose plot type for which axes limits have to be set manually. + // Ensure that if any of the options below is "TRUE", then set non zero limits for the + // corresponding "set_axes_position" and "set_axes_velocity" parameters in the next section. + // Set "set_axes_component_position_flag" and/or "set_axes_component_velocity_flag" to "True" + // if manual limits have to be applied to the components plots, set "False" otherwise. + // Set "set_axes_magnitude_position_flag" and/or "set_axes_magnitude_velocity_flag" to "True" + // if manual limits have to be applied to the magnitude plots, set "False" otherwise + "set_axes_position_component_flag" : "", + "set_axes_velocity_component_flag" : "", + "set_axes_position_magnitude_flag" : "", + "set_axes_velocity_magnitude_flag" : "", + + // Set axes limit for the position and velocity error plots (magnitude and/or component) // Format: [xmin, xmax, ymin, ymax] // Auto sizing feature for the axes will be used if all the fields // inside the square bracket are made zero. - "set_axes_position" : [,,,], - "set_axes_velocity" : [,,,], + "set_axes_position_component" : [,,,], + "set_axes_velocity_component" : [,,,], + "set_axes_position_magnitude" : [,,,], + "set_axes_velocity_magnitude" : [,,,], // Characteristics for figures. - "figure_dpi" : 300, - "tick_label_size" : 4, - "axis_label_size" : 10, - "colormap" : "jet" + "figure_dpi" : 300, + "tick_label_size" : 4, + "axis_label_size" : 10, + "colormap" : "jet" } diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index c96b7db..3d0b09b 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -183,27 +183,29 @@ def plotComponents( errorX, errorY, errorZ, if config[ 'add_title' ] == 'True': plt.title( plotTitle ) - if flag == True: - xAxesLowerLimit = config['set_axes_position'][ 0 ] - xAxesUpperLimit = config['set_axes_position'][ 1 ] - yAxesLowerLimit = config['set_axes_position'][ 2 ] - yAxesUpperLimit = config['set_axes_position'][ 3 ] - else: - xAxesLowerLimit = config['set_axes_velocity'][ 0 ] - xAxesUpperLimit = config['set_axes_velocity'][ 1 ] - yAxesLowerLimit = config['set_axes_velocity'][ 2 ] - yAxesUpperLimit = config['set_axes_velocity'][ 3 ] - - if xAxesLowerLimit != 0 \ - or xAxesUpperLimit != 0 \ - or yAxesLowerLimit != 0 \ - or yAxesUpperLimit != 0: - print "Using user defined axes limits" - print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + if flag == True and config['set_axes_position_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_position_component'][ 0 ] + xAxesUpperLimit = config['set_axes_position_component'][ 1 ] + yAxesLowerLimit = config['set_axes_position_component'][ 2 ] + yAxesUpperLimit = config['set_axes_position_component'][ 3 ] + print "Using user defined axes limits for position component plot..." + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) + + if flag == False and config['set_axes_velocity_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_component'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_component'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] + print "Using user defined axes limits for velocity component plot..." + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) xLegend = mlines.Line2D( [], [], color=xcolor, label=xlegend ) yLegend = mlines.Line2D( [], [], color=ycolor, label=ylegend ) @@ -268,29 +270,29 @@ def plotComponentsMarkers( errorX, errorY, errorZ, if config[ 'add_title' ] == 'True': plt.title( plotTitle ) - if flag == True: - xAxesLowerLimit = config['set_axes_position'][ 0 ] - xAxesUpperLimit = config['set_axes_position'][ 1 ] - yAxesLowerLimit = config['set_axes_position'][ 2 ] - yAxesUpperLimit = config['set_axes_position'][ 3 ] - else: - xAxesLowerLimit = config['set_axes_velocity'][ 0 ] - xAxesUpperLimit = config['set_axes_velocity'][ 1 ] - yAxesLowerLimit = config['set_axes_velocity'][ 2 ] - yAxesUpperLimit = config['set_axes_velocity'][ 3 ] - xmin, xmax, ymin, ymax = ax.axis('auto') ax.set_xlim( xmin, xmax ) ax.set_ylim( ymin, ymax ) - if xAxesLowerLimit != 0 \ - or xAxesUpperLimit != 0 \ - or yAxesLowerLimit != 0 \ - or yAxesUpperLimit != 0: - print "Using user defined axes limits" - print "" - ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) - ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + if flag == True and config['set_axes_position_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_position_component'][ 0 ] + xAxesUpperLimit = config['set_axes_position_component'][ 1 ] + yAxesLowerLimit = config['set_axes_position_component'][ 2 ] + yAxesUpperLimit = config['set_axes_position_component'][ 3 ] + print "Using user defined axes limits for position component plot..." + print "" + ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) + ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + + if flag == False and config['set_axes_velocity_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_component'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_component'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] + print "Using user defined axes limits for velocity component plot..." + print "" + ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) + ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) plt.legend( ) plt.grid( True ) @@ -405,16 +407,30 @@ def plotComponentsMarkers( errorX, errorY, errorZ, n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ normed=False, color=j2CurveColor, alpha=1, label='J2' ) - if xAxesLowerLimit != 0 \ - or xAxesUpperLimit != 0 \ - or yAxesLowerLimit != 0 \ - or yAxesUpperLimit != 0: - print "Using user defined axes limits" - print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + if errorType[ errorTypeIndex ] == 'arrival_position': + if config[ 'set_axes_position_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] + print "Using user defined axes limits for position magnitude plot..." + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) + else: + if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] + print "Using user defined axes limits for velocity magnitude plot..." + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) j2Legend = mlines.Line2D( [], [], color=j2CurveColor, label='J2' ) magnitudeLegend = mpatches.Patch( color=figureColor, label='Magnitude' ) @@ -425,16 +441,30 @@ def plotComponentsMarkers( errorX, errorY, errorZ, n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ facecolor=figureColor, alpha=1, label='Magnitude' ) - if xAxesLowerLimit != 0 \ - or xAxesUpperLimit != 0 \ - or yAxesLowerLimit != 0 \ - or yAxesUpperLimit != 0: - print "Using user defined axes limits" - print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + if errorType[ errorTypeIndex ] == 'arrival_position': + if config[ 'set_axes_position_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] + print "Using user defined axes limits for position magnitude plot..." + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) + else: + if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] + print "Using user defined axes limits for velocity magnitude plot..." + print "" + plt.axis([xAxesLowerLimit, \ + xAxesUpperLimit, \ + yAxesLowerLimit, \ + yAxesUpperLimit]) # plt.legend( ) From 8a3f75c4c0b48406cedd5d455de25b357f17c54a Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Wed, 11 May 2016 20:10:19 +0200 Subject: [PATCH 03/10] Modify magnitude plot's manual axes set feature --- config/plot_hist_sgp4Scan.json.empty | 9 +++- python/plot_hist_sgp4Scan.py | 78 +++++++++++++++++----------- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/config/plot_hist_sgp4Scan.json.empty b/config/plot_hist_sgp4Scan.json.empty index 6f00f31..03e8769 100644 --- a/config/plot_hist_sgp4Scan.json.empty +++ b/config/plot_hist_sgp4Scan.json.empty @@ -57,12 +57,19 @@ "set_axes_position_magnitude_flag" : "", "set_axes_velocity_magnitude_flag" : "", - // Set axes limit for the position and velocity error plots (magnitude and/or component) + // Set axes limit for the position and velocity error plots (component) // Format: [xmin, xmax, ymin, ymax] // Auto sizing feature for the axes will be used if all the fields // inside the square bracket are made zero. "set_axes_position_component" : [,,,], "set_axes_velocity_component" : [,,,], + + // Set axes limit for the position and velocity error plots (magnitude) + // Format: [xmin, xmax, ymin, ymax] + // Auto sizing feature for the axes will be used if all the fields + // inside the square bracket are made zero. + // Leave ymin and ymax fields as zero if only the x axes has to be set manually (The Y limits + // will then be set automatically) "set_axes_position_magnitude" : [,,,], "set_axes_velocity_magnitude" : [,,,], diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index 3d0b09b..ea79332 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -176,10 +176,6 @@ def plotComponents( errorX, errorY, errorZ, n, bins, patches = plt.hist( errorZ, bins=200, histtype='step', normed=False, \ color=zcolor, alpha=1, label=zlegend, log=False ) - # Figure properties - plt.xlabel( xAxisLabel ) - plt.ylabel( yAxisLabel ) - if config[ 'add_title' ] == 'True': plt.title( plotTitle ) @@ -207,6 +203,10 @@ def plotComponents( errorX, errorY, errorZ, yAxesLowerLimit, \ yAxesUpperLimit]) + # Figure properties + plt.xlabel( xAxisLabel ) + plt.ylabel( yAxisLabel ) + xLegend = mlines.Line2D( [], [], color=xcolor, label=xlegend ) yLegend = mlines.Line2D( [], [], color=ycolor, label=ylegend ) zLegend = mlines.Line2D( [], [], color=zcolor, label=zlegend ) @@ -257,23 +257,13 @@ def plotComponentsMarkers( errorX, errorY, errorZ, linestyle='solid', linewidth=2, color=zcolor, label=zlegend, \ marker='*', markersize=6, markerfacecolor=zcolor ) + markerFigure = plt.figure( ) ax = markerFigure.add_subplot( 1, 1, 1 ) ax.add_line( xMarkerLine ) ax.add_line( yMarkerLine ) ax.add_line( zMarkerLine ) - # Figure properties - plt.xlabel( xAxisLabel ) - plt.ylabel( yAxisLabel ) - - if config[ 'add_title' ] == 'True': - plt.title( plotTitle ) - - xmin, xmax, ymin, ymax = ax.axis('auto') - ax.set_xlim( xmin, xmax ) - ax.set_ylim( ymin, ymax ) - if flag == True and config['set_axes_position_component_flag'] == 'True': xAxesLowerLimit = config['set_axes_position_component'][ 0 ] xAxesUpperLimit = config['set_axes_position_component'][ 1 ] @@ -294,6 +284,19 @@ def plotComponentsMarkers( errorX, errorY, errorZ, ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + if config['set_axes_position_component_flag'] == 'False' \ + and config['set_axes_velocity_component_flag'] == 'False': + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + + # Figure properties + plt.xlabel( xAxisLabel ) + plt.ylabel( yAxisLabel ) + + if config[ 'add_title' ] == 'True': + plt.title( plotTitle ) + plt.legend( ) plt.grid( True ) @@ -402,10 +405,6 @@ def plotComponentsMarkers( errorX, errorY, errorZ, j2CurveColor = '1' if config['add_j2'] == "True": - n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ - normed=False, color=j2CurveColor, alpha=1, label='J2' ) if errorType[ errorTypeIndex ] == 'arrival_position': if config[ 'set_axes_position_magnitude_flag' ] == 'True': @@ -432,15 +431,17 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesLowerLimit, \ yAxesUpperLimit]) + n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ + normed=False, color=j2CurveColor, alpha=1, label='J2' ) + j2Legend = mlines.Line2D( [], [], color=j2CurveColor, label='J2' ) magnitudeLegend = mpatches.Patch( color=figureColor, label='Magnitude' ) lines = [ magnitudeLegend, j2Legend ] labels = [ line.get_label( ) for line in lines ] plt.legend( lines, labels ) else: - n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - if errorType[ errorTypeIndex ] == 'arrival_position': if config[ 'set_axes_position_magnitude_flag' ] == 'True': xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] @@ -449,10 +450,18 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] print "Using user defined axes limits for position magnitude plot..." print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + print "Using auto axes limits for position magnitude plot..." + print "" + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) else: if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] @@ -461,11 +470,18 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] print "Using user defined axes limits for velocity magnitude plot..." print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) - + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + print "Using auto axes limits for velocity magnitude plot..." + print "" + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) # plt.legend( ) # Select appropriate unit and title for the error type From 05e9e9fe56cfd531311a8b7e88e8bd79f4c61120 Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Wed, 11 May 2016 20:29:21 +0200 Subject: [PATCH 04/10] Add set axes feature for the j2 plots as well --- python/plot_hist_sgp4Scan.py | 47 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index ea79332..19f1427 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -412,30 +412,51 @@ def plotComponentsMarkers( errorX, errorY, errorZ, xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] - print "Using user defined axes limits for position magnitude plot..." + + print "Using user defined axes limits for position magnitude J2 plot..." print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + histtype='step', \ + normed=False, color=j2CurveColor, \ + alpha=1, label='J2' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ + normed=False, color=j2CurveColor, alpha=1, label='J2' ) else: if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] - print "Using user defined axes limits for velocity magnitude plot..." + print "Using user defined axes limits for velocity magnitude J2 plot..." print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) - - n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + histtype='step', \ + normed=False, color=j2CurveColor, \ + alpha=1, label='J2' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ facecolor=figureColor, alpha=1, label='Magnitude' ) - n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ + n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ normed=False, color=j2CurveColor, alpha=1, label='J2' ) + j2Legend = mlines.Line2D( [], [], color=j2CurveColor, label='J2' ) magnitudeLegend = mpatches.Patch( color=figureColor, label='Magnitude' ) lines = [ magnitudeLegend, j2Legend ] From 51b26ab62b3d8fc4bcb7363a420a4919cfba7bed Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Fri, 13 May 2016 11:57:27 +0200 Subject: [PATCH 05/10] Rectify set-manual-axes-limit feature for component plot (without markers) --- python/plot_hist_sgp4Scan.py | 60 +++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index 19f1427..1432556 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -169,16 +169,6 @@ def plotComponents( errorX, errorY, errorZ, xAxisLabel, yAxisLabel, plotTitle, \ flag ): - n, bins, patches = plt.hist( errorX, bins=200, histtype='step', normed=False, \ - color=xcolor, alpha=1, label=xlegend, log=False ) - n, bins, patches = plt.hist( errorY, bins=200, histtype='step', normed=False, \ - color=ycolor, alpha=1, label=ylegend, log=False ) - n, bins, patches = plt.hist( errorZ, bins=200, histtype='step', normed=False, \ - color=zcolor, alpha=1, label=zlegend, log=False ) - - if config[ 'add_title' ] == 'True': - plt.title( plotTitle ) - if flag == True and config['set_axes_position_component_flag'] == 'True': xAxesLowerLimit = config['set_axes_position_component'][ 0 ] xAxesUpperLimit = config['set_axes_position_component'][ 1 ] @@ -186,10 +176,20 @@ def plotComponents( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_position_component'][ 3 ] print "Using user defined axes limits for position component plot..." print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + n, bins, patches = plt.hist( errorX, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, \ + color=xcolor, alpha=1, label=xlegend, log=False ) + n, bins, patches = plt.hist( errorY, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, \ + color=ycolor, alpha=1, label=ylegend, log=False ) + n, bins, patches = plt.hist( errorZ, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, \ + color=zcolor, alpha=1, label=zlegend, log=False ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) if flag == False and config['set_axes_velocity_component_flag'] == 'True': xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] @@ -198,12 +198,36 @@ def plotComponents( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] print "Using user defined axes limits for velocity component plot..." print "" - plt.axis([xAxesLowerLimit, \ - xAxesUpperLimit, \ - yAxesLowerLimit, \ - yAxesUpperLimit]) + n, bins, patches = plt.hist( errorX, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, \ + color=xcolor, alpha=1, label=xlegend, log=False ) + n, bins, patches = plt.hist( errorY, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, \ + color=ycolor, alpha=1, label=ylegend, log=False ) + n, bins, patches = plt.hist( errorZ, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, \ + color=zcolor, alpha=1, label=zlegend, log=False ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + + if config['set_axes_velocity_component_flag'] == 'False' \ + and config['set_axes_position_component_flag'] == 'False': + n, bins, patches = plt.hist( errorX, bins=200, \ + histtype='step', normed=False, \ + color=xcolor, alpha=1, label=xlegend, log=False ) + n, bins, patches = plt.hist( errorY, bins=200, \ + histtype='step', normed=False, \ + color=ycolor, alpha=1, label=ylegend, log=False ) + n, bins, patches = plt.hist( errorZ, bins=200, \ + histtype='step', normed=False, \ + color=zcolor, alpha=1, label=zlegend, log=False ) # Figure properties + if config[ 'add_title' ] == 'True': + plt.title( plotTitle ) plt.xlabel( xAxisLabel ) plt.ylabel( yAxisLabel ) From 5b9d5e5eef8ffab860fdd022cd3d862b247f5a8e Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Fri, 13 May 2016 15:12:05 +0200 Subject: [PATCH 06/10] Add set-axes-manually feature for the component plot with markers --- python/plot_hist_sgp4Scan.py | 138 +++++++++++++++++++++++++++-------- 1 file changed, 106 insertions(+), 32 deletions(-) diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index 1432556..d2cc988 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -260,34 +260,6 @@ def plotComponentsMarkers( errorX, errorY, errorZ, xAxisLabel, yAxisLabel, plotTitle, \ flag ): - xDataHist, xBinEdges = np.histogram( errorX, bins=50, normed=False ) - xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 - - yDataHist, yBinEdges = np.histogram( errorY, bins=50, normed=False ) - yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 - - zDataHist, zBinEdges = np.histogram( errorZ, bins=50, normed=False ) - zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 - - xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ - linestyle='solid', linewidth=2, color=xcolor, label=xlegend, \ - marker='s', markersize=6, markerfacecolor=xcolor ) - - yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ - linestyle='solid', linewidth=2, color=ycolor, label=ylegend, \ - marker='v', markersize=6, markerfacecolor=ycolor ) - - zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ - linestyle='solid', linewidth=2, color=zcolor, label=zlegend, \ - marker='*', markersize=6, markerfacecolor=zcolor ) - - - markerFigure = plt.figure( ) - ax = markerFigure.add_subplot( 1, 1, 1 ) - ax.add_line( xMarkerLine ) - ax.add_line( yMarkerLine ) - ax.add_line( zMarkerLine ) - if flag == True and config['set_axes_position_component_flag'] == 'True': xAxesLowerLimit = config['set_axes_position_component'][ 0 ] xAxesUpperLimit = config['set_axes_position_component'][ 1 ] @@ -295,8 +267,44 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_position_component'][ 3 ] print "Using user defined axes limits for position component plot..." print "" - ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) - ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 + + yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 + + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 + + xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ + linestyle='solid', linewidth=2, \ + color=xcolor, label=xlegend, \ + marker='s', markersize=6, markerfacecolor=xcolor ) + + yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ + linestyle='solid', linewidth=2, \ + color=ycolor, label=ylegend, \ + marker='v', markersize=6, markerfacecolor=ycolor ) + + zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ + linestyle='solid', linewidth=2, \ + color=zcolor, label=zlegend, \ + marker='*', markersize=6, markerfacecolor=zcolor ) + + + markerFigure = plt.figure( ) + ax = markerFigure.add_subplot( 1, 1, 1 ) + ax.add_line( xMarkerLine ) + ax.add_line( yMarkerLine ) + ax.add_line( zMarkerLine ) + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + if yAxesUpperLimit != 0: + ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) if flag == False and config['set_axes_velocity_component_flag'] == 'True': xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] @@ -305,11 +313,77 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] print "Using user defined axes limits for velocity component plot..." print "" - ax.set_xlim( xAxesLowerLimit, xAxesUpperLimit ) - ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 + + yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 + + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 + + xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ + linestyle='solid', linewidth=2, \ + color=xcolor, label=xlegend, \ + marker='s', markersize=6, markerfacecolor=xcolor ) + + yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ + linestyle='solid', linewidth=2, \ + color=ycolor, label=ylegend, \ + marker='v', markersize=6, markerfacecolor=ycolor ) + + zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ + linestyle='solid', linewidth=2, \ + color=zcolor, label=zlegend, \ + marker='*', markersize=6, markerfacecolor=zcolor ) + + + markerFigure = plt.figure( ) + ax = markerFigure.add_subplot( 1, 1, 1 ) + ax.add_line( xMarkerLine ) + ax.add_line( yMarkerLine ) + ax.add_line( zMarkerLine ) + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + if yAxesUpperLimit != 0: + ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) if config['set_axes_position_component_flag'] == 'False' \ and config['set_axes_velocity_component_flag'] == 'False': + xDataHist, xBinEdges = np.histogram( errorX, bins=50, normed=False ) + xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 + + yDataHist, yBinEdges = np.histogram( errorY, bins=50, normed=False ) + yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 + + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, normed=False ) + zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 + + xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ + linestyle='solid', linewidth=2, \ + color=xcolor, label=xlegend, \ + marker='s', markersize=6, markerfacecolor=xcolor ) + + yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ + linestyle='solid', linewidth=2, \ + color=ycolor, label=ylegend, \ + marker='v', markersize=6, markerfacecolor=ycolor ) + + zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ + linestyle='solid', linewidth=2, \ + color=zcolor, label=zlegend, \ + marker='*', markersize=6, markerfacecolor=zcolor ) + + + markerFigure = plt.figure( ) + ax = markerFigure.add_subplot( 1, 1, 1 ) + ax.add_line( xMarkerLine ) + ax.add_line( yMarkerLine ) + ax.add_line( zMarkerLine ) xmin, xmax, ymin, ymax = ax.axis('auto') ax.set_xlim( xmin, xmax ) ax.set_ylim( ymin, ymax ) From 5f6d719e4db8f37f5d74ba33d4d9bf9fe54f3b51 Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Fri, 13 May 2016 16:55:30 +0200 Subject: [PATCH 07/10] Add feature to make normed plots --- config/plot_hist_sgp4Scan.json.empty | 5 ++ python/plot_hist_sgp4Scan.py | 90 +++++++++++++++++++++------- 2 files changed, 73 insertions(+), 22 deletions(-) diff --git a/config/plot_hist_sgp4Scan.json.empty b/config/plot_hist_sgp4Scan.json.empty index 03e8769..9bab089 100644 --- a/config/plot_hist_sgp4Scan.json.empty +++ b/config/plot_hist_sgp4Scan.json.empty @@ -45,6 +45,11 @@ // For grayscale, put True otherwise False "grayscale" : "", + // Normed histogram plots + // Set 'True' if the histogram plots (magnitude and components) have to be normed + // Set 'False' otherwise + "normed" : "", + // Choose plot type for which axes limits have to be set manually. // Ensure that if any of the options below is "TRUE", then set non zero limits for the // corresponding "set_axes_position" and "set_axes_velocity" parameters in the next section. diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py index d2cc988..98e19f0 100644 --- a/python/plot_hist_sgp4Scan.py +++ b/python/plot_hist_sgp4Scan.py @@ -176,17 +176,21 @@ def plotComponents( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_position_component'][ 3 ] print "Using user defined axes limits for position component plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None n, bins, patches = plt.hist( errorX, bins=200, \ range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=xcolor, alpha=1, label=xlegend, log=False ) n, bins, patches = plt.hist( errorY, bins=200, \ range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=ycolor, alpha=1, label=ylegend, log=False ) n, bins, patches = plt.hist( errorZ, bins=200, \ range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=zcolor, alpha=1, label=zlegend, log=False ) if yAxesUpperLimit != 0: plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) @@ -198,31 +202,39 @@ def plotComponents( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] print "Using user defined axes limits for velocity component plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None n, bins, patches = plt.hist( errorX, bins=200, \ range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=xcolor, alpha=1, label=xlegend, log=False ) n, bins, patches = plt.hist( errorY, bins=200, \ range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=ycolor, alpha=1, label=ylegend, log=False ) n, bins, patches = plt.hist( errorZ, bins=200, \ range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=zcolor, alpha=1, label=zlegend, log=False ) if yAxesUpperLimit != 0: plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) if config['set_axes_velocity_component_flag'] == 'False' \ and config['set_axes_position_component_flag'] == 'False': + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None n, bins, patches = plt.hist( errorX, bins=200, \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=xcolor, alpha=1, label=xlegend, log=False ) n, bins, patches = plt.hist( errorY, bins=200, \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=ycolor, alpha=1, label=ylegend, log=False ) n, bins, patches = plt.hist( errorZ, bins=200, \ - histtype='step', normed=False, \ + histtype='step', normed=False, weights=weights, \ color=zcolor, alpha=1, label=zlegend, log=False ) # Figure properties @@ -267,16 +279,23 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_position_component'][ 3 ] print "Using user defined axes limits for position component plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ @@ -313,16 +332,23 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] print "Using user defined axes limits for velocity component plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False ) + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ @@ -354,13 +380,17 @@ def plotComponentsMarkers( errorX, errorY, errorZ, if config['set_axes_position_component_flag'] == 'False' \ and config['set_axes_velocity_component_flag'] == 'False': - xDataHist, xBinEdges = np.histogram( errorX, bins=50, normed=False ) + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + xDataHist, xBinEdges = np.histogram( errorX, bins=50, normed=False, weights=weights ) xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 - yDataHist, yBinEdges = np.histogram( errorY, bins=50, normed=False ) + yDataHist, yBinEdges = np.histogram( errorY, bins=50, normed=False, weights=weights ) yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 - zDataHist, zBinEdges = np.histogram( errorZ, bins=50, normed=False ) + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, normed=False, weights=weights ) zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ @@ -503,7 +533,6 @@ def plotComponentsMarkers( errorX, errorY, errorZ, j2CurveColor = '1' if config['add_j2'] == "True": - if errorType[ errorTypeIndex ] == 'arrival_position': if config[ 'set_axes_position_magnitude_flag' ] == 'True': xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] @@ -569,17 +598,25 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] print "Using user defined axes limits for position magnitude plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None n, bins, patches = plt.hist( magnitudeError, bins=50, \ range=( xAxesLowerLimit, xAxesUpperLimit ), \ - normed=False, \ + normed=False, weights=weights, \ facecolor=figureColor, alpha=1, label='Magnitude' ) if yAxesUpperLimit != 0: plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) else: print "Using auto axes limits for position magnitude plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None n, bins, patches = plt.hist( magnitudeError, bins=50, \ - normed=False, \ + normed=False, weights=weights, \ facecolor=figureColor, alpha=1, label='Magnitude' ) else: if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': @@ -589,17 +626,26 @@ def plotComponentsMarkers( errorX, errorY, errorZ, yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] print "Using user defined axes limits for velocity magnitude plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None n, bins, patches = plt.hist( magnitudeError, bins=50, \ range=( xAxesLowerLimit, xAxesUpperLimit ), \ normed=False, \ + weights=weights, \ facecolor=figureColor, alpha=1, label='Magnitude' ) if yAxesUpperLimit != 0: plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) else: print "Using auto axes limits for velocity magnitude plot..." print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None n, bins, patches = plt.hist( magnitudeError, bins=50, \ - normed=False, \ + normed=False, weights=weights, \ facecolor=figureColor, alpha=1, label='Magnitude' ) # plt.legend( ) From 00d76d9bc8a0f4c9e78ffe214bbe3b0d6c70ad8e Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Fri, 13 May 2016 17:23:42 +0200 Subject: [PATCH 08/10] Rename files --- config/plot_sgp4_error_histogram.json.empty | 86 ++ python/plot_sgp4_error_histogram.py | 835 ++++++++++++++++++++ 2 files changed, 921 insertions(+) create mode 100644 config/plot_sgp4_error_histogram.json.empty create mode 100644 python/plot_sgp4_error_histogram.py diff --git a/config/plot_sgp4_error_histogram.json.empty b/config/plot_sgp4_error_histogram.json.empty new file mode 100644 index 0000000..9bab089 --- /dev/null +++ b/config/plot_sgp4_error_histogram.json.empty @@ -0,0 +1,86 @@ +// Copyright (c) 2014-2016 Kartik Kumar, Dinamica Srl (me@kartikkumar.com) +// Copyright (c) 2014-2016 Abhishek Agrawal, Delft University of Technology +// (abhishek.agrawal@protonmail.com) +// Distributed under the MIT License. +// See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT +{ + // Path to SQLite database containing scan data. + "database" : "", + + // Directory where the histogram is stored. + // Do not add a '/' at the end of the output dierectory. + "output_directory" : "", + + // Filename for histogram. + // Do not mention error type in the file name, it will automatically be included by the python + // plotting script. + "histogram_figure" : "", + + // Add or remove j2 analysis curve in position and velocity error histogram plots. + // Put True to add the j2 curve, else False. + "add_j2" : "", + + // Set reference frame for histogram plot of the error components. + // For Earth-Centered Inertial, use "ECI". + // For Radial-Tangen-Normal reference frame, use "RTN" + "frame" : "", + + // Set plot style for error component plots + // Set to "True" for plot with lines and markers + // Set to "False" for a histogram step plot with small bin size + "component_marker" : "", + + // Set output format for the figure (example: ".pdf", ".png") + "figure_format" : "", + + // Add or remove figure title. + // To add a title to the figure, put True otherwise False. + "add_title" : "", + + // Check for GUI + // If user machine has a display/GUI then put True, else False + "display" : "", + + // Set colortype for the figures. + // For grayscale, put True otherwise False + "grayscale" : "", + + // Normed histogram plots + // Set 'True' if the histogram plots (magnitude and components) have to be normed + // Set 'False' otherwise + "normed" : "", + + // Choose plot type for which axes limits have to be set manually. + // Ensure that if any of the options below is "TRUE", then set non zero limits for the + // corresponding "set_axes_position" and "set_axes_velocity" parameters in the next section. + // Set "set_axes_component_position_flag" and/or "set_axes_component_velocity_flag" to "True" + // if manual limits have to be applied to the components plots, set "False" otherwise. + // Set "set_axes_magnitude_position_flag" and/or "set_axes_magnitude_velocity_flag" to "True" + // if manual limits have to be applied to the magnitude plots, set "False" otherwise + "set_axes_position_component_flag" : "", + "set_axes_velocity_component_flag" : "", + "set_axes_position_magnitude_flag" : "", + "set_axes_velocity_magnitude_flag" : "", + + // Set axes limit for the position and velocity error plots (component) + // Format: [xmin, xmax, ymin, ymax] + // Auto sizing feature for the axes will be used if all the fields + // inside the square bracket are made zero. + "set_axes_position_component" : [,,,], + "set_axes_velocity_component" : [,,,], + + // Set axes limit for the position and velocity error plots (magnitude) + // Format: [xmin, xmax, ymin, ymax] + // Auto sizing feature for the axes will be used if all the fields + // inside the square bracket are made zero. + // Leave ymin and ymax fields as zero if only the x axes has to be set manually (The Y limits + // will then be set automatically) + "set_axes_position_magnitude" : [,,,], + "set_axes_velocity_magnitude" : [,,,], + + // Characteristics for figures. + "figure_dpi" : 300, + "tick_label_size" : 4, + "axis_label_size" : 10, + "colormap" : "jet" +} diff --git a/python/plot_sgp4_error_histogram.py b/python/plot_sgp4_error_histogram.py new file mode 100644 index 0000000..98e19f0 --- /dev/null +++ b/python/plot_sgp4_error_histogram.py @@ -0,0 +1,835 @@ +''' +Copyright (c) 2014-2016 Kartik Kumar, Dinamica Srl (me@kartikkumar.com) +Copyright (c) 2014-2016 Abhishek Agrawal, Delft University of Technology + (abhishek.agrawal@protonmail.com) +Distributed under the MIT License. +See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT +''' + +# Set up modules and packages +# I/O +import commentjson +import json +from pprint import pprint + +# SQL database +import sqlite3 + +# Numerical +import numpy as np +import pandas as pd + +# System +import sys +import time +from tqdm import tqdm + +print "" +print "---------------------------------------------------------------------------------" +print " D2D " +print " " +print " Copyright (c) 2016, K. Kumar (me@kartikkumar.com) " +print " Copyright (c) 2016, A. Agrawal (abhishek.agrawal@protonmail.com) " +print "---------------------------------------------------------------------------------" +print "" + +# Start timer. +start_time = time.time( ) + +print "" +print "******************************************************************" +print " Input parameters " +print "******************************************************************" +print "" + +# Parse JSON configuration file +# Raise exception if wrong number of inputs are provided to script +if len(sys.argv) != 2: + raise Exception("Only provide a JSON config file as input!") + +json_data = open(sys.argv[1]) +config = commentjson.load(json_data) +json_data.close() +pprint(config) + +# Get plotting packages +import matplotlib + +# If user's computer does not have a GUI/display then the TKAgg will not be used +if config['display'] == 'True': + matplotlib.use('TkAgg') +else: + matplotlib.use('Agg') + +import matplotlib.colors +import matplotlib.axes +import matplotlib.lines as mlines +import matplotlib.patches as mpatches +import matplotlib.pyplot as plt +import matplotlib.mlab as mlab +from matplotlib import rcParams +from matplotlib import cm +from mpl_toolkits.mplot3d import Axes3D +from mpl_toolkits.mplot3d import axes3d + +print "" +print "******************************************************************" +print " Operations " +print "******************************************************************" +print "" + +print "Input data files being read ..." + +output_path_prefix = config["output_directory"] + '/' + +print "Fetching scan data from database ..." + +# Connect to SQLite database. +try: + database = sqlite3.connect(config['database']) + +except sqlite3.Error, e: + print "Error %s:" % e.args[0] + sys.exit(1) + +# Function to calculate the transformation matrix for ECI to RTN frame conversion +# @param[in] refX X position of the RTN frame's origin w.r.t the ECI frame's origin +# @param[in] refY Y position of the RTN frame's origin w.r.t the ECI frame's origin +# @param[in] refZ Z position of the RTN frame's origin w.r.t the ECI frame's origin +# @param[in] refVX X velocity of the RTN frame's origin w.r.t the ECI frame's origin +# @param[in] refVY Y velocity of the RTN frame's origin w.r.t the ECI frame's origin +# @param[in] refVZ Z velocity of the RTN frame's origin w.r.t the ECI frame's origin +def gammaECI2RTN( refX, refY, refZ, refVX, refVY, refVZ ): + + # Radial unit vector: + unitR = np.zeros( shape=( 1, 3 ), dtype=float ) + + # Transverse unit vector: + unitT = np.zeros( shape=( 1, 3 ), dtype=float ) + + # Normal unit vector: + unitN = np.zeros( shape=( 1, 3 ), dtype=float ) + + vectorR = np.array( object=[ refX, refY, refZ ], dtype=float ) + + vectorV = np.array( object=[ refVX, refVY, refVZ ], dtype=float ) + + arrivalPositionMagnitude = np.linalg.norm( vectorR ) + + if arrivalPositionMagnitude != 0: + unitR = np.divide( vectorR, arrivalPositionMagnitude ) + + angularMomentumVector = np.cross( vectorR, vectorV ) + angularMomentumMagnitude = np.linalg.norm( angularMomentumVector ) + + if angularMomentumMagnitude != 0: + unitN = np.divide( angularMomentumVector, angularMomentumMagnitude ) + + unitT = np.cross( unitN, unitR ) + + gamma = np.zeros( shape=( 3, 3 ), dtype=float ) + gamma[ 0 ][ : ] = unitR + gamma[ 1 ][ : ] = unitT + gamma[ 2 ][ : ] = unitN + + return gamma + +# Sanity check for the gammaECI2RTN function: +# errorVectorECI = [ 10, 10, 0 ] +# errorVectorRTN = np.zeros( shape=( 3, 1 ), dtype=float ) +# gamma = np.zeros( shape=( 3, 3 ), dtype=float ) +# gamma = gammaECI2RTN( 0, 10, 0, -30, 0, 0 ) +# errorVectorRTN[ 0 ] = np.inner( gamma[ 0 ][ : ], errorVectorECI ) +# errorVectorRTN[ 1 ] = np.inner( gamma[ 1 ][ : ], errorVectorECI ) +# errorVectorRTN[ 2 ] = np.inner( gamma[ 2 ][ : ], errorVectorECI ) +# print "Error Vector RTN: " +# print errorVectorRTN +# expectedErrorVectorRTN = [ 10, -10, 0 ] +# print "Expected Error Vector RTN: " +# print expectedErrorVectorRTN +# exit( ) + +# Function to plot the components of position/velocity error vector +# @param[in] errorX x component +# @param[in] errorY y component +# @param[in] errorZ z component +# @param[in] xcolor x component color in the plot +# @param[in] ycolor y component color in the plot +# @param[in] zcolor z component color in the plot +# @param[in] xlegend legend for the x component curve in the plot +# @param[in] ylegend legend for the y component curve in the plot +# @param[in] zlegend legend for the z component curve in the plot +# @param[in] xAxisLabel Label for the X axis +# @param[in] yAxisLabel Label for the Y axis +# @param[in] zAxisLabel Label for the Z axis +# @param[in] flag Set True if position error vector is being plotted, else False +def plotComponents( errorX, errorY, errorZ, \ + xcolor, ycolor, zcolor, \ + xlegend, ylegend, zlegend, \ + xAxisLabel, yAxisLabel, plotTitle, \ + flag ): + + if flag == True and config['set_axes_position_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_position_component'][ 0 ] + xAxesUpperLimit = config['set_axes_position_component'][ 1 ] + yAxesLowerLimit = config['set_axes_position_component'][ 2 ] + yAxesUpperLimit = config['set_axes_position_component'][ 3 ] + print "Using user defined axes limits for position component plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + n, bins, patches = plt.hist( errorX, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, weights=weights, \ + color=xcolor, alpha=1, label=xlegend, log=False ) + n, bins, patches = plt.hist( errorY, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, weights=weights, \ + color=ycolor, alpha=1, label=ylegend, log=False ) + n, bins, patches = plt.hist( errorZ, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, weights=weights, \ + color=zcolor, alpha=1, label=zlegend, log=False ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + + if flag == False and config['set_axes_velocity_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_component'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_component'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] + print "Using user defined axes limits for velocity component plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + n, bins, patches = plt.hist( errorX, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, weights=weights, \ + color=xcolor, alpha=1, label=xlegend, log=False ) + n, bins, patches = plt.hist( errorY, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, weights=weights, \ + color=ycolor, alpha=1, label=ylegend, log=False ) + n, bins, patches = plt.hist( errorZ, bins=200, \ + range=(xAxesLowerLimit, xAxesUpperLimit), \ + histtype='step', normed=False, weights=weights, \ + color=zcolor, alpha=1, label=zlegend, log=False ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + + if config['set_axes_velocity_component_flag'] == 'False' \ + and config['set_axes_position_component_flag'] == 'False': + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + n, bins, patches = plt.hist( errorX, bins=200, \ + histtype='step', normed=False, weights=weights, \ + color=xcolor, alpha=1, label=xlegend, log=False ) + n, bins, patches = plt.hist( errorY, bins=200, \ + histtype='step', normed=False, weights=weights, \ + color=ycolor, alpha=1, label=ylegend, log=False ) + n, bins, patches = plt.hist( errorZ, bins=200, \ + histtype='step', normed=False, weights=weights, \ + color=zcolor, alpha=1, label=zlegend, log=False ) + + # Figure properties + if config[ 'add_title' ] == 'True': + plt.title( plotTitle ) + plt.xlabel( xAxisLabel ) + plt.ylabel( yAxisLabel ) + + xLegend = mlines.Line2D( [], [], color=xcolor, label=xlegend ) + yLegend = mlines.Line2D( [], [], color=ycolor, label=ylegend ) + zLegend = mlines.Line2D( [], [], color=zcolor, label=zlegend ) + lines = [xLegend, yLegend, zLegend] + labels = [line.get_label( ) for line in lines] + plt.legend(lines, labels) + + plt.grid( True ) + +# Function to plot the components of position/velocity error vector using line and markers +# @param[in] errorX x component +# @param[in] errorY y component +# @param[in] errorZ z component +# @param[in] xcolor x component color in the plot +# @param[in] ycolor y component color in the plot +# @param[in] zcolor z component color in the plot +# @param[in] xlegend legend for the x component curve in the plot +# @param[in] ylegend legend for the y component curve in the plot +# @param[in] zlegend legend for the z component curve in the plot +# @param[in] xAxisLabel Label for the X axis +# @param[in] yAxisLabel Label for the Y axis +# @param[in] zAxisLabel Label for the Z axis +# @param[in] flag Set True if position error vector is being plotted, else False +def plotComponentsMarkers( errorX, errorY, errorZ, \ + xcolor, ycolor, zcolor, \ + xlegend, ylegend, zlegend, \ + xAxisLabel, yAxisLabel, plotTitle, \ + flag ): + + if flag == True and config['set_axes_position_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_position_component'][ 0 ] + xAxesUpperLimit = config['set_axes_position_component'][ 1 ] + yAxesLowerLimit = config['set_axes_position_component'][ 2 ] + yAxesUpperLimit = config['set_axes_position_component'][ 3 ] + print "Using user defined axes limits for position component plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) + xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 + + yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) + yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 + + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) + zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 + + xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ + linestyle='solid', linewidth=2, \ + color=xcolor, label=xlegend, \ + marker='s', markersize=6, markerfacecolor=xcolor ) + + yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ + linestyle='solid', linewidth=2, \ + color=ycolor, label=ylegend, \ + marker='v', markersize=6, markerfacecolor=ycolor ) + + zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ + linestyle='solid', linewidth=2, \ + color=zcolor, label=zlegend, \ + marker='*', markersize=6, markerfacecolor=zcolor ) + + + markerFigure = plt.figure( ) + ax = markerFigure.add_subplot( 1, 1, 1 ) + ax.add_line( xMarkerLine ) + ax.add_line( yMarkerLine ) + ax.add_line( zMarkerLine ) + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + if yAxesUpperLimit != 0: + ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + + if flag == False and config['set_axes_velocity_component_flag'] == 'True': + xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_component'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_component'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] + print "Using user defined axes limits for velocity component plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) + xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 + + yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) + yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 + + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ + range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ + weights=weights ) + zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 + + xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ + linestyle='solid', linewidth=2, \ + color=xcolor, label=xlegend, \ + marker='s', markersize=6, markerfacecolor=xcolor ) + + yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ + linestyle='solid', linewidth=2, \ + color=ycolor, label=ylegend, \ + marker='v', markersize=6, markerfacecolor=ycolor ) + + zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ + linestyle='solid', linewidth=2, \ + color=zcolor, label=zlegend, \ + marker='*', markersize=6, markerfacecolor=zcolor ) + + + markerFigure = plt.figure( ) + ax = markerFigure.add_subplot( 1, 1, 1 ) + ax.add_line( xMarkerLine ) + ax.add_line( yMarkerLine ) + ax.add_line( zMarkerLine ) + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + if yAxesUpperLimit != 0: + ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) + + if config['set_axes_position_component_flag'] == 'False' \ + and config['set_axes_velocity_component_flag'] == 'False': + if config['normed'] == 'True': + weights = np.ones_like( errorX ) / float( len( errorX ) ) + else: + weights = None + xDataHist, xBinEdges = np.histogram( errorX, bins=50, normed=False, weights=weights ) + xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 + + yDataHist, yBinEdges = np.histogram( errorY, bins=50, normed=False, weights=weights ) + yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 + + zDataHist, zBinEdges = np.histogram( errorZ, bins=50, normed=False, weights=weights ) + zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 + + xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ + linestyle='solid', linewidth=2, \ + color=xcolor, label=xlegend, \ + marker='s', markersize=6, markerfacecolor=xcolor ) + + yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ + linestyle='solid', linewidth=2, \ + color=ycolor, label=ylegend, \ + marker='v', markersize=6, markerfacecolor=ycolor ) + + zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ + linestyle='solid', linewidth=2, \ + color=zcolor, label=zlegend, \ + marker='*', markersize=6, markerfacecolor=zcolor ) + + + markerFigure = plt.figure( ) + ax = markerFigure.add_subplot( 1, 1, 1 ) + ax.add_line( xMarkerLine ) + ax.add_line( yMarkerLine ) + ax.add_line( zMarkerLine ) + xmin, xmax, ymin, ymax = ax.axis('auto') + ax.set_xlim( xmin, xmax ) + ax.set_ylim( ymin, ymax ) + + # Figure properties + plt.xlabel( xAxisLabel ) + plt.ylabel( yAxisLabel ) + + if config[ 'add_title' ] == 'True': + plt.title( plotTitle ) + + plt.legend( ) + plt.grid( True ) + + +errorType = [ "arrival_position", "arrival_velocity" ] + +# Fetch scan data. +scan_data = pd.read_sql( "SELECT arrival_position_x_error, \ + arrival_position_y_error, \ + arrival_position_z_error, \ + arrival_position_error, \ + arrival_velocity_x_error, \ + arrival_velocity_y_error, \ + arrival_velocity_z_error, \ + arrival_velocity_error \ + FROM sgp4_scanner_results \ + WHERE success = 1;", \ + database ) + +scan_data.columns = [ 'positionErrorX', \ + 'positionErrorY', \ + 'positionErrorZ', \ + 'positionErrorMagnitude', \ + 'velocityErrorX', \ + 'velocityErrorY', \ + 'velocityErrorZ', \ + 'velocityErrorMagnitude' ] + +lambert_scan_data = pd.read_sql( "SELECT lambert_scanner_results.arrival_position_x, \ + lambert_scanner_results.arrival_position_y, \ + lambert_scanner_results.arrival_position_z, \ + lambert_scanner_results.arrival_velocity_x, \ + lambert_scanner_results.arrival_velocity_y, \ + lambert_scanner_results.arrival_velocity_z \ + FROM lambert_scanner_results \ + INNER JOIN sgp4_scanner_results \ + ON lambert_scanner_results.transfer_id = \ + sgp4_scanner_results.lambert_transfer_id \ + AND sgp4_scanner_results.success = 1;", + database ) + +lambert_scan_data.columns = [ 'arrivalPositionX', \ + 'arrivalPositionY', \ + 'arrivalPositionZ', \ + 'arrivalVelocityX', \ + 'arrivalVelocityY', \ + 'arrivalVelocityZ' ] + +if config['add_j2'] == "True": + j2_analysis_data = pd.read_sql( "SELECT arrival_position_x_error, \ + arrival_position_y_error, \ + arrival_position_z_error, \ + arrival_position_error, \ + arrival_velocity_x_error, \ + arrival_velocity_y_error, \ + arrival_velocity_z_error, \ + arrival_velocity_error \ + FROM j2_analysis_results;", \ + database ) + + j2_analysis_data.columns = [ 'positionErrorX', \ + 'positionErrorY', \ + 'positionErrorZ', \ + 'positionErrorMagnitude', \ + 'velocityErrorX', \ + 'velocityErrorY', \ + 'velocityErrorZ', \ + 'velocityErrorMagnitude' ] + + +print "Fetch successful!" +print "" + +for errorTypeIndex in range( len( errorType ) ): + if errorType[ errorTypeIndex ] == "arrival_position": + print "Plotting position error magnitude histogram ..." + print "" + magnitudeError = scan_data[ 'positionErrorMagnitude' ] + if config['add_j2'] == "True": + j2magnitudeError = j2_analysis_data[ 'positionErrorMagnitude' ] + else: + print "" + print "Plotting velocity error magnitude histogram ..." + print "" + magnitudeError = scan_data[ 'velocityErrorMagnitude' ] + if config['add_j2'] == "True": + j2magnitudeError = j2_analysis_data[ 'velocityErrorMagnitude' ] + + # Calculate mean, variance and standard deviation + mu = sum( magnitudeError ) / len( magnitudeError ) + print 'Mean = ' + repr( mu ) + + sumOfSquareDeviations = sum( ( x - mu )**2 for x in magnitudeError ) + variance = sumOfSquareDeviations / len( magnitudeError ) + print 'Variance = ' + repr( variance ) + + sigma = variance**0.5 + print 'Standard Deviation = ' + repr( sigma ) + + # Plot the magnitude of the error + if config['grayscale'] == 'False': + figureColor = 'green' + j2CurveColor = 'red' + else: + figureColor = '0.40' + j2CurveColor = '1' + + if config['add_j2'] == "True": + if errorType[ errorTypeIndex ] == 'arrival_position': + if config[ 'set_axes_position_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] + + print "Using user defined axes limits for position magnitude J2 plot..." + print "" + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + histtype='step', \ + normed=False, color=j2CurveColor, \ + alpha=1, label='J2' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ + normed=False, color=j2CurveColor, alpha=1, label='J2' ) + else: + if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] + print "Using user defined axes limits for velocity magnitude J2 plot..." + print "" + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + histtype='step', \ + normed=False, color=j2CurveColor, \ + alpha=1, label='J2' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ + normed=False, color=j2CurveColor, alpha=1, label='J2' ) + + + j2Legend = mlines.Line2D( [], [], color=j2CurveColor, label='J2' ) + magnitudeLegend = mpatches.Patch( color=figureColor, label='Magnitude' ) + lines = [ magnitudeLegend, j2Legend ] + labels = [ line.get_label( ) for line in lines ] + plt.legend( lines, labels ) + else: + if errorType[ errorTypeIndex ] == 'arrival_position': + if config[ 'set_axes_position_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] + print "Using user defined axes limits for position magnitude plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, weights=weights, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + print "Using auto axes limits for position magnitude plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + normed=False, weights=weights, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + else: + if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': + xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] + xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] + yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] + yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] + print "Using user defined axes limits for velocity magnitude plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + range=( xAxesLowerLimit, xAxesUpperLimit ), \ + normed=False, \ + weights=weights, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + if yAxesUpperLimit != 0: + plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) + else: + print "Using auto axes limits for velocity magnitude plot..." + print "" + if config['normed'] == 'True': + weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) + else: + weights = None + n, bins, patches = plt.hist( magnitudeError, bins=50, \ + normed=False, weights=weights, \ + facecolor=figureColor, alpha=1, label='Magnitude' ) + # plt.legend( ) + + # Select appropriate unit and title for the error type + if errorType[ errorTypeIndex ] == 'arrival_position': + plotTitle = 'Arrival Position Error' + xAxisLabel = 'Arrival position error [km]' + else: + plotTitle = 'Arrival Velocity Error' + xAxisLabel = 'Arrival velocity error [km/s]' + + # Figure properties + plt.xlabel( xAxisLabel ) + plt.ylabel( 'Frequency' ) + + if config[ 'add_title' ] == 'True': + plt.title( plotTitle + " " + 'Magnitude' ) + + plt.grid( True ) + + # Save figure to file. + if config['add_j2'] == "True": + plt.savefig( output_path_prefix + "J2_" + config["histogram_figure"] + "_" + + errorType[ errorTypeIndex ] + "_error" + "_magnitude" + + config["figure_format"], dpi=config["figure_dpi"] ) + plt.close( ) + else: + plt.savefig( output_path_prefix + config["histogram_figure"] + "_" + + errorType[ errorTypeIndex ] + "_error" + "_magnitude" + + config["figure_format"], dpi=config["figure_dpi"] ) + plt.close( ) + +# Plot the components of the (position/velocity) error vector in a separate figure. +if config['grayscale'] == 'False': + xcolor = 'red' + ycolor = 'blue' + zcolor = 'black' +else: + xcolor = '0' + ycolor = '0.30' + zcolor = '0.60' + +positionErrorX = scan_data[ 'positionErrorX' ] +positionErrorY = scan_data[ 'positionErrorY' ] +positionErrorZ = scan_data[ 'positionErrorZ' ] +velocityErrorX = scan_data[ 'velocityErrorX' ] +velocityErrorY = scan_data[ 'velocityErrorY' ] +velocityErrorZ = scan_data[ 'velocityErrorZ' ] + +if config['frame'] == "RTN": + # ECI to RTN frame transformation. + print "" + print "Performing ECI to RTN frame conversion for the position and velocity error vectors ..." + print "" + + arrivalPositionX = lambert_scan_data[ 'arrivalPositionX' ] + arrivalPositionY = lambert_scan_data[ 'arrivalPositionY' ] + arrivalPositionZ = lambert_scan_data[ 'arrivalPositionZ' ] + arrivalVelocityX = lambert_scan_data[ 'arrivalVelocityX' ] + arrivalVelocityY = lambert_scan_data[ 'arrivalVelocityY' ] + arrivalVelocityZ = lambert_scan_data[ 'arrivalVelocityZ' ] + + totalCases = len( arrivalPositionX ) + gamma = np.zeros( shape=( 3, 3 ), dtype=float ) + + for i in tqdm( range( totalCases ) ): + gamma = gammaECI2RTN( arrivalPositionX[ i ], \ + arrivalPositionY[ i ], \ + arrivalPositionZ[ i ], \ + arrivalVelocityX[ i ], \ + arrivalVelocityY[ i ], \ + arrivalVelocityZ[ i ] ) + + positionErrorVectorECI = [ positionErrorX[ i ], positionErrorY[ i ], positionErrorZ[ i ] ] + velocityErrorVectorECI = [ velocityErrorX[ i ], velocityErrorY[ i ], velocityErrorZ[ i ] ] + + positionErrorX[ i ] = np.inner( gamma[ 0 ][ : ], positionErrorVectorECI ) + positionErrorY[ i ] = np.inner( gamma[ 1 ][ : ], positionErrorVectorECI ) + positionErrorZ[ i ] = np.inner( gamma[ 2 ][ : ], positionErrorVectorECI ) + + velocityErrorX[ i ] = np.inner( gamma[ 0 ][ : ], velocityErrorVectorECI ) + velocityErrorY[ i ] = np.inner( gamma[ 1 ][ : ], velocityErrorVectorECI ) + velocityErrorZ[ i ] = np.inner( gamma[ 2 ][ : ], velocityErrorVectorECI ) + + print "Plotting position error components defined in RTN frame" + + if config['component_marker'] == "False": + plotComponents( positionErrorX, positionErrorY, positionErrorZ, \ + xcolor, ycolor, zcolor, \ + "Radial", "Transverse", "Normal", \ + "Arrival position error [km]", "Frequency", "Position Error Components", \ + True ) + else: + plotComponentsMarkers( positionErrorX, positionErrorY, positionErrorZ, \ + xcolor, ycolor, zcolor, \ + "Radial", "Transverse", "Normal", \ + "Arrival position error [km]", "Frequency", \ + "Position Error Components", True ) + + # Save figure to file. + plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_position_error" + + "_components_" + config["frame"] + config["figure_format"], \ + dpi=config["figure_dpi"] ) + plt.close( ) + + print "Plotting velocity error components defined in RTN frame" + + if config['component_marker'] == "False": + plotComponents( velocityErrorX, velocityErrorY, velocityErrorZ, \ + xcolor, ycolor, zcolor, \ + "Radial", "Transverse", "Normal", \ + "Arrival velocity error [km/s]", "Frequency", "Velocity Error Components",\ + False ) + else: + plotComponentsMarkers( velocityErrorX, velocityErrorY, velocityErrorZ, \ + xcolor, ycolor, zcolor, \ + "Radial", "Transverse", "Normal", \ + "Arrival velocity error [km/s]", "Frequency", \ + "Velocity Error Components", False ) + + # Save figure to file. + plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_velocity_error" + + "_components_" + config["frame"] + config["figure_format"], \ + dpi=config["figure_dpi"] ) + plt.close( ) + +else: + print "Plotting position error components defined in ECI frame" + + if config['component_marker'] == "False": + plotComponents( positionErrorX, positionErrorY, positionErrorZ, \ + xcolor, ycolor, zcolor, \ + "X Axis", "Y Axis", "Z Axis", \ + "Arrival position error [km]", "Frequency", "Position Error Components", \ + True ) + else: + plotComponentsMarkers( positionErrorX, positionErrorY, positionErrorZ, \ + xcolor, ycolor, zcolor, \ + "X Axis", "Y Axis", "Z Axis", \ + "Arrival position error [km]", "Frequency", \ + "Position Error Components", True ) + + # Save figure to file. + plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_position_error" + + "_components_" + config["frame"] + config["figure_format"], \ + dpi=config["figure_dpi"] ) + plt.close( ) + + print "Plotting velocity error components defined in ECI frame" + + if config['component_marker'] == "False": + plotComponents( velocityErrorX, velocityErrorY, velocityErrorZ, \ + xcolor, ycolor, zcolor, \ + "X Axis", "Y Axis", "Z Axis", \ + "Arrival velocity error [km/s]", "Frequency", "Velocity Error Components",\ + False ) + else: + plotComponentsMarkers( velocityErrorX, velocityErrorY, velocityErrorZ, \ + xcolor, ycolor, zcolor, \ + "X Axis", "Y Axis", "Z Axis", \ + "Arrival velocity error [km/s]", "Frequency", \ + "Velocity Error Components", False ) + + # Save figure to file. + plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_velocity_error" + + "_components_" + config["frame"] + config["figure_format"], \ + dpi=config["figure_dpi"] ) + plt.close( ) + +print "All figures generated successfully!" +print "" + +# Close SQLite database if it's still open. +if database: + database.close( ) + +# Stop timer +end_time = time.time( ) + +# Print elapsed time +print "Script time: " + str("{:,g}".format(end_time - start_time)) + "s" + +print "" +print "------------------------------------------------------------------" +print " Exited successfully! " +print "------------------------------------------------------------------" +print "" From 554c538c1becba6fbce5eebf628a351e0c5d86d7 Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Fri, 13 May 2016 17:25:36 +0200 Subject: [PATCH 09/10] remove files with the old name --- config/plot_hist_sgp4Scan.json.empty | 86 --- python/plot_hist_sgp4Scan.py | 835 --------------------------- 2 files changed, 921 deletions(-) delete mode 100644 config/plot_hist_sgp4Scan.json.empty delete mode 100644 python/plot_hist_sgp4Scan.py diff --git a/config/plot_hist_sgp4Scan.json.empty b/config/plot_hist_sgp4Scan.json.empty deleted file mode 100644 index 9bab089..0000000 --- a/config/plot_hist_sgp4Scan.json.empty +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2014-2016 Kartik Kumar, Dinamica Srl (me@kartikkumar.com) -// Copyright (c) 2014-2016 Abhishek Agrawal, Delft University of Technology -// (abhishek.agrawal@protonmail.com) -// Distributed under the MIT License. -// See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT -{ - // Path to SQLite database containing scan data. - "database" : "", - - // Directory where the histogram is stored. - // Do not add a '/' at the end of the output dierectory. - "output_directory" : "", - - // Filename for histogram. - // Do not mention error type in the file name, it will automatically be included by the python - // plotting script. - "histogram_figure" : "", - - // Add or remove j2 analysis curve in position and velocity error histogram plots. - // Put True to add the j2 curve, else False. - "add_j2" : "", - - // Set reference frame for histogram plot of the error components. - // For Earth-Centered Inertial, use "ECI". - // For Radial-Tangen-Normal reference frame, use "RTN" - "frame" : "", - - // Set plot style for error component plots - // Set to "True" for plot with lines and markers - // Set to "False" for a histogram step plot with small bin size - "component_marker" : "", - - // Set output format for the figure (example: ".pdf", ".png") - "figure_format" : "", - - // Add or remove figure title. - // To add a title to the figure, put True otherwise False. - "add_title" : "", - - // Check for GUI - // If user machine has a display/GUI then put True, else False - "display" : "", - - // Set colortype for the figures. - // For grayscale, put True otherwise False - "grayscale" : "", - - // Normed histogram plots - // Set 'True' if the histogram plots (magnitude and components) have to be normed - // Set 'False' otherwise - "normed" : "", - - // Choose plot type for which axes limits have to be set manually. - // Ensure that if any of the options below is "TRUE", then set non zero limits for the - // corresponding "set_axes_position" and "set_axes_velocity" parameters in the next section. - // Set "set_axes_component_position_flag" and/or "set_axes_component_velocity_flag" to "True" - // if manual limits have to be applied to the components plots, set "False" otherwise. - // Set "set_axes_magnitude_position_flag" and/or "set_axes_magnitude_velocity_flag" to "True" - // if manual limits have to be applied to the magnitude plots, set "False" otherwise - "set_axes_position_component_flag" : "", - "set_axes_velocity_component_flag" : "", - "set_axes_position_magnitude_flag" : "", - "set_axes_velocity_magnitude_flag" : "", - - // Set axes limit for the position and velocity error plots (component) - // Format: [xmin, xmax, ymin, ymax] - // Auto sizing feature for the axes will be used if all the fields - // inside the square bracket are made zero. - "set_axes_position_component" : [,,,], - "set_axes_velocity_component" : [,,,], - - // Set axes limit for the position and velocity error plots (magnitude) - // Format: [xmin, xmax, ymin, ymax] - // Auto sizing feature for the axes will be used if all the fields - // inside the square bracket are made zero. - // Leave ymin and ymax fields as zero if only the x axes has to be set manually (The Y limits - // will then be set automatically) - "set_axes_position_magnitude" : [,,,], - "set_axes_velocity_magnitude" : [,,,], - - // Characteristics for figures. - "figure_dpi" : 300, - "tick_label_size" : 4, - "axis_label_size" : 10, - "colormap" : "jet" -} diff --git a/python/plot_hist_sgp4Scan.py b/python/plot_hist_sgp4Scan.py deleted file mode 100644 index 98e19f0..0000000 --- a/python/plot_hist_sgp4Scan.py +++ /dev/null @@ -1,835 +0,0 @@ -''' -Copyright (c) 2014-2016 Kartik Kumar, Dinamica Srl (me@kartikkumar.com) -Copyright (c) 2014-2016 Abhishek Agrawal, Delft University of Technology - (abhishek.agrawal@protonmail.com) -Distributed under the MIT License. -See accompanying file LICENSE.md or copy at http://opensource.org/licenses/MIT -''' - -# Set up modules and packages -# I/O -import commentjson -import json -from pprint import pprint - -# SQL database -import sqlite3 - -# Numerical -import numpy as np -import pandas as pd - -# System -import sys -import time -from tqdm import tqdm - -print "" -print "---------------------------------------------------------------------------------" -print " D2D " -print " " -print " Copyright (c) 2016, K. Kumar (me@kartikkumar.com) " -print " Copyright (c) 2016, A. Agrawal (abhishek.agrawal@protonmail.com) " -print "---------------------------------------------------------------------------------" -print "" - -# Start timer. -start_time = time.time( ) - -print "" -print "******************************************************************" -print " Input parameters " -print "******************************************************************" -print "" - -# Parse JSON configuration file -# Raise exception if wrong number of inputs are provided to script -if len(sys.argv) != 2: - raise Exception("Only provide a JSON config file as input!") - -json_data = open(sys.argv[1]) -config = commentjson.load(json_data) -json_data.close() -pprint(config) - -# Get plotting packages -import matplotlib - -# If user's computer does not have a GUI/display then the TKAgg will not be used -if config['display'] == 'True': - matplotlib.use('TkAgg') -else: - matplotlib.use('Agg') - -import matplotlib.colors -import matplotlib.axes -import matplotlib.lines as mlines -import matplotlib.patches as mpatches -import matplotlib.pyplot as plt -import matplotlib.mlab as mlab -from matplotlib import rcParams -from matplotlib import cm -from mpl_toolkits.mplot3d import Axes3D -from mpl_toolkits.mplot3d import axes3d - -print "" -print "******************************************************************" -print " Operations " -print "******************************************************************" -print "" - -print "Input data files being read ..." - -output_path_prefix = config["output_directory"] + '/' - -print "Fetching scan data from database ..." - -# Connect to SQLite database. -try: - database = sqlite3.connect(config['database']) - -except sqlite3.Error, e: - print "Error %s:" % e.args[0] - sys.exit(1) - -# Function to calculate the transformation matrix for ECI to RTN frame conversion -# @param[in] refX X position of the RTN frame's origin w.r.t the ECI frame's origin -# @param[in] refY Y position of the RTN frame's origin w.r.t the ECI frame's origin -# @param[in] refZ Z position of the RTN frame's origin w.r.t the ECI frame's origin -# @param[in] refVX X velocity of the RTN frame's origin w.r.t the ECI frame's origin -# @param[in] refVY Y velocity of the RTN frame's origin w.r.t the ECI frame's origin -# @param[in] refVZ Z velocity of the RTN frame's origin w.r.t the ECI frame's origin -def gammaECI2RTN( refX, refY, refZ, refVX, refVY, refVZ ): - - # Radial unit vector: - unitR = np.zeros( shape=( 1, 3 ), dtype=float ) - - # Transverse unit vector: - unitT = np.zeros( shape=( 1, 3 ), dtype=float ) - - # Normal unit vector: - unitN = np.zeros( shape=( 1, 3 ), dtype=float ) - - vectorR = np.array( object=[ refX, refY, refZ ], dtype=float ) - - vectorV = np.array( object=[ refVX, refVY, refVZ ], dtype=float ) - - arrivalPositionMagnitude = np.linalg.norm( vectorR ) - - if arrivalPositionMagnitude != 0: - unitR = np.divide( vectorR, arrivalPositionMagnitude ) - - angularMomentumVector = np.cross( vectorR, vectorV ) - angularMomentumMagnitude = np.linalg.norm( angularMomentumVector ) - - if angularMomentumMagnitude != 0: - unitN = np.divide( angularMomentumVector, angularMomentumMagnitude ) - - unitT = np.cross( unitN, unitR ) - - gamma = np.zeros( shape=( 3, 3 ), dtype=float ) - gamma[ 0 ][ : ] = unitR - gamma[ 1 ][ : ] = unitT - gamma[ 2 ][ : ] = unitN - - return gamma - -# Sanity check for the gammaECI2RTN function: -# errorVectorECI = [ 10, 10, 0 ] -# errorVectorRTN = np.zeros( shape=( 3, 1 ), dtype=float ) -# gamma = np.zeros( shape=( 3, 3 ), dtype=float ) -# gamma = gammaECI2RTN( 0, 10, 0, -30, 0, 0 ) -# errorVectorRTN[ 0 ] = np.inner( gamma[ 0 ][ : ], errorVectorECI ) -# errorVectorRTN[ 1 ] = np.inner( gamma[ 1 ][ : ], errorVectorECI ) -# errorVectorRTN[ 2 ] = np.inner( gamma[ 2 ][ : ], errorVectorECI ) -# print "Error Vector RTN: " -# print errorVectorRTN -# expectedErrorVectorRTN = [ 10, -10, 0 ] -# print "Expected Error Vector RTN: " -# print expectedErrorVectorRTN -# exit( ) - -# Function to plot the components of position/velocity error vector -# @param[in] errorX x component -# @param[in] errorY y component -# @param[in] errorZ z component -# @param[in] xcolor x component color in the plot -# @param[in] ycolor y component color in the plot -# @param[in] zcolor z component color in the plot -# @param[in] xlegend legend for the x component curve in the plot -# @param[in] ylegend legend for the y component curve in the plot -# @param[in] zlegend legend for the z component curve in the plot -# @param[in] xAxisLabel Label for the X axis -# @param[in] yAxisLabel Label for the Y axis -# @param[in] zAxisLabel Label for the Z axis -# @param[in] flag Set True if position error vector is being plotted, else False -def plotComponents( errorX, errorY, errorZ, \ - xcolor, ycolor, zcolor, \ - xlegend, ylegend, zlegend, \ - xAxisLabel, yAxisLabel, plotTitle, \ - flag ): - - if flag == True and config['set_axes_position_component_flag'] == 'True': - xAxesLowerLimit = config['set_axes_position_component'][ 0 ] - xAxesUpperLimit = config['set_axes_position_component'][ 1 ] - yAxesLowerLimit = config['set_axes_position_component'][ 2 ] - yAxesUpperLimit = config['set_axes_position_component'][ 3 ] - print "Using user defined axes limits for position component plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( errorX ) / float( len( errorX ) ) - else: - weights = None - n, bins, patches = plt.hist( errorX, bins=200, \ - range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, weights=weights, \ - color=xcolor, alpha=1, label=xlegend, log=False ) - n, bins, patches = plt.hist( errorY, bins=200, \ - range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, weights=weights, \ - color=ycolor, alpha=1, label=ylegend, log=False ) - n, bins, patches = plt.hist( errorZ, bins=200, \ - range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, weights=weights, \ - color=zcolor, alpha=1, label=zlegend, log=False ) - if yAxesUpperLimit != 0: - plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) - - if flag == False and config['set_axes_velocity_component_flag'] == 'True': - xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] - xAxesUpperLimit = config['set_axes_velocity_component'][ 1 ] - yAxesLowerLimit = config['set_axes_velocity_component'][ 2 ] - yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] - print "Using user defined axes limits for velocity component plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( errorX ) / float( len( errorX ) ) - else: - weights = None - n, bins, patches = plt.hist( errorX, bins=200, \ - range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, weights=weights, \ - color=xcolor, alpha=1, label=xlegend, log=False ) - n, bins, patches = plt.hist( errorY, bins=200, \ - range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, weights=weights, \ - color=ycolor, alpha=1, label=ylegend, log=False ) - n, bins, patches = plt.hist( errorZ, bins=200, \ - range=(xAxesLowerLimit, xAxesUpperLimit), \ - histtype='step', normed=False, weights=weights, \ - color=zcolor, alpha=1, label=zlegend, log=False ) - if yAxesUpperLimit != 0: - plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) - - if config['set_axes_velocity_component_flag'] == 'False' \ - and config['set_axes_position_component_flag'] == 'False': - if config['normed'] == 'True': - weights = np.ones_like( errorX ) / float( len( errorX ) ) - else: - weights = None - n, bins, patches = plt.hist( errorX, bins=200, \ - histtype='step', normed=False, weights=weights, \ - color=xcolor, alpha=1, label=xlegend, log=False ) - n, bins, patches = plt.hist( errorY, bins=200, \ - histtype='step', normed=False, weights=weights, \ - color=ycolor, alpha=1, label=ylegend, log=False ) - n, bins, patches = plt.hist( errorZ, bins=200, \ - histtype='step', normed=False, weights=weights, \ - color=zcolor, alpha=1, label=zlegend, log=False ) - - # Figure properties - if config[ 'add_title' ] == 'True': - plt.title( plotTitle ) - plt.xlabel( xAxisLabel ) - plt.ylabel( yAxisLabel ) - - xLegend = mlines.Line2D( [], [], color=xcolor, label=xlegend ) - yLegend = mlines.Line2D( [], [], color=ycolor, label=ylegend ) - zLegend = mlines.Line2D( [], [], color=zcolor, label=zlegend ) - lines = [xLegend, yLegend, zLegend] - labels = [line.get_label( ) for line in lines] - plt.legend(lines, labels) - - plt.grid( True ) - -# Function to plot the components of position/velocity error vector using line and markers -# @param[in] errorX x component -# @param[in] errorY y component -# @param[in] errorZ z component -# @param[in] xcolor x component color in the plot -# @param[in] ycolor y component color in the plot -# @param[in] zcolor z component color in the plot -# @param[in] xlegend legend for the x component curve in the plot -# @param[in] ylegend legend for the y component curve in the plot -# @param[in] zlegend legend for the z component curve in the plot -# @param[in] xAxisLabel Label for the X axis -# @param[in] yAxisLabel Label for the Y axis -# @param[in] zAxisLabel Label for the Z axis -# @param[in] flag Set True if position error vector is being plotted, else False -def plotComponentsMarkers( errorX, errorY, errorZ, \ - xcolor, ycolor, zcolor, \ - xlegend, ylegend, zlegend, \ - xAxisLabel, yAxisLabel, plotTitle, \ - flag ): - - if flag == True and config['set_axes_position_component_flag'] == 'True': - xAxesLowerLimit = config['set_axes_position_component'][ 0 ] - xAxesUpperLimit = config['set_axes_position_component'][ 1 ] - yAxesLowerLimit = config['set_axes_position_component'][ 2 ] - yAxesUpperLimit = config['set_axes_position_component'][ 3 ] - print "Using user defined axes limits for position component plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( errorX ) / float( len( errorX ) ) - else: - weights = None - xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ - weights=weights ) - xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 - - yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ - weights=weights ) - yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 - - zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ - weights=weights ) - zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 - - xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ - linestyle='solid', linewidth=2, \ - color=xcolor, label=xlegend, \ - marker='s', markersize=6, markerfacecolor=xcolor ) - - yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ - linestyle='solid', linewidth=2, \ - color=ycolor, label=ylegend, \ - marker='v', markersize=6, markerfacecolor=ycolor ) - - zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ - linestyle='solid', linewidth=2, \ - color=zcolor, label=zlegend, \ - marker='*', markersize=6, markerfacecolor=zcolor ) - - - markerFigure = plt.figure( ) - ax = markerFigure.add_subplot( 1, 1, 1 ) - ax.add_line( xMarkerLine ) - ax.add_line( yMarkerLine ) - ax.add_line( zMarkerLine ) - xmin, xmax, ymin, ymax = ax.axis('auto') - ax.set_xlim( xmin, xmax ) - ax.set_ylim( ymin, ymax ) - if yAxesUpperLimit != 0: - ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) - - if flag == False and config['set_axes_velocity_component_flag'] == 'True': - xAxesLowerLimit = config['set_axes_velocity_component'][ 0 ] - xAxesUpperLimit = config['set_axes_velocity_component'][ 1 ] - yAxesLowerLimit = config['set_axes_velocity_component'][ 2 ] - yAxesUpperLimit = config['set_axes_velocity_component'][ 3 ] - print "Using user defined axes limits for velocity component plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( errorX ) / float( len( errorX ) ) - else: - weights = None - xDataHist, xBinEdges = np.histogram( errorX, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ - weights=weights ) - xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 - - yDataHist, yBinEdges = np.histogram( errorY, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ - weights=weights ) - yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 - - zDataHist, zBinEdges = np.histogram( errorZ, bins=50, \ - range=(xAxesLowerLimit, xAxesUpperLimit), normed=False, \ - weights=weights ) - zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 - - xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ - linestyle='solid', linewidth=2, \ - color=xcolor, label=xlegend, \ - marker='s', markersize=6, markerfacecolor=xcolor ) - - yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ - linestyle='solid', linewidth=2, \ - color=ycolor, label=ylegend, \ - marker='v', markersize=6, markerfacecolor=ycolor ) - - zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ - linestyle='solid', linewidth=2, \ - color=zcolor, label=zlegend, \ - marker='*', markersize=6, markerfacecolor=zcolor ) - - - markerFigure = plt.figure( ) - ax = markerFigure.add_subplot( 1, 1, 1 ) - ax.add_line( xMarkerLine ) - ax.add_line( yMarkerLine ) - ax.add_line( zMarkerLine ) - xmin, xmax, ymin, ymax = ax.axis('auto') - ax.set_xlim( xmin, xmax ) - ax.set_ylim( ymin, ymax ) - if yAxesUpperLimit != 0: - ax.set_ylim( yAxesLowerLimit, yAxesUpperLimit ) - - if config['set_axes_position_component_flag'] == 'False' \ - and config['set_axes_velocity_component_flag'] == 'False': - if config['normed'] == 'True': - weights = np.ones_like( errorX ) / float( len( errorX ) ) - else: - weights = None - xDataHist, xBinEdges = np.histogram( errorX, bins=50, normed=False, weights=weights ) - xBinCentre = ( xBinEdges[:-1] + xBinEdges[1:] ) / 2 - - yDataHist, yBinEdges = np.histogram( errorY, bins=50, normed=False, weights=weights ) - yBinCentre = ( yBinEdges[:-1] + yBinEdges[1:] ) / 2 - - zDataHist, zBinEdges = np.histogram( errorZ, bins=50, normed=False, weights=weights ) - zBinCentre = ( zBinEdges[:-1] + zBinEdges[1:] ) / 2 - - xMarkerLine = mlines.Line2D( xBinCentre, xDataHist, \ - linestyle='solid', linewidth=2, \ - color=xcolor, label=xlegend, \ - marker='s', markersize=6, markerfacecolor=xcolor ) - - yMarkerLine = mlines.Line2D( yBinCentre, yDataHist, \ - linestyle='solid', linewidth=2, \ - color=ycolor, label=ylegend, \ - marker='v', markersize=6, markerfacecolor=ycolor ) - - zMarkerLine = mlines.Line2D( zBinCentre, zDataHist, \ - linestyle='solid', linewidth=2, \ - color=zcolor, label=zlegend, \ - marker='*', markersize=6, markerfacecolor=zcolor ) - - - markerFigure = plt.figure( ) - ax = markerFigure.add_subplot( 1, 1, 1 ) - ax.add_line( xMarkerLine ) - ax.add_line( yMarkerLine ) - ax.add_line( zMarkerLine ) - xmin, xmax, ymin, ymax = ax.axis('auto') - ax.set_xlim( xmin, xmax ) - ax.set_ylim( ymin, ymax ) - - # Figure properties - plt.xlabel( xAxisLabel ) - plt.ylabel( yAxisLabel ) - - if config[ 'add_title' ] == 'True': - plt.title( plotTitle ) - - plt.legend( ) - plt.grid( True ) - - -errorType = [ "arrival_position", "arrival_velocity" ] - -# Fetch scan data. -scan_data = pd.read_sql( "SELECT arrival_position_x_error, \ - arrival_position_y_error, \ - arrival_position_z_error, \ - arrival_position_error, \ - arrival_velocity_x_error, \ - arrival_velocity_y_error, \ - arrival_velocity_z_error, \ - arrival_velocity_error \ - FROM sgp4_scanner_results \ - WHERE success = 1;", \ - database ) - -scan_data.columns = [ 'positionErrorX', \ - 'positionErrorY', \ - 'positionErrorZ', \ - 'positionErrorMagnitude', \ - 'velocityErrorX', \ - 'velocityErrorY', \ - 'velocityErrorZ', \ - 'velocityErrorMagnitude' ] - -lambert_scan_data = pd.read_sql( "SELECT lambert_scanner_results.arrival_position_x, \ - lambert_scanner_results.arrival_position_y, \ - lambert_scanner_results.arrival_position_z, \ - lambert_scanner_results.arrival_velocity_x, \ - lambert_scanner_results.arrival_velocity_y, \ - lambert_scanner_results.arrival_velocity_z \ - FROM lambert_scanner_results \ - INNER JOIN sgp4_scanner_results \ - ON lambert_scanner_results.transfer_id = \ - sgp4_scanner_results.lambert_transfer_id \ - AND sgp4_scanner_results.success = 1;", - database ) - -lambert_scan_data.columns = [ 'arrivalPositionX', \ - 'arrivalPositionY', \ - 'arrivalPositionZ', \ - 'arrivalVelocityX', \ - 'arrivalVelocityY', \ - 'arrivalVelocityZ' ] - -if config['add_j2'] == "True": - j2_analysis_data = pd.read_sql( "SELECT arrival_position_x_error, \ - arrival_position_y_error, \ - arrival_position_z_error, \ - arrival_position_error, \ - arrival_velocity_x_error, \ - arrival_velocity_y_error, \ - arrival_velocity_z_error, \ - arrival_velocity_error \ - FROM j2_analysis_results;", \ - database ) - - j2_analysis_data.columns = [ 'positionErrorX', \ - 'positionErrorY', \ - 'positionErrorZ', \ - 'positionErrorMagnitude', \ - 'velocityErrorX', \ - 'velocityErrorY', \ - 'velocityErrorZ', \ - 'velocityErrorMagnitude' ] - - -print "Fetch successful!" -print "" - -for errorTypeIndex in range( len( errorType ) ): - if errorType[ errorTypeIndex ] == "arrival_position": - print "Plotting position error magnitude histogram ..." - print "" - magnitudeError = scan_data[ 'positionErrorMagnitude' ] - if config['add_j2'] == "True": - j2magnitudeError = j2_analysis_data[ 'positionErrorMagnitude' ] - else: - print "" - print "Plotting velocity error magnitude histogram ..." - print "" - magnitudeError = scan_data[ 'velocityErrorMagnitude' ] - if config['add_j2'] == "True": - j2magnitudeError = j2_analysis_data[ 'velocityErrorMagnitude' ] - - # Calculate mean, variance and standard deviation - mu = sum( magnitudeError ) / len( magnitudeError ) - print 'Mean = ' + repr( mu ) - - sumOfSquareDeviations = sum( ( x - mu )**2 for x in magnitudeError ) - variance = sumOfSquareDeviations / len( magnitudeError ) - print 'Variance = ' + repr( variance ) - - sigma = variance**0.5 - print 'Standard Deviation = ' + repr( sigma ) - - # Plot the magnitude of the error - if config['grayscale'] == 'False': - figureColor = 'green' - j2CurveColor = 'red' - else: - figureColor = '0.40' - j2CurveColor = '1' - - if config['add_j2'] == "True": - if errorType[ errorTypeIndex ] == 'arrival_position': - if config[ 'set_axes_position_magnitude_flag' ] == 'True': - xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] - xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] - yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] - yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] - - print "Using user defined axes limits for position magnitude J2 plot..." - print "" - n, bins, patches = plt.hist( magnitudeError, bins=50, \ - range=( xAxesLowerLimit, xAxesUpperLimit ), \ - normed=False, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - n, bins, patches = plt.hist( j2magnitudeError, bins=50, \ - range=( xAxesLowerLimit, xAxesUpperLimit ), \ - histtype='step', \ - normed=False, color=j2CurveColor, \ - alpha=1, label='J2' ) - if yAxesUpperLimit != 0: - plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) - else: - n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ - normed=False, color=j2CurveColor, alpha=1, label='J2' ) - else: - if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': - xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] - xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] - yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] - yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] - print "Using user defined axes limits for velocity magnitude J2 plot..." - print "" - n, bins, patches = plt.hist( magnitudeError, bins=50, \ - range=( xAxesLowerLimit, xAxesUpperLimit ), \ - normed=False, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - n, bins, patches = plt.hist( j2magnitudeError, bins=50, \ - range=( xAxesLowerLimit, xAxesUpperLimit ), \ - histtype='step', \ - normed=False, color=j2CurveColor, \ - alpha=1, label='J2' ) - if yAxesUpperLimit != 0: - plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) - else: - n, bins, patches = plt.hist( magnitudeError, bins=50, normed=False, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - n, bins, patches = plt.hist( j2magnitudeError, bins=50, histtype='step', \ - normed=False, color=j2CurveColor, alpha=1, label='J2' ) - - - j2Legend = mlines.Line2D( [], [], color=j2CurveColor, label='J2' ) - magnitudeLegend = mpatches.Patch( color=figureColor, label='Magnitude' ) - lines = [ magnitudeLegend, j2Legend ] - labels = [ line.get_label( ) for line in lines ] - plt.legend( lines, labels ) - else: - if errorType[ errorTypeIndex ] == 'arrival_position': - if config[ 'set_axes_position_magnitude_flag' ] == 'True': - xAxesLowerLimit = config['set_axes_position_magnitude'][ 0 ] - xAxesUpperLimit = config['set_axes_position_magnitude'][ 1 ] - yAxesLowerLimit = config['set_axes_position_magnitude'][ 2 ] - yAxesUpperLimit = config['set_axes_position_magnitude'][ 3 ] - print "Using user defined axes limits for position magnitude plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) - else: - weights = None - n, bins, patches = plt.hist( magnitudeError, bins=50, \ - range=( xAxesLowerLimit, xAxesUpperLimit ), \ - normed=False, weights=weights, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - if yAxesUpperLimit != 0: - plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) - else: - print "Using auto axes limits for position magnitude plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) - else: - weights = None - n, bins, patches = plt.hist( magnitudeError, bins=50, \ - normed=False, weights=weights, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - else: - if config[ 'set_axes_velocity_magnitude_flag' ] == 'True': - xAxesLowerLimit = config['set_axes_velocity_magnitude'][ 0 ] - xAxesUpperLimit = config['set_axes_velocity_magnitude'][ 1 ] - yAxesLowerLimit = config['set_axes_velocity_magnitude'][ 2 ] - yAxesUpperLimit = config['set_axes_velocity_magnitude'][ 3 ] - print "Using user defined axes limits for velocity magnitude plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) - else: - weights = None - n, bins, patches = plt.hist( magnitudeError, bins=50, \ - range=( xAxesLowerLimit, xAxesUpperLimit ), \ - normed=False, \ - weights=weights, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - if yAxesUpperLimit != 0: - plt.ylim( yAxesLowerLimit, yAxesUpperLimit ) - else: - print "Using auto axes limits for velocity magnitude plot..." - print "" - if config['normed'] == 'True': - weights = np.ones_like( magnitudeError ) / float( len( magnitudeError ) ) - else: - weights = None - n, bins, patches = plt.hist( magnitudeError, bins=50, \ - normed=False, weights=weights, \ - facecolor=figureColor, alpha=1, label='Magnitude' ) - # plt.legend( ) - - # Select appropriate unit and title for the error type - if errorType[ errorTypeIndex ] == 'arrival_position': - plotTitle = 'Arrival Position Error' - xAxisLabel = 'Arrival position error [km]' - else: - plotTitle = 'Arrival Velocity Error' - xAxisLabel = 'Arrival velocity error [km/s]' - - # Figure properties - plt.xlabel( xAxisLabel ) - plt.ylabel( 'Frequency' ) - - if config[ 'add_title' ] == 'True': - plt.title( plotTitle + " " + 'Magnitude' ) - - plt.grid( True ) - - # Save figure to file. - if config['add_j2'] == "True": - plt.savefig( output_path_prefix + "J2_" + config["histogram_figure"] + "_" - + errorType[ errorTypeIndex ] + "_error" + "_magnitude" - + config["figure_format"], dpi=config["figure_dpi"] ) - plt.close( ) - else: - plt.savefig( output_path_prefix + config["histogram_figure"] + "_" - + errorType[ errorTypeIndex ] + "_error" + "_magnitude" - + config["figure_format"], dpi=config["figure_dpi"] ) - plt.close( ) - -# Plot the components of the (position/velocity) error vector in a separate figure. -if config['grayscale'] == 'False': - xcolor = 'red' - ycolor = 'blue' - zcolor = 'black' -else: - xcolor = '0' - ycolor = '0.30' - zcolor = '0.60' - -positionErrorX = scan_data[ 'positionErrorX' ] -positionErrorY = scan_data[ 'positionErrorY' ] -positionErrorZ = scan_data[ 'positionErrorZ' ] -velocityErrorX = scan_data[ 'velocityErrorX' ] -velocityErrorY = scan_data[ 'velocityErrorY' ] -velocityErrorZ = scan_data[ 'velocityErrorZ' ] - -if config['frame'] == "RTN": - # ECI to RTN frame transformation. - print "" - print "Performing ECI to RTN frame conversion for the position and velocity error vectors ..." - print "" - - arrivalPositionX = lambert_scan_data[ 'arrivalPositionX' ] - arrivalPositionY = lambert_scan_data[ 'arrivalPositionY' ] - arrivalPositionZ = lambert_scan_data[ 'arrivalPositionZ' ] - arrivalVelocityX = lambert_scan_data[ 'arrivalVelocityX' ] - arrivalVelocityY = lambert_scan_data[ 'arrivalVelocityY' ] - arrivalVelocityZ = lambert_scan_data[ 'arrivalVelocityZ' ] - - totalCases = len( arrivalPositionX ) - gamma = np.zeros( shape=( 3, 3 ), dtype=float ) - - for i in tqdm( range( totalCases ) ): - gamma = gammaECI2RTN( arrivalPositionX[ i ], \ - arrivalPositionY[ i ], \ - arrivalPositionZ[ i ], \ - arrivalVelocityX[ i ], \ - arrivalVelocityY[ i ], \ - arrivalVelocityZ[ i ] ) - - positionErrorVectorECI = [ positionErrorX[ i ], positionErrorY[ i ], positionErrorZ[ i ] ] - velocityErrorVectorECI = [ velocityErrorX[ i ], velocityErrorY[ i ], velocityErrorZ[ i ] ] - - positionErrorX[ i ] = np.inner( gamma[ 0 ][ : ], positionErrorVectorECI ) - positionErrorY[ i ] = np.inner( gamma[ 1 ][ : ], positionErrorVectorECI ) - positionErrorZ[ i ] = np.inner( gamma[ 2 ][ : ], positionErrorVectorECI ) - - velocityErrorX[ i ] = np.inner( gamma[ 0 ][ : ], velocityErrorVectorECI ) - velocityErrorY[ i ] = np.inner( gamma[ 1 ][ : ], velocityErrorVectorECI ) - velocityErrorZ[ i ] = np.inner( gamma[ 2 ][ : ], velocityErrorVectorECI ) - - print "Plotting position error components defined in RTN frame" - - if config['component_marker'] == "False": - plotComponents( positionErrorX, positionErrorY, positionErrorZ, \ - xcolor, ycolor, zcolor, \ - "Radial", "Transverse", "Normal", \ - "Arrival position error [km]", "Frequency", "Position Error Components", \ - True ) - else: - plotComponentsMarkers( positionErrorX, positionErrorY, positionErrorZ, \ - xcolor, ycolor, zcolor, \ - "Radial", "Transverse", "Normal", \ - "Arrival position error [km]", "Frequency", \ - "Position Error Components", True ) - - # Save figure to file. - plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_position_error" - + "_components_" + config["frame"] + config["figure_format"], \ - dpi=config["figure_dpi"] ) - plt.close( ) - - print "Plotting velocity error components defined in RTN frame" - - if config['component_marker'] == "False": - plotComponents( velocityErrorX, velocityErrorY, velocityErrorZ, \ - xcolor, ycolor, zcolor, \ - "Radial", "Transverse", "Normal", \ - "Arrival velocity error [km/s]", "Frequency", "Velocity Error Components",\ - False ) - else: - plotComponentsMarkers( velocityErrorX, velocityErrorY, velocityErrorZ, \ - xcolor, ycolor, zcolor, \ - "Radial", "Transverse", "Normal", \ - "Arrival velocity error [km/s]", "Frequency", \ - "Velocity Error Components", False ) - - # Save figure to file. - plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_velocity_error" - + "_components_" + config["frame"] + config["figure_format"], \ - dpi=config["figure_dpi"] ) - plt.close( ) - -else: - print "Plotting position error components defined in ECI frame" - - if config['component_marker'] == "False": - plotComponents( positionErrorX, positionErrorY, positionErrorZ, \ - xcolor, ycolor, zcolor, \ - "X Axis", "Y Axis", "Z Axis", \ - "Arrival position error [km]", "Frequency", "Position Error Components", \ - True ) - else: - plotComponentsMarkers( positionErrorX, positionErrorY, positionErrorZ, \ - xcolor, ycolor, zcolor, \ - "X Axis", "Y Axis", "Z Axis", \ - "Arrival position error [km]", "Frequency", \ - "Position Error Components", True ) - - # Save figure to file. - plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_position_error" - + "_components_" + config["frame"] + config["figure_format"], \ - dpi=config["figure_dpi"] ) - plt.close( ) - - print "Plotting velocity error components defined in ECI frame" - - if config['component_marker'] == "False": - plotComponents( velocityErrorX, velocityErrorY, velocityErrorZ, \ - xcolor, ycolor, zcolor, \ - "X Axis", "Y Axis", "Z Axis", \ - "Arrival velocity error [km/s]", "Frequency", "Velocity Error Components",\ - False ) - else: - plotComponentsMarkers( velocityErrorX, velocityErrorY, velocityErrorZ, \ - xcolor, ycolor, zcolor, \ - "X Axis", "Y Axis", "Z Axis", \ - "Arrival velocity error [km/s]", "Frequency", \ - "Velocity Error Components", False ) - - # Save figure to file. - plt.savefig( output_path_prefix + config["histogram_figure"] + "_arrival_velocity_error" - + "_components_" + config["frame"] + config["figure_format"], \ - dpi=config["figure_dpi"] ) - plt.close( ) - -print "All figures generated successfully!" -print "" - -# Close SQLite database if it's still open. -if database: - database.close( ) - -# Stop timer -end_time = time.time( ) - -# Print elapsed time -print "Script time: " + str("{:,g}".format(end_time - start_time)) + "s" - -print "" -print "------------------------------------------------------------------" -print " Exited successfully! " -print "------------------------------------------------------------------" -print "" From 39d696f3c09e4fddc16c4194fd5eddc3e09daa06 Mon Sep 17 00:00:00 2001 From: Abhishek Agrawal Date: Fri, 13 May 2016 17:45:15 +0200 Subject: [PATCH 10/10] Y axis label mod --- python/plot_sgp4_error_histogram.py | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/python/plot_sgp4_error_histogram.py b/python/plot_sgp4_error_histogram.py index 98e19f0..16f3105 100644 --- a/python/plot_sgp4_error_histogram.py +++ b/python/plot_sgp4_error_histogram.py @@ -659,7 +659,10 @@ def plotComponentsMarkers( errorX, errorY, errorZ, # Figure properties plt.xlabel( xAxisLabel ) - plt.ylabel( 'Frequency' ) + if config['normed'] == 'True': + plt.ylabel( 'Normalized frequency' ) + else: + plt.ylabel( 'Frequency' ) if config[ 'add_title' ] == 'True': plt.title( plotTitle + " " + 'Magnitude' ) @@ -730,19 +733,24 @@ def plotComponentsMarkers( errorX, errorY, errorZ, velocityErrorY[ i ] = np.inner( gamma[ 1 ][ : ], velocityErrorVectorECI ) velocityErrorZ[ i ] = np.inner( gamma[ 2 ][ : ], velocityErrorVectorECI ) + if config['normed'] == 'True': + yAxisLabels = "Normalized frequency" + else: + yAxisLabels = "Frequency" + print "Plotting position error components defined in RTN frame" if config['component_marker'] == "False": plotComponents( positionErrorX, positionErrorY, positionErrorZ, \ xcolor, ycolor, zcolor, \ "Radial", "Transverse", "Normal", \ - "Arrival position error [km]", "Frequency", "Position Error Components", \ + "Arrival position error [km]", yAxisLabels, "Position Error Components", \ True ) else: plotComponentsMarkers( positionErrorX, positionErrorY, positionErrorZ, \ xcolor, ycolor, zcolor, \ "Radial", "Transverse", "Normal", \ - "Arrival position error [km]", "Frequency", \ + "Arrival position error [km]", yAxisLabels, \ "Position Error Components", True ) # Save figure to file. @@ -757,13 +765,13 @@ def plotComponentsMarkers( errorX, errorY, errorZ, plotComponents( velocityErrorX, velocityErrorY, velocityErrorZ, \ xcolor, ycolor, zcolor, \ "Radial", "Transverse", "Normal", \ - "Arrival velocity error [km/s]", "Frequency", "Velocity Error Components",\ + "Arrival velocity error [km/s]", yAxisLabels, "Velocity Error Components",\ False ) else: plotComponentsMarkers( velocityErrorX, velocityErrorY, velocityErrorZ, \ xcolor, ycolor, zcolor, \ "Radial", "Transverse", "Normal", \ - "Arrival velocity error [km/s]", "Frequency", \ + "Arrival velocity error [km/s]", yAxisLabels, \ "Velocity Error Components", False ) # Save figure to file. @@ -773,19 +781,25 @@ def plotComponentsMarkers( errorX, errorY, errorZ, plt.close( ) else: + + if config['normed'] == 'True': + yAxisLabels = "Normalized frequency" + else: + yAxisLabels = "Frequency" + print "Plotting position error components defined in ECI frame" if config['component_marker'] == "False": plotComponents( positionErrorX, positionErrorY, positionErrorZ, \ xcolor, ycolor, zcolor, \ "X Axis", "Y Axis", "Z Axis", \ - "Arrival position error [km]", "Frequency", "Position Error Components", \ + "Arrival position error [km]", yAxisLabels, "Position Error Components", \ True ) else: plotComponentsMarkers( positionErrorX, positionErrorY, positionErrorZ, \ xcolor, ycolor, zcolor, \ "X Axis", "Y Axis", "Z Axis", \ - "Arrival position error [km]", "Frequency", \ + "Arrival position error [km]", yAxisLabels, \ "Position Error Components", True ) # Save figure to file. @@ -800,13 +814,13 @@ def plotComponentsMarkers( errorX, errorY, errorZ, plotComponents( velocityErrorX, velocityErrorY, velocityErrorZ, \ xcolor, ycolor, zcolor, \ "X Axis", "Y Axis", "Z Axis", \ - "Arrival velocity error [km/s]", "Frequency", "Velocity Error Components",\ + "Arrival velocity error [km/s]", yAxisLabels, "Velocity Error Components",\ False ) else: plotComponentsMarkers( velocityErrorX, velocityErrorY, velocityErrorZ, \ xcolor, ycolor, zcolor, \ "X Axis", "Y Axis", "Z Axis", \ - "Arrival velocity error [km/s]", "Frequency", \ + "Arrival velocity error [km/s]", yAxisLabels, \ "Velocity Error Components", False ) # Save figure to file.