Reply to topic  [ 8 posts ] 
oxy and functions 
Author Message
Yorick Guru

Joined: Sat Jan 22, 2005 2:44 pm
Posts: 86
Location: Pasadena, CA
Post oxy and functions
Yorick 2.2.00x

Should I be expecting this to work ?
Code:
func test(pl){x=y=[0,1];pl,y,x;}

Code:
> test,plg
ERROR (test) expecting scalar string argument
WARNING source code unavailable (try dbdis function)
now at pc= 15 (of 27), failed at pc= 21
To enter debug mode, type <RETURN> now (then dbexit to get out)

The same example does produce the expect result if the function
called is "plg" and it is called wiith a single variable, OR if the first
test is called with "plmk," even with two variables.
Code:
func test(pl){x=y=[0,1];pl,y;}

Expected result also from:
Code:
> func f1(x,y){return x+y;}
> func test(f){x=y=3;return f(x,y);}
> test(f1)
6


Fri Feb 04, 2011 5:09 pm
Profile YIM
Yorick Guru

Joined: Thu May 10, 2007 12:07 pm
Posts: 62
Post 
This is a récurent topic I guess. David will explain better, but basically the problem is a feature on plg and some other plot function which are interpreted differently.
e.i. when you call plg the yorick interpreter call it as plg, y, "y", x, "x"
This feature was to allow, I guess, to print legend on graphical window (but I think nobody use this).

Following your example if you do:
Code:
func test(pl){x=y=[0,1];pl,y,"y", x, "x";}


it should work with plg but not with other function.
[/code]


Sat Feb 05, 2011 7:15 am
Profile
Yorick Guru

Joined: Sat Jan 22, 2005 2:44 pm
Posts: 86
Location: Pasadena, CA
Post 
Thank you. Indeed your first post on the forum, and Daves's answer. discusses this:

http://yorick.sourceforge.net/phpBB2/vi ... highlight=

Note to self: use forum search....


Sat Feb 05, 2011 10:08 am
Profile YIM
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post 
This is a misfeature to make yorick behave like a code 20 years ago by automatically generating legends. When we ran large radhydro simulations, we used to have them generate plots by the tens of thousands, just in case one of them might be useful. When the things you are plotting are complicated functions rather than trivial indexed arrays, the automatic legends are worthless. I hope nobody uses them.

The ugly curve labeling letters (marks=1 keyword) have a similar origin.

One of these days, I will make vg.gs the default graphics style, and insist that users who want the work.gs style and its legends explicitly turn it on. However, I am afraid I am stuck with the stupid treatment of plg and the other basic graphics commands by the yorick parser well into the future. You can create non-special synonyms (maybe pltg, pltm, pltf, etc.) to replace them; your synonyms will not be mangled by the parser and will behave as you expect. By "synonym", I mean an interpreted wrapper that calls the underlying built-in function. It will be messy because these things all handle a large number of keyword arguments; you will have to look in yorick/graph.c to figure out how to write the wrapper. I hope to replace this graphics system with something more modern eventually; the problem is that all the sensible paths forward add a huge list of library dependencies which I cannot supply on all platforms (gtk depends on glib, pango, etc, etc, etc). The agony is how to add this and still provide support for the current very low dependency graphics on stripped down science-only platforms like Blue Gene and its successors.


Sat Feb 05, 2011 2:43 pm
Profile
Yorick Master

Joined: Tue Mar 07, 2006 10:31 pm
Posts: 125
Location: Meudon, France
Post Re:
munro wrote:
By "synonym", I mean an interpreted wrapper that calls the underlying built-in function. It will be messy because these things all handle a large number of keyword arguments; you will have to look in yorick/graph.c to figure out how to write the wrapper.


As a matter of fact, I wrote wrappers for all the plotting routines which accept a single keyword argument. This single argument is a structure which can hold any of the actual keywords. My purpose is to be able to store graphical keywords in a sane way when designing a GUI or something of the sort : a single variable holds all of the display details for a given graphical object.

This is found in graphk.i, distributed with the yutils package.

Regards, Thibaut.


Tue Feb 15, 2011 2:07 am
Profile WWW
Yorick Guru

Joined: Thu May 10, 2007 12:07 pm
Posts: 62
Post Re: oxy and functions
Hi Thierry,

You may be interested on this : http://www.pinpinatla.com/Info/oplot.i

This an object oriented plot with a lot of features. I did one with h_table and I translated and improved to work with oxy object.
I found this very powerful to plot a bunch a graphic with one style and change *almost* everything aspect quickly, because all plot informations ( point symbol, size, color, window, style, x/ytitles, grid, system log etc ... etc ... ) are inside the objects.
The objects have piramidal structure window object can have system object which can have plot object (which can have sub-plot object ), ...

I have copied past here the small tutorial I wrote in the beginning of the file (sorry for the english, I did it fast as usual):

Code:
  oplot is a set of oxy object used to plot graphics. The "data" can be
   separated from the plot object;
   
    - The "plot" objects: created by plot_new
                       They contain plot parameters and can contain other
                       sub-plot inside. The plot is hierarchic that mean
                       that if parameters is not defined in the sub-plot the
                       value of this parameters will be taken on the parent
                       plot.
                       
    - The "system" objects: created by sys_new
                       They contain system parameters and "plot" objects (the
                       ones that gonna be ploted on the system).
                       
    - The "window" objects: created by win_new
                       They contain window parameters and "systems" objects

    - The "master" objects: created by master_new
                       They contain "window" objects

    [+ "Filter" object are different (see help, filter_new)]
   
   Each object have the same  methods:
    new : create a new derived obj and set parameters
    _   : is an alias of new
    set : set parameters and/or sub-object
    get : get parameter
    i   : reorder the sub- object if called as subroutine
          or create a new object, with new order if called
          as function.
    go  : Plot the coresponding object through the hierarchy
    info: Give information on the object

  see help, oplot_methods   for more info about the methods
 
  Tutorial Example:
    Let start with the basic:
     // Let us create a plot object call skyObject
       skyObject = plot_new(plot="plp", size=0.5);
     
  // Create others object derived from the first one:   
       stars    = skyObject(new, color="red", symbol=3 );
       galaxies = skyObject(new, color="green", symbol=8, fill=1);

   // Let us put them in a system object (with random data for instance)
       obj_mag  = sys_new( stars(_,x=random(10), y=random(10)),
                            galaxies(_,x=random(13),y=random(13)),
                            xtitle="Magnitude", ytitle="Mag Error"
                           );
   // Now I can plot it if I want:
       obj_mag, go;
       
   // you found that the symbol is too small you can still change it
   //  On the skyObject (because stars and galaxies are derived from it):
      skyObject, set, size=1.5;
      fma; obj_mag, go;

   // Well you want now to put an other system on the same window
   // So let create an other system object:
      obj_flux  = sys_new(  stars(_,x=random(10), y=random(10)),
                            galaxies(_,x=random(13),y=random(13)),
                            xtitle="Flux", ytitle="Flux Error"
                            );
   // And now we can put them in a window object
   // (the d=0.1 is the space between systems)
     w_mf = win_new( obj_mag, obj_flux,  d=0.1, title="Mag and Fluxed")
   // let us plot it and in the same time set the parameter fma=1 (which
   //   will fma the window before) temporaly,  that mean the parameters
   // will stand only during this "go"
     w_mf, go, fma=1

   // We can put the system on the other way and square the windows
   // and reduce the size of the title
     w_mf, go, fma=1, ny=1, square=1, title_height=12
   // But you can see that this parameters has been set temporarly
     w_mf, go ,fma=1; //will give the same result than before
   // this following will set everything in the window object:
     w_mf, set, fma=1, ny=1, nx=2, square=1, title_height=12
   // I want to change symbols of Galaxies, no problem:
     galaxies, set, symbol=4;
     w_mf, go;

   // USING EXTERNAL DATA
   // In the example above we have set the data inside the systems object
   // wich is not conveniant. The data can be set separatly. Let us create
   // some data:
      data1 = save( "galaxies", save("mag", random(10), "emag", random(10),
                                     "flux", random(10), "eflux", random(10)
                                     ),
                    "stars"   , save("mag", random(10), "emag", random(10),
                                     "flux", random(10), "eflux", random(10)
                                     )                 
                    );
   // Now I gonna recreate galaxies and stars object and set where to
   // find the data;  2 possibilities :
       stars    = skyObject(new, color="red", symbol=3 , data=data1(stars));
       galaxies = skyObject(new, color="green", symbol=8, fill=1,
                            data=data1(galaxies));
                           
  // OR - I prefer to not set directly the data but the path to the subdata, the
  // data will be set later.
     stars    = skyObject(new, color="red", symbol=3 , subdata="stars");
     galaxies = skyObject(new, color="green", symbol=8, fill=1,
                          subdata="galaxies");
  // Okay now I can redefine the system objects, in x and y, instead of
  // putting value, this time I will put a string (coresponding the the data)
  // Again 2 possibilities:
      obj_mag  = sys_new( stars(_, x="mag", y="emag"),
                         galaxies(_, x="mag", y="emag"),
                          xtitle="Magnitude", ytitle="Mag Error"
                        );
  // Or I can do like this, I can define an oxy object call pdefault, which
  // is the default for child plot object.
  // (TO ilustrate I put the limits/relimits params: (see help, sys_new)
       obj_mag  = sys_new( stars, galaxies,
                           xtitle="Magnitude", ytitle="Mag Error",
                           limits=1, relimits=1,
                           pdefault=save(x="mag", y="emag")
                          );
       obj_flux  = sys_new( stars, galaxies,
                           xtitle="Flux", ytitle="Flux Error",
                           limits=1, relimits=1,
                           pdefault=save(x="flux", y="eflux")
                           );                 
   // Okay now we can put in a window object:
      w_mf = win_new( obj_mag , obj_flux, fma=1, d=0.1, file="mag_flux.eps");
   // And plot it with the data in input:
      w_mf, go , data=data1;
   // I like this graph, let us save it:
      w_mf, go , data=data1, save=1
     
   // If you have an other set of data just change "data="   parameter.
   
   // We can go further, Let say you have 2 samples of data and you
   // want to plot them in 2 windows.
   // Let us first create a new sample:
        data2 = save( "galaxies", save("mag", random(20), "emag", random(20),
                                     "flux", random(20), "eflux", random(20)
                                     ),
                    "stars"   , save("mag", random(30), "emag", random(30),
                                     "flux", random(30), "eflux", random(30)
                                     )                 
                    );
    // And put the 2 samples in one object:
       AllData = save(sample1=data1, sample2=data2);
   // Now we can create a master object with 2 windows
   //  (The version parameter is use when saving the plots):
       M = master_new(
                      w_mf(_, subdata="sample1",version="_s1"),
                      w_mf(_, subdata="sample2",version="_s2")
                      );
   // Let us plot the 2 windows with AllData:
       M, go, data=AllData;
   // This would have been equivalent to do:
     window, 1; w_mf, go, data=AllData(sample1);
     window, 2; w_mf, go, data=AllDate(sample2);
  // Let us save the 2 plots (using wdefault, the default parameters for window):
       M, go, data=AllData, wdefault=save(save=1);
  // An other possibility woul have been to do: w_mf, set, save=1;

  // A nice thing is that when one set the vars as string to refer to
  // a data member this can be a string with a yorick expression
  // The var inside the expression will refer to the var inside the data,
  // If the var start with a $ it will refer to external variable,  example:
     galaxies, set, x="mag+12"
   // or
     offset = 12;
     galaxies, set, x="mag+$offset", y="$abs(emag)+0.2";
     M, go, data=AllData
     offset = 3;
     M, go, data=AllData
   //The evaluation of a string implied to create a temp .i file
     
   // Also  DATA can be: oxy object, structure -OR- h_table   
   // See  help, filter_new   for how to use data filters
 


Fri Mar 04, 2011 12:08 pm
Profile
Yorick Guru

Joined: Sat Jan 22, 2005 2:44 pm
Posts: 86
Location: Pasadena, CA
Post Re: oxy and functions
Sylvain, thank you for posting this. Very interesting. I played with your examples and
found a few typos, missing defaults, and a functions keyword problem. This will become
useful.
(right is new)
Code:
diff oplot*
1422c1422
<   save, pdefault, [], _plot_get_thing(w, "pdefault");
---
>   save, pdefault, [], _plot_get_thing(s, "pdefault");
1426c1426
<   save, sdefault, [], _plot_get_thing(w, "sdefault");   
---
>   save, sdefault, [], _plot_get_thing(s, "sdefault");   
2012,2014c2012,2014
< pltitle_orient= [0,1];
< pltitle_pos= [2,2];
< pltitle_switch= [0,0];
---
>
2535c2535,2536
<                                            "width","color","fill","ecolor"],
---
>                                            "width","color","fill","hide","ecolor",
>                                            "ewidth"],
2659,2661c2660
<   plp,p.y,p.x,dx=p.dx,xlo=p.xlo,xhi=p.xhi,dy=p.dy,ylo=p.ylo,yhi=p.yhi,\
<     size=p.size,symbol=p.symbol,ticks=p.ticks,legend=p.legend,type=p.type,\
<     width=p.width,color=(p.fill&&p.ecolor?_(p.color,p.ecolor):p.color),fill=p.fill;
---
>   plp,p.y,p.x,dx=p.dx,xlo=p.xlo,xhi=p.xhi,dy=p.dy,ylo=p.ylo,yhi=p.yhi,size=p.size,symbol=p.symbol,ticks=p.ticks,legend=p.legend,type=p.type,width=p.width,color=p.color,fill=p.fill,hide=p.hide,ecolor=p.ecolor,ewidth=p.ewidth;
2666,2669c2665
<   plg,p.y,p.x,legend=p.legend,hide=p.hide,type=p.type,width=p.width,\
<     color=p.color,closed=p.closed,smooth=p.smooth,marks=p.marks,\
<     marker=p.marker,mspace=p.mspace,mphase=p.mphase,rays=p.rays,\
<     arrowl=p.arrowl,arroww=p.arroww,rspace=p.rspace,rphase=p.rphase,n=p.n;


Sat Mar 05, 2011 8:15 pm
Profile YIM
Yorick Guru

Joined: Thu May 10, 2007 12:07 pm
Posts: 62
Post Re: oxy and functions
Thanks,

I forget I had a different version of plp. I changed the file: http://www.pinpinatla.com/Info/oplot.i
I will try at some point to make a clean version, if anyone have a suggestion, he is welcome.

Sylvain.


Sun Mar 06, 2011 5:20 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.