cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
GardDog
Level III

JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

Hi, I have a script that creates the attached graph of some data points and overlays it with an additional line graph. I need to now be able to calculate the delta between the high and low points in multiple different x coordinates. I am able to do the first one since it includes all the x coordinate values, but I am stumped on how to do it for only the x coordinate values in-between the orange calculated lines, as well as only the only the initial curve on both the left and right side inside of the orange line calculations. Than I wanted to display these values on the graph if possible, or in a text box that is displayed when the graph is made. I have included some images that help to explain the 4 different ranges I need to calculate the delta from, as well as included my current script. The orange line may change depending on the data, since it is based off of a value that the user inputs when you run the script. Any assistance is greatly appreciated. Thanks!

Edge_of_frame_field.JPGFrame_field.JPGFull_field.JPG

framex_value = "";
w = New Window( "Frame size X",// opens a window with a title and this content...
		<<Return Result,
    Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing 
        V List Box( // V and H lists nest to organize the display boxes
            H Center Box( Text Box( "Frame size X" ) ), // a second title, centered
            Spacer Box( size( 1, 20 ) ), // a little vertical space
            H List Box( Text Box( "Frame size X: " ), framex = Number Edit Box( "." ) ), // data entry
            Spacer Box( size( 1, 10 ) ), // a little vertical space
            H Center Box( // center the button
                Button Box( "Create graph", // this script runs when the button is pressed...
                  framex_value = framex << get ;
                   
                    column("X coordinate")<<data type(Numeric)<<Modeling Type(Continuous)<<Format(Best,12);
					New Column ( "New Y", Numeric, Nominal, Width( 5), Formula(Round(Y coordinate)));
					dt =Current Data Table();
					dt << select where( :New Y != 50503 );
					dt << delete rows;
					New Column ( "Normalized", Numeric, Continuous, Width( 10 ), Precision ( 7 ), Formula(IntenCD/Col Max(IntenCD)) );
					New Column ( "Delta" , Numeric, Continuous, Width( 10 ), Precision ( 7 ), Formula(Col Max(IntenCD)-(Col Min(IntenCD))));
					FullMat = matrix(Col Max(IntenCD)-(Col Min(IntenCD)));
					New Column ( "Normalized Field", Numeric, Continuous, Width( 10 ), Precision ( 7 ));
					
					//New Column ( "Normalized Field", Numeric, Continuous, Width( 10 ), Precision ( 7 ));
					//dt << select where( :X coordinate > (76200 - framex_value/2) & :X coordinate < (76200 - framex_value/2) );
					//dt << delete rows:
					//FieldMat = matrix(Col Max(IntenCD)-(Col Min(IntenCD)));
                    
                    New Window( " Delta results: ", modal,
						Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
						V List Box( // V and H lists nest to organize the display boxes
						H List Box( Text Box( "Full plate delta: " ), TextBox( Char( FullMat ) ) ),
						//Spacer Box( size( 1, 10 ) ), // a little vertical space
						//H List Box( Text Box( "Full field delta: " ), TextBox( Char( FieldMat ) ) ),
						//Spacer Box( size( 1, 10 ) ), // a little vertical space
						//H List Box( Text Box( "Edge of field delta: " ), TextBox( Char( 0 ) ) ),
							))
						);
						
					// Determine X Matrix
					xMat = matrix(76200 - (framex_value/2)) |/ matrix(76200 - (framex_value/2)) |/ 
						matrix(76200 + (framex_value/2)) |/ matrix(76200 + (framex_value/2));
					// The yMat is static
					yMat = [1, 0.92, 0.92, 1];

					gb = dt << Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Variables( X( :X Coordinate ), Y( :Normalized ) ),
						Elements( Points( X, Y, Legend( 5 ) ) )
					);

					Report( gb )[FrameBox( 1 )] << Add Graphics Script(
						Pen Color( "orange" );
						Pen Size( 2 );
						Line( xmat, ymat );
					);
					report(gb)[AxisBox(2)] << min(.91);
                    
                    w << closeWindow; // just the dialog, not the report
                )
            )
        )
     )
  
);
2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box


// Is the purpose of the display window below, only to display the values of overallDelta and withinOrangeDelta?
// That is all it is going to do.  It does not allow for any data input, just displaying of those values

overallDelta = 22;
withinOrangeDelta = 15;

New Window( " Delta results: ",
	modal,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
		V List Box( // V and H lists nest to organize the display boxes
			H List Box( Text Box( "Full plate delta: " ), Text Box( Char( overallDelta, 7, 4 ) ) ),
			Spacer Box( size( 1, 10 ) ), // a little vertical space
			H List Box( Text Box( "Full field delta: " ), Text Box( Char( withinOrangeDelta, 7, 4 ) ) ),
			Spacer Box( size( 1, 10 ) ), // a little vertical space
			H List Box( Text Box( "Edge of field delta: " ), Text Box( Char( 0 ) ) ),

		)
	)
);
					
// The leftDelta and rightDelta calculations will be similar to the above withinOrangeDelta, but
// I don't know what the upper and lower boundry values of :Normalized are  or what the interior 
// boundrys for the calclations are 


// The code below will create your X Coordinate by Normalized graph
// If you have generated the xmat and ymat matrices, it will draw your orange line on the chart
// Then at a fixed XY point on the graph, of 500,.92 it will add in the text "Overall Delta = nn.nnnn"
// It is likely, that different data from your sample data will make the positioning of the statistics
// inapproprate if you have a hardwired value of 500,.92 for the display.  So you will need to determine
// what those values need to be.  You can get the values by determining the minimum values in the data table
// or you can query the displayed graph to get the axis minimums and then set the position from there.

gb = dt << Graph Builder(
	Size( 534, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :X Coordinate ), Y( :Normalized ) ),
	Elements( Points( X, Y, Legend( 5 ) ) )
);

Report( gb )[FrameBox( 1 )] << Add Graphics Script(
	Pen Color( "orange" );
	Pen Size( 2 );
	Line( xmat, ymat );
						
						// Add the results to the chart
	Text( 500, .92, "Overall Delta = " || Char( Format( overallDelta, 7, 4 ) ) );
	Text( 500, .915, "Within Delta = " || Char( Format( withinOrangeDelta, 7, 4 ) ) );
);
Report( gb )[AxisBox( 2 )] << Min( .91 );
 
 
 // I don't see any window reference called "w"                   
w << closeWindow; // just the dialog, not the report
Jim

View solution in original post

txnelson
Super User

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

by default, when JMP creates a variable, like your xMat etc.  the variable will remain until it is changed.  And, if on the first run of your code, the required variable hasn't been created, when you are asking for it in your code, it will not have a value to provide the program, and then some calculations will not be able to be run.  However, if later in the script, the variable is set, it will remain set until deleted of changed.  Therefore, when you run the script for a second time, and the code gets to the point where in the first run of the script, it could not find the required variable, this time it will find it, because it was set at a later time in the code during the last run of the script.

I found a possible place where this could have happened.  You were setting the variable dt after activities on the data table were being done.  I moved the line of code further up in the script, so that may get the code to work on a first run.  I also placed a "Clear Symbols()" as the first line of the script.  This will clear out all variables in the code as the script begins.  This will ensure that the variable values referenced will have to have been created in this run of the code, since all of the values from the last run have been erased.  Try the code and see if it works.

Clear Symbols();
Names Default To Here( 1 );

ramex_value = "";
w = New Window( "Frame size X", // opens a window with a title and this content...
	<<Return Result,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing 
		V List Box( // V and H lists nest to organize the display boxes
			H Center Box( Text Box( "Frame size X" ) ), // a second title, centered
			Spacer Box( size( 1, 20 ) ), // a little vertical space
			H List Box( Text Box( "Frame size X: " ), framex = Number Edit Box( "." ) ), // data entry
			Spacer Box( size( 1, 10 ) ), // a little vertical space
			H Center Box( // center the button
				Button Box( "Create graph", // this script runs when the button is pressed...
					framex_value = framex << get;
					
					dt = Current Data Table();
					
					Column( dt, "X coordinate" ) << data type( Numeric ) << Modeling Type( Continuous ) << Format( Best, 12 );
					
					dt << New Column( "New Y", Numeric, Nominal, Width( 5 ), Formula( Round( Y coordinate ) ) );
					
					dt << select where( :New Y != 50503 );
					dt << delete rows;
					dt << New Column( "Normalized", Numeric, Continuous, Width( 10 ), Precision( 7 ), Formula( IntenCD / Col Max( IntenCD ) ) );


					// Determine X Matrix
					xMat = Matrix( 76200 - (framex_value / 2) ) |/ Matrix( 76200 - (framex_value / 2) ) |/ Matrix( 76200 + (framex_value / 2) ) |/
					Matrix( 76200 + (framex_value / 2) );
					// The yMat is static
					yMat = [1, 0.92, 0.92, 1];
					
					// The overall delta
					overallDelta = Col Max( dt:Normalized ) - Col Min( dt:Normalized );
									
					//The delta between the lines
					withinOrangeDelta = Col Max(
						If( dt:X coordinate > (76200 - (framex_value / 2)) & dt:X coordinate < (76200 + (framex_value / 2)),
							dt:Normalized,
							.
						)
					) - Col Max( dt:Normalized ) - Col Min( dt:Normalized ) + 1;
					Col Min( If( dt:X coordinate > (76200 - (framex_value / 2)) & dt:X coordinate < (76200 + (framex_value / 2)), dt:Normalized, . ) );
					
								// Graph Builer and Delta display
					gb = dt << Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Variables( X( dt:X Coordinate ), Y( dt:Normalized ) ),
						Elements( Points( X, Y, Legend( 5 ) ) )
					);

					Report( gb )[FrameBox( 1 )] << Add Graphics Script(
						Pen Color( "orange" );
						Pen Size( 2 );
						Line( xmat, ymat );
													
													// Add the results to the chart
						Text( Boxed, {75000, .94}, "Overall Delta = " || Char( Format( overallDelta, 7, 4 ) ) );
						Text( Boxed, {75000, .93}, "Within Frame Delta = " || Char( Format( withinOrangeDelta, 7, 4 ) ) );
					);
					Report( gb )[AxisBox( 2 )] << Min( .91 );
							
					w << closeWindow;

				)
			)
		)
	)
  
);
Jim

View solution in original post

13 REPLIES 13
txnelson
Super User

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

I have added some code to your chart(untested code), that will calculate the overall and within deltas.  The left and right delta calculations require the rules for defining the boxes.

I have also added a very simple display for the 2 values.

In both cases, I am providing you with the approach that needs to be taken to give you these next enhancements to your code.  I can not guarantee perfect code, but you should see the concept and be able to take it from there 

framex_value = "";
w = New Window( "Frame size X",// opens a window with a title and this content...
		<<Return Result,
    Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing 
        V List Box( // V and H lists nest to organize the display boxes
            H Center Box( Text Box( "Frame size X" ) ), // a second title, centered
            Spacer Box( size( 1, 20 ) ), // a little vertical space
            H List Box( Text Box( "Frame size X: " ), framex = Number Edit Box( "." ) ), // data entry
            Spacer Box( size( 1, 10 ) ), // a little vertical space
            H Center Box( // center the button
                Button Box( "Create graph", // this script runs when the button is pressed...
                  framex_value = framex << get ;
                   
                    column("X coordinate")<<data type(Numeric)<<Modeling Type(Continuous)<<Format(Best,12);
					New Column ( "New Y", Numeric, Nominal, Width( 5), Formula(Round(Y coordinate)));
					dt =Current Data Table();
					dt << select where( :New Y != 50503 );
					dt << delete rows;
					New Column ( "Normalized", Numeric, Continuous, Width( 10 ), Precision ( 7 ), Formula(IntenCD/Col Max(IntenCD)) );
					New Column ( "Delta" , Numeric, Continuous, Width( 10 ), Precision ( 7 ), Formula(Col Max(IntenCD)-(Col Min(IntenCD))));
					FullMat = matrix(Col Max(IntenCD)-(Col Min(IntenCD)));
					New Column ( "Normalized Field", Numeric, Continuous, Width( 10 ), Precision ( 7 ));
					
					//New Column ( "Normalized Field", Numeric, Continuous, Width( 10 ), Precision ( 7 ));
					//dt << select where( :X coordinate > (76200 - framex_value/2) & :X coordinate < (76200 - framex_value/2) );
					//dt << delete rows:
					//FieldMat = matrix(Col Max(IntenCD)-(Col Min(IntenCD)));
                    
                    New Window( " Delta results: ", modal,
						Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
						V List Box( // V and H lists nest to organize the display boxes
						H List Box( Text Box( "Full plate delta: " ), TextBox( Char( FullMat ) ) ),
						//Spacer Box( size( 1, 10 ) ), // a little vertical space
						//H List Box( Text Box( "Full field delta: " ), TextBox( Char( FieldMat ) ) ),
						//Spacer Box( size( 1, 10 ) ), // a little vertical space
						//H List Box( Text Box( "Edge of field delta: " ), TextBox( Char( 0 ) ) ),
							))
						);
						
					// Determine X Matrix
					xMat = matrix(76200 - (framex_value/2)) |/ matrix(76200 - (framex_value/2)) |/ 
						matrix(76200 + (framex_value/2)) |/ matrix(76200 + (framex_value/2));
					// The yMat is static
					yMat = [1, 0.92, 0.92, 1];
					
					// The overall delta
					overallDelta = Col Max( :Normalized ) - Col Min( :Normalized );
					
					// The delta between the lines
					withinOrangeDelta = Col Max(
						If( :X coordinate > (76200 - (framex_value / 2)) & :X coordinate < (76200 + (framex_value / 2)),
							:Normalize,
							.
						)
					) - Col Max( :Normalized ) - Col Min( :Normalized );
					withinOrangeDelta = Col Min(
						If( :X coordinate > (76200 - (framex_value / 2)) & :X coordinate < (76200 + (framex_value / 2)),
							:Normalize,
							.
						)
					);
					
					// The leftDelta and rightDelta calculations will be similar to the above withinOrangeDelta, but
					// I don't know what the upper and lower boundry values of :Normalized are  or what the interior 
					// boundrys for the calclations are 

					gb = dt << Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Variables( X( :X Coordinate ), Y( :Normalized ) ),
						Elements( Points( X, Y, Legend( 5 ) ) )
					);

					Report( gb )[FrameBox( 1 )] << Add Graphics Script(
						Pen Color( "orange" );
						Pen Size( 2 );
						Line( xmat, ymat );
						
						// Add the results to the chart
						text ( 500,.92, "Overall Delta = " || char(format(overallDelta, 7,4)));
						text ( 500,.915, "Within Delta = " || char(format(withinOrangeDelta, 7,4)));
					);
					report(gb)[AxisBox(2)] << min(.91);
                    
                    w << closeWindow; // just the dialog, not the report
                )
            )
        )
     )
  
);
Jim
GardDog
Level III

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

Awesome, thanks. This looks great. I will give it a try and see how it works. I really appreciate the help with this.

GardDog
Level III

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

Thanks for the help on this, I am still having some issues though. When I run the script I am getting the following error. 

 

Name Unresolved: Normalize{16} in access or evaluation of 'Normalize' , :Normalize/*###*/

 

Also If I comment this section out that is having the problem, to test the display comments they are not showing up in the graph. 

 

Could you please help me to understand the issue with these?

thanks.

txnelson
Super User

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

Normalized column is created from the data table you provide.  What data did you use to create the graphs you show......the "Normalized" column is used as one of the Axis values in those graphs

Jim
GardDog
Level III

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

So the instances in the code where is says :Normalize, this should actually be :Normalized?

 

GardDog_0-1598032538418.png

 

txnelson
Super User

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

Yes.......apparently it is my typo.....sorrry
Jim
GardDog
Level III

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

No worries, that is what I was wondering. 

 

How about the text showing up in the chart? I am not seeing this. I am able to make a pop-up window that opens before the graph with the values, but I really liked your idea of having those values displayed on the chart so that they are able to be viewed with the graph. Is there something that I am missing there?

I included just the end of the script for reference.

 

Thanks again for all the help on this!

 

New Window( " Delta results: ", modal,
						Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
						V List Box( // V and H lists nest to organize the display boxes
						H List Box( Text Box( "Full plate delta: " ), TextBox( Char( overallDelta, 7,4 ) ) ),
						Spacer Box( size( 1, 10 ) ), // a little vertical space
						H List Box( Text Box( "Full field delta: " ), TextBox( Char( withinOrangeDelta, 7,4 ) ) ),
						Spacer Box( size( 1, 10 ) ), // a little vertical space
						H List Box( Text Box( "Edge of field delta: " ), TextBox( Char( 0 ) ) ),
							))
						);
					
					// The leftDelta and rightDelta calculations will be similar to the above withinOrangeDelta, but
					// I don't know what the upper and lower boundry values of :Normalized are  or what the interior 
					// boundrys for the calclations are 

					gb = dt << Graph Builder(
						Size( 534, 456 ),
						Show Control Panel( 0 ),
						Variables( X( :X Coordinate ), Y( :Normalized ) ),
						Elements( Points( X, Y, Legend( 5 ) ) )
					);

					Report( gb )[FrameBox( 1 )] << Add Graphics Script(
						Pen Color( "orange" );
						Pen Size( 2 );
						Line( xmat, ymat );
						
						// Add the results to the chart
						text ( 500,.92, "Overall Delta = " || char(format(overallDelta, 7,4)));
						text ( 500,.915, "Within Delta = " || char(format(withinOrangeDelta, 7,4)));
					);
					report(gb)[AxisBox(2)] << min(.91);
                    
                    w << closeWindow; // just the dialog, not the report
                )
            )
        )
     )
  
);
txnelson
Super User

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box


// Is the purpose of the display window below, only to display the values of overallDelta and withinOrangeDelta?
// That is all it is going to do.  It does not allow for any data input, just displaying of those values

overallDelta = 22;
withinOrangeDelta = 15;

New Window( " Delta results: ",
	modal,
	Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
		V List Box( // V and H lists nest to organize the display boxes
			H List Box( Text Box( "Full plate delta: " ), Text Box( Char( overallDelta, 7, 4 ) ) ),
			Spacer Box( size( 1, 10 ) ), // a little vertical space
			H List Box( Text Box( "Full field delta: " ), Text Box( Char( withinOrangeDelta, 7, 4 ) ) ),
			Spacer Box( size( 1, 10 ) ), // a little vertical space
			H List Box( Text Box( "Edge of field delta: " ), Text Box( Char( 0 ) ) ),

		)
	)
);
					
// The leftDelta and rightDelta calculations will be similar to the above withinOrangeDelta, but
// I don't know what the upper and lower boundry values of :Normalized are  or what the interior 
// boundrys for the calclations are 


// The code below will create your X Coordinate by Normalized graph
// If you have generated the xmat and ymat matrices, it will draw your orange line on the chart
// Then at a fixed XY point on the graph, of 500,.92 it will add in the text "Overall Delta = nn.nnnn"
// It is likely, that different data from your sample data will make the positioning of the statistics
// inapproprate if you have a hardwired value of 500,.92 for the display.  So you will need to determine
// what those values need to be.  You can get the values by determining the minimum values in the data table
// or you can query the displayed graph to get the axis minimums and then set the position from there.

gb = dt << Graph Builder(
	Size( 534, 456 ),
	Show Control Panel( 0 ),
	Variables( X( :X Coordinate ), Y( :Normalized ) ),
	Elements( Points( X, Y, Legend( 5 ) ) )
);

Report( gb )[FrameBox( 1 )] << Add Graphics Script(
	Pen Color( "orange" );
	Pen Size( 2 );
	Line( xmat, ymat );
						
						// Add the results to the chart
	Text( 500, .92, "Overall Delta = " || Char( Format( overallDelta, 7, 4 ) ) );
	Text( 500, .915, "Within Delta = " || Char( Format( withinOrangeDelta, 7, 4 ) ) );
);
Report( gb )[AxisBox( 2 )] << Min( .91 );
 
 
 // I don't see any window reference called "w"                   
w << closeWindow; // just the dialog, not the report
Jim
GardDog
Level III

Re: JMP script formula to calculate the delta of multiple different ranges from X coordinates of a .csv file and display on graph, or in a text box

That additional explanation makes sense. I will work on your suggestions. Thank you.