Skip to content

How_do_I_create_an_N Dimensional_domain?

Gijs Molenaar edited this page Feb 13, 2014 · 3 revisions

The new way

Use meq.gen_domain() and meq.gen_cells() (the "gen" stands for generalized). Example from this workshop script.

  • domain = meq.gen_domain(time=[0,7200],l=[-.05,.05],m=[-.05,.05]);  cells = meq.gen_cells(domain,num_time=100,num_l=100,num_m=100);```

The old way, for historical amusement

(This whole thing needs to be pythonized!)

So how does one go about defining a domain greater than 2? In glish if I do something like domain := meq.domain(-1,1,-1,1,-1,1) everything falls over.

Does one first have to define a non-standard axis_map record. (I see that Ronald's PatchComposer c++ node adds on L,M,U & V axes, but obviously I want to do all the n-dim domain stuff in a script.)

The meq.domain() and meq.cells() functions in Glish (and Python, for that matter) only support freq/time domains at the moment. However, both a domain and a cells objects in Python (or Glish) is a record, so the quickest way to do it is start with a 2D domain, and add fields to it so as to add dimensions.

  1. First, you have to define the extra axes. forest_state.axis_map defines the domain "names". If you are not using any of Ronald's nodes, then this will contain time and freq only. You can use mqs.meq('Get.Forest.State',[=],wait_reply=T) to get the current state; you'll get back the forest state record including axis_map. Now modify this map by inserting more elements into it, each element is a little record of the form [id='l'], [id='m'], etc -- then give it back to the kernel using mqs.meq('Set.Forest.State',[axis_map=your_modified_map]).

  2. Now, a 2D domain is a record of the form, e.g. [freq=[0 1] , time=[0 1] ]. Assuming you've defined extra axes l/m, you can just say:

  dom  := meq.domain(0,1,0,1);
  dom.l := [0.,1.]
  dom.m := [0.,1.]

BTW, don't try to build up a domain record from scratch -- it needs some magic to be recognized as a Domain object on the C++ side. You must call meq.domain() to make a 2D domain first, and then extend it as above.

  1. Cells is a bit more elaborate but the same principle holds. Create a 2D cells, then add extra fields. Easiest thing is to copy them from another axis (otherwise you have to worry about getting cell sizes and segments right). E.g.:
 c := meq.cells(dom,8,4);
 c.grid.l := c.grid.m := c.grid.freq;
 c.cell_size.l := c.cell_size.m := c.cell_size.freq;
 c.segments.l := c.segments.m := c.segments.freq;

1a. As an alternative, you can dispence with axis names and use axis numbers instead, by referring to them simply as '2', '3', etc. ('0' and '1' being time/freq). This makes record access in Glish somewhat more clumsy, e.g.:

 dom['2'] := [0.,1.]

etc... but saves you the trouble of manipulating forest state.

Clone this wiki locally