Subscribe Bookmark RSS Feed

Overlay plot that checks for and plots only those columns present

terapin

Community Trekker

Joined:

Jun 23, 2011

I would like to create a single JSL script that will create a V List Box of overlay plots only for those columns that exist in a data file. The names of the columns may change from file to file, or may be absent or present.  I can't figure out how to create an Overlay Plot where I list all possible variables to be plotted, but only plot those present in the current data table.


Any suggestions would be greatly appreciated.

For example, plot the following soil temperatures if present in the current data table, but assume that the last column (Tsoil - 10cm #2 (C), or any other column for that matter, is absent.

Clear Log();

sdate = Date MDY( 10, 1, 2010 );

sdate_view = Format( sdate, "m/d/y h:m" );

n_rows = N Rows();

edate = :Name( "Date & Time" )[n_rows] + 500000;

edate_view = Format( edate, "m/d/y h:m" );

dt = Current Data Table();

dt << Clear Row States;

win1 = New Window( "Hourly Plots",

  V List Box(

  op1 = Overlay Plot(

  X( :Name( "Date & Time" ) ),

  Y( :Name( "Tsoil - 5cm (C)" ), :Name( "Tsoil - 10 cm (C)" ), :Name( "Tsoil - 10cm #2 (C)" ) )),

  Where( :Name( "Date & Time" ) >= sdate & :Name( "Date & Time" ) <= edate ),

  Separate Axes( 1 ),

  Connect Thru Missing( 1 )

  ),

  Report( op1 )[Frame Box( 1 )] << {Frame Size( 700, 250 ), Marker Size( 1 ), DispatchSeg( Marker Seg( 1 ), {Color( "Red" )} )},

  Report( op1 )[Axis Box( 1 )] << Axis Settings( {Format( "Fixed Dec", 10, 1 ), Inc( 0.5 ), Minor Ticks( 0 ), Show Major Grid( 1 )} ),

  Report( op1 )[Axis Box( 2 )] << Axis Settings(

  {Format( "m/d/y", 10 ), Interval( "Day" ), Inc( 14 ), Minor Ticks( 0 ), Show Major Grid( 1 ), Show Minor Grid( 0 ), Min( sdate ),

  Max( edate )}

  ) << Remove Axis Label << Add Axis Label( "Date & Time" ),

  )

);

2 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

you can accomplish what you want by capturing the column found in the data table and then using the list created as you Y columns.

Clear Log();

sdate = Date MDY( 10, 1, 2010 );

sdate_view = Format( sdate, "m/d/y h:m" );

n_rows = N Rows();

edate = :Name( "Date & Time" )[n_rows] + 500000;

edate_view = Format( edate, "m/d/y h:m" );

dt = Current Data Table();

dt << Clear Row States;

colnameslist=dt<<get column names(numeric);

// the list will contain the timestamp column, "Date & Time"

// Remove the "Date & Time" column from the list

remove(thelist,loc(thelist,parse("Name(\!"Date & Time\!")"))[1]);

win1 = New Window( "Hourly Plots",

  V List Box(

  op1 = Overlay Plot(

  X( :Name( "Date & Time" ) ),

// reference the list of names

  Y(     eval(colnameslist)),

  Where( :Name( "Date & Time" ) >= sdate & :Name( "Date & Time" ) <= edate ),

  Separate Axes( 1 ),

  Connect Thru Missing( 1 )

  ),

  Report( op1 )[Frame Box( 1 )] << {Frame Size( 700, 250 ), Marker Size( 1 ), DispatchSeg( Marker Seg( 1 ), {Color( "Red" )} )},

  Report( op1 )[Axis Box( 1 )] << Axis Settings( {Format( "Fixed Dec", 10, 1 ), Inc( 0.5 ), Minor Ticks( 0 ), Show Major Grid( 1 )} ),

  Report( op1 )[Axis Box( 2 )] << Axis Settings(

  {Format( "m/d/y", 10 ), Interval( "Day" ), Inc( 14 ), Minor Ticks( 0 ), Show Major Grid( 1 ), Show Minor Grid( 0 ), Min( sdate ),

  Max( edate )}

  ) << Remove Axis Label << Add Axis Label( "Date & Time" ),

  )

);

Jim
terapin

Community Trekker

Joined:

Jun 23, 2011

Thanks for your reply,

I had been playing with lists and came up with the following solution to my problem before your post.  Similar to what you proposed, but best for my application since it lets me define the potential list of variables that could be found in the numerous data files that need to be plotted.

// *****************************************************************************************************************************************

// Potential Tsoil

pot_cs_tsoil_list = {"Soil Temperature @ Litter (C)", "Soil Temperature @ 5 cm (C)", "Soil Temperature @ 5 cm #2 (C)", "Soil Temperature @ 10 cm (C)",

"Soil Temperature @ 15 cm (C)", "Soil Temperature @ 15 cm #2 (C)", "Soil Temperature @ 30 cm (C)", "Soil Temperature @ 50 cm (C)",

"Soil Temperature @ 70 cm (C)", "Soil Temperature @ 90 cm (C)"};

// Create empty list to hold names of the those measurement variables found in data table

act_cs_tsoil_list = {};

// Run through data table column names and put those that match measurement variable list into new list

For( i = 1, i <= N Items( pot_cs_tsoil_list ), i++,

  If( Contains( dt_col_name_list, pot_cs_tsoil_list ),

  Insert Into( act_cs_tsoil_list, pot_cs_tsoil_list )

  )

);

Thanks for taking the time to respond and for confirming that my approach was a reasonable way to accomplish this.