source: sasview/src/sans/dataloader/readers/cansas_constants.py @ ac5b69d

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ac5b69d was ac5b69d, checked in by Jeff Krzywon <jeffery.krzywon@…>, 10 years ago

Ticket #249 fix: Saving and loading projects and analysis is now working.

  • Property mode set to 100644
File size: 38.0 KB
Line 
1"""
2Information relating to the CanSAS data format. These constants are used in
3the cansas_reader.py file to read in any version of the cansas format.
4"""
5class CansasConstants:
6    """
7    The base class to define where all of the data is to be saved by
8    cansas_reader.py.
9    """
10   
11    names = ''
12    format = ''
13   
14   
15    def __init__(self):
16        self.names = self.CANSAS_NS
17        self.format = self.CANSAS_FORMAT
18   
19   
20    def iterate_namespace(self, namespace):
21        """
22        Method to iterate through a cansas constants tree based on a list of
23        names
24       
25        :param namespace: A list of names that match the tree structure of
26            cansas_constants
27        """
28        # The current level to look through in cansas_constants.
29        return_me = CurrentLevel()
30        return_me.current_level = self.CANSAS_FORMAT.get("SASentry")
31        # Defaults for variable and datatype
32        return_me.ns_variable = "{0}.meta_data[\"{2}\"] = \"{1}\""
33        return_me.ns_datatype = "content"
34        return_me.ns_optional = True
35        for name in namespace:
36            try:
37                if name != "SASentry":
38                    return_me.current_level = \
39                            return_me.current_level.get("children").get(name, "")
40                    if return_me.current_level == "":
41                        return_me.current_level = \
42                                return_me.current_level.get("<any>", "")
43                    cl_variable = return_me.current_level.get("variable", "")
44                    cl_datatype = return_me.current_level.get("storeas", "")
45                    cl_units_optional = \
46                                return_me.current_level.get("units_required", "")
47                    # Where are how to store the variable for the given namespace
48                    # CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit
49                    return_me.ns_variable = cl_variable if cl_variable != "" else \
50                                        return_me.ns_variable
51                    return_me.ns_datatype = cl_datatype if cl_datatype != "" else \
52                                        return_me.ns_datatype
53                    return_me.ns_optional = cl_units_optional if \
54                                        cl_units_optional != return_me.ns_optional \
55                                        else return_me.ns_optional
56            except AttributeError:
57                return_me.ns_variable = "{0}.meta_data[\"{2}\"] = \"{1}\""
58                return_me.ns_datatype = "content"
59                return_me.ns_optional = True
60        return return_me   
61   
62   
63    """
64    CANSAS_NS holds the base namespace and the default schema file information
65    """
66    CANSAS_NS = {
67                 "1.0" : {
68                          "ns" : "cansas1d/1.0", 
69                          "schema" : "cansas1d_v1_0.xsd"
70                          },
71                 "1.1" : {
72                          "ns" : "urn:cansas1d:1.1", 
73                          "schema" : "cansas1d_v1_1.xsd"
74                          }
75                 }
76   
77   
78    """
79    The constants below hold information on where to store the CanSAS data when
80    loaded in using sasview
81    """
82    META_DATA = "{0}.meta_data[\"{2}\"] = \"{1}\""
83    ANY = {
84           "variable" : "{0}.meta_data[\"{2}\"] = \'{1}\'",
85           "storeas" : "content",
86           }
87    TITLE = {"variable" : "{0}.title = \"{1}\""}
88    SASNOTE = {"variable" : "{0}.notes.append(\'{1}\')"}
89    SASPROCESS_TERM = {
90                       "variable" : None,
91                       "attributes" : {
92                                       "unit" : {"variable" : None},
93                                       "name" : {"variable" : None}
94                                       }
95                       }
96    SASPROCESS_SASPROCESSNOTE = {
97                                 "variable" : None,
98                                 "children" : {"<any>" : ANY}
99                                 }
100    SASPROCESS = {
101                  "variable" : None,
102                  "children" : {
103                                "name" : {"variable" : "{0}.name = \'{1}\'"},
104                               "date" : {"variable" : "{0}.date = \'{1}\'"},
105                               "description" : {"variable" : \
106                                                "{0}.description = \'{1}\'"},
107                               "term" : SASPROCESS_TERM,
108                               "SASprocessnote" : SASPROCESS_SASPROCESSNOTE,
109                               "<any>" : ANY
110                               },
111                 }
112    RUN = {
113           "variable" : "{0}.run.append(\"{1}\")",
114           "attributes" : {"name" : {"variable" : \
115                                     "{0}.run_name[node_value] = \"{1}\""}}
116           }
117    SASDATA_IDATA_Q = {
118                       "variable" : "{0}.x = numpy.append({0}.x, {1})",
119                       "unit" : "x_unit",
120                       "attributes" : {
121                                       "unit" : {
122                                                 "variable" : \
123                                                    "{0}._xunit = \"{1}\"",
124                                                    "storeas" : "content"
125                                                    }
126                                       }
127                       }
128    SASDATA_IDATA_I = {
129                       "variable" : "{0}.y = numpy.append({0}.y, {1})",
130                       "unit" : "y_unit",
131                       "attributes" : {
132                                       "unit" : {
133                                                 "variable" : \
134                                                    "{0}._yunit = \"{1}\"",
135                                                    "storeas" : "content"
136                                                }
137                                       }
138                       }
139    SASDATA_IDATA_IDEV = {
140                          "variable" : \
141                          "{0}.dy = numpy.append({0}.dy, {1})",
142                          "unit" : "y_unit",
143                          "attributes" : {
144                                          "unit" : {
145                                                    "variable" : META_DATA,
146                                                    "storeas" : "content"
147                                                    }
148                                          },
149                          }
150    SASDATA_IDATA_QDEV = {
151                          "variable" : \
152                          "{0}.dx = numpy.append({0}.dx, {1})",
153                          "unit" : "x_unit",
154                          "attributes" : {
155                                          "unit" : {
156                                                    "variable" : META_DATA,
157                                                    "storeas" : "content"
158                                                    }
159                                          },
160                          }
161    SASDATA_IDATA_DQL = {
162                         "variable" : \
163                         "{0}.dxl = numpy.append({0}.dxl, {1})",
164                         "unit" : "x_unit",
165                         "attributes" : {
166                                         "unit" : {
167                                                   "variable" : META_DATA,
168                                                "storeas" : "content"
169                                                }
170                                         },
171                         }
172    SASDATA_IDATA_DQW = {
173                         "variable" : \
174                         "{0}.dxw = numpy.append({0}.dxw, {1})",
175                         "unit" : "x_unit",
176                         "attributes" : {
177                                         "unit" : {
178                                                   "variable" : META_DATA,
179                                                   "storeas" : "content"
180                                                   }
181                                         },
182                         }
183    SASDATA_IDATA_QMEAN = {
184                           "storeas" : "content",
185                           "unit" : "x_unit",
186                           "variable" : META_DATA,
187                           "attributes" : {"unit" : {"variable" : META_DATA}},
188                           }
189    SASDATA_IDATA_SHADOWFACTOR = {
190                                  "variable" : META_DATA,
191                                  "storeas" : "content",
192                                  }
193    SASDATA_IDATA = {
194                     "storeas" : "float",
195                     "units_optional" : False,
196                     "variable" : None,
197                     "attributes" : {
198                                     "name" : {
199                                               "variable" : META_DATA,
200                                               "storeas" : "content",
201                                               },
202                                     "timestamp" : {
203                                                    "variable" : META_DATA,
204                                                    "storeas" : "timestamp",
205                                                    }
206                                     },
207                     "children" : {
208                                   "Q" : SASDATA_IDATA_Q,
209                                   "I" : SASDATA_IDATA_I,
210                                   "Idev" : SASDATA_IDATA_IDEV,
211                                   "Qdev" : SASDATA_IDATA_QDEV,
212                                   "dQw" : SASDATA_IDATA_DQW,
213                                   "dQl" : SASDATA_IDATA_DQL,
214                                   "Qmean" : SASDATA_IDATA_QMEAN,
215                                   "Shadowfactor" : SASDATA_IDATA_SHADOWFACTOR,
216                                   "<any>" : ANY
217                                   }
218                   }
219    SASDATA = {
220               "attributes" : {"name" : {"variable" : META_DATA,}},
221               "variable" : None,
222               "children" : {
223                             "Idata" : SASDATA_IDATA,
224                             "<any>" : ANY
225                             }
226               }
227    SASTRANSSPEC_TDATA_LAMDBA = {
228                                 "variable" : "{0}.wavelength.append({1})",
229                                 "unit" : "wavelength_unit",
230                                 "attributes" : {
231                                                 "unit" : {
232                                                            "variable" : "{0}.wavelength_unit = \"{1}\"",
233                                                            "storeas" : "content"
234                                                            }
235                                                 }
236                                 }
237    SASTRANSSPEC_TDATA_T = {
238                            "variable" : "{0}.transmission.append({1})",
239                            "unit" : "transmission_unit",
240                            "attributes" : {
241                                            "unit" : {
242                                                      "variable" : "{0}.transmission_unit = \"{1}\"",
243                                                      "storeas" : "content"
244                                                      }
245                                            }
246                            }
247    SASTRANSSPEC_TDATA_TDEV = {
248                               "variable" : \
249                                    "{0}.transmission_deviation.append({1})",
250                               "unit" : "transmission_deviation_unit",
251                                "attributes" : {
252                                                "unit" : {
253                                                          "variable" : "{0}.transmission_deviation_unit = \"{1}\"",
254                                                          "storeas" : "content"
255                                                          }
256                                                }
257                               }
258    SASTRANSSPEC_TDATA = {
259                          "storeas" : "float",
260                          "variable" : None,
261                          "children" : {
262                                        "Lambda" : SASTRANSSPEC_TDATA_LAMDBA,
263                                        "T" : SASTRANSSPEC_TDATA_T,
264                                        "Tdev" : SASTRANSSPEC_TDATA_TDEV,
265                                        "<any>" : ANY,
266                                        }
267                          }
268    SASTRANSSPEC = {
269                    "variable" : None,
270                    "children" : {
271                                  "Tdata" : SASTRANSSPEC_TDATA,
272                                  "<any>" : ANY,
273                                  },
274                    "attributes" : {"name" : {"variable" : \
275                                              "{0}.name = \"{1}\""},
276                                    "timestamp" : {"variable" : \
277                                                   "{0}.timestamp = \"{1}\""},
278                                    }
279                    }
280    SASSAMPLE_THICK = {
281                       "variable" : "{0}.sample.thickness = {1}",
282                       "unit" : "sample.thickness_unit",
283                       "storeas" : "float",
284                       "attributes" : {
285                                       "units" : {
286                                                  "variable" : "{0}.sample.thickness_unit = \"{1}\"",
287                                                  "storeas" : "content"
288                                                  }
289                                       },
290                       }
291    SASSAMPLE_TRANS = {
292                       "variable" : "{0}.sample.transmission = {1}",
293                       "storeas" : "float",
294                       }
295    SASSAMPLE_TEMP = {
296                      "variable" : "{0}.sample.temperature = {1}",
297                      "unit" : "sample.temperature_unit",
298                      "storeas" : "float",
299                      "attributes" : {
300                                      "units" : {
301                                                 "variable" : "{0}.sample.temperature_unit = \"{1}\"",
302                                                 "storeas" : "content"
303                                                 }
304                                      },
305                      }
306    SASSAMPLE_POS_ATTR = {
307                          "units" : {
308                                     "variable" : \
309                                        "{0}.sample.position_unit = \"{1}\"",
310                                     "storeas" : "content"
311                                     }
312                          }
313    SASSAMPLE_POS_X = {
314                       "variable" : "{0}.sample.position.x = {1}",
315                       "unit" : "sample.position_unit",
316                       "storeas" : "float",
317                       "attributes" : SASSAMPLE_POS_ATTR
318                       }
319    SASSAMPLE_POS_Y = {
320                       "variable" : "{0}.sample.position.y = {1}",
321                       "unit" : "sample.position_unit",
322                       "storeas" : "float",
323                       "attributes" : SASSAMPLE_POS_ATTR
324                       }
325    SASSAMPLE_POS_Z = {
326                       "variable" : "{0}.sample.position.z = {1}",
327                       "unit" : "sample.position_unit",
328                       "storeas" : "float",
329                       "attributes" : SASSAMPLE_POS_ATTR
330                       }
331    SASSAMPLE_POS = {
332                     "children" : {
333                                   "variable" : None,
334                                   "x" : SASSAMPLE_POS_X,
335                                   "y" : SASSAMPLE_POS_Y,
336                                   "z" : SASSAMPLE_POS_Z,
337                                   },
338                     }
339    SASSAMPLE_ORIENT_ATTR = {
340                             "units" : {
341                                        "variable" : "{0}.sample.orientation_unit = \"{1}\"",
342                                        "storeas" : "content"
343                                        }
344                             }
345    SASSAMPLE_ORIENT_ROLL = {
346                             "variable" : "{0}.sample.orientation.x = {1}",
347                             "unit" : "sample.orientation_unit",
348                             "storeas" : "float",
349                             "attributes" : SASSAMPLE_ORIENT_ATTR
350                             }
351    SASSAMPLE_ORIENT_PITCH = {
352                             "variable" : "{0}.sample.orientation.y = {1}",
353                             "unit" : "sample.orientation_unit",
354                             "storeas" : "float",
355                             "attributes" : SASSAMPLE_ORIENT_ATTR
356                             }
357    SASSAMPLE_ORIENT_YAW = {
358                             "variable" : "{0}.sample.orientation.z = {1}",
359                             "unit" : "sample.orientation_unit",
360                             "storeas" : "float",
361                             "attributes" : SASSAMPLE_ORIENT_ATTR
362                             }
363    SASSAMPLE_ORIENT = {
364                        "variable" : None,
365                        "children" : {
366                                      "roll" : SASSAMPLE_ORIENT_ROLL,
367                                      "pitch" : SASSAMPLE_ORIENT_PITCH,
368                                      "yaw" : SASSAMPLE_ORIENT_YAW,
369                                      },
370                        }
371    SASSAMPLE = {
372                 "attributes" : {"name" : {\
373                                    "variable" : "{0}.sample.name = \"{1}\""},},
374                 "variable" : None,
375                 "children" : {
376                               "ID" : {"variable" : "{0}.sample.ID = \"{1}\""},
377                               "thickness" : SASSAMPLE_THICK,
378                               "transmission" : SASSAMPLE_TRANS, 
379                               "temperature" : SASSAMPLE_TEMP, 
380                               "position" : SASSAMPLE_POS,
381                               "orientation" : SASSAMPLE_ORIENT,
382                               "details" : {"variable" : \
383                                        "{0}.sample.details.append(\"{1}\")"},
384                               "<any>" : ANY
385                               },
386                 }
387    SASINSTR_SRC_BEAMSIZE_ATTR = {
388                                  "unit" : \
389                                    "{0}.source.beam_size_unit = \"{1}\"",
390                                  "storeas" : "content"
391                                  }
392    SASINSTR_SRC_BEAMSIZE_X = {
393                               "variable" : "{0}.source.beam_size.x = {1}",
394                               "unit" : "source.beam_size_unit",
395                               "storeas" : "float",
396                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR
397                               }
398    SASINSTR_SRC_BEAMSIZE_Y = {
399                               "variable" : "{0}.source.beam_size.y = {1}",
400                               "unit" : "source.beam_size_unit",
401                               "storeas" : "float",
402                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR
403                               }
404    SASINSTR_SRC_BEAMSIZE_Z = {
405                               "variable" : "{0}.source.beam_size.z = {1}",
406                               "unit" : "source.beam_size_unit",
407                               "storeas" : "float",
408                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR
409                               }
410    SASINSTR_SRC_BEAMSIZE = {
411                             "attributes" : {"name" : {"variable" : \
412                                        "{0}.source.beam_size_name = \"{1}\""}},
413                             "variable" : None,
414                             "children" : {
415                                           "x" : SASINSTR_SRC_BEAMSIZE_X,
416                                           "y" : SASINSTR_SRC_BEAMSIZE_Y,
417                                           "z" : SASINSTR_SRC_BEAMSIZE_Z,
418                                           }
419                             }
420    SASINSTR_SRC_WL = {
421                       "variable" : "{0}.source.wavelength = {1}",
422                       "unit" : "source.wavelength_unit",
423                       "storeas" : "float",
424                       "attributes" : {
425                                       "unit" : {
426                                                 "variable" : "{0}.source.wavelength_unit = \"{1}\"",
427                                                 "storeas" : "content"
428                                                 },
429                                       }
430                       }
431    SASINSTR_SRC_WL_MIN = {
432                           "variable" : "{0}.source.wavelength_min = {1}",
433                           "unit" : "source.wavelength_min_unit",
434                           "storeas" : "float",
435                           "attributes" : {
436                                           "unit" : {
437                                                     "variable" : "{0}.source.wavelength_min_unit = \"{1}\"", 
438                                                     "storeas" : "content"
439                                                     },
440                                           }
441                           }
442    SASINSTR_SRC_WL_MAX = {
443                           "variable" : "{0}.source.wavelength_max = {1}",
444                           "unit" : "source.wavelength_max_unit",
445                           "storeas" : "float",
446                           "attributes" : {
447                                           "unit" : {
448                                                     "variable" : "{0}.source.wavelength_max_unit = \"{1}\"", 
449                                                     "storeas" : "content"
450                                                     },
451                                           }
452                           }
453    SASINSTR_SRC_WL_SPR = {
454                           "variable" : "{0}.source.wavelength_spread = {1}",
455                           "unit" : "source.wavelength_spread_unit",
456                           "storeas" : "float",
457                           "attributes" : {
458                                           "unit" : {
459                                                     "variable" : "{0}.source.wavelength_spread_unit = \"{1}\"", 
460                                                     "storeas" : "content"
461                                                     },
462                                           }
463                           }
464    SASINSTR_SRC = {
465                    "attributes" : {"name" : {"variable" : \
466                                              "{0}.source.name = \"{1}\""}},
467                    "variable" : None,
468                    "children" : {
469                                  "radiation" : {"variable" : \
470                                            "{0}.source.radiation = \"{1}\""},
471                                  "beam_size" : SASINSTR_SRC_BEAMSIZE,
472                                  "beam_shape" : {"variable" : \
473                                            "{0}.source.beam_shape = \"{1}\""},
474                                  "wavelength" : SASINSTR_SRC_WL,
475                                  "wavelength_min" : SASINSTR_SRC_WL_MIN,
476                                  "wavelength_max" : SASINSTR_SRC_WL_MAX,
477                                  "wavelength_spread" : SASINSTR_SRC_WL_SPR,
478                                  },
479                    }
480    SASINSTR_COLL_APER_ATTR = {
481                               "unit" : {
482                                         "variable" : "{0}.size_unit = \"{1}\"",
483                                         "storeas" : "content"
484                                         },                                   
485                               }
486    SASINSTR_COLL_APER_X = {
487                            "variable" : "{0}.size.x = {1}",
488                            "unit" : "size_unit",
489                            "storeas" : "float",
490                            "attributes" : SASINSTR_COLL_APER_ATTR
491                            }
492    SASINSTR_COLL_APER_Y = {
493                            "variable" : "{0}.size.y = {1}",
494                            "unit" : "size_unit",
495                            "storeas" : "float",
496                            "attributes" : SASINSTR_COLL_APER_ATTR
497                            }
498    SASINSTR_COLL_APER_Z = {
499                            "variable" : "{0}.size.z = {1}",
500                            "unit" : "size_unit",
501                            "storeas" : "float",
502                            "attributes" : SASINSTR_COLL_APER_ATTR
503                            }
504    SASINSTR_COLL_APER_SIZE = {
505                               "attributes" : {"unit" : {"variable" : \
506                                                    "{0}.size_unit = \"{1}\""}},
507                               "children" : {
508                                             "storeas" : "float",
509                                            "x" : SASINSTR_COLL_APER_X,
510                                            "y" : SASINSTR_COLL_APER_Y,
511                                            "z" : SASINSTR_COLL_APER_Z,
512                                            }
513                               }
514    SASINSTR_COLL_APER_DIST = {
515                               "storeas" : "float",
516                               "attributes" : {
517                                               "storeas" : "content",
518                                               "unit" : {"variable" : \
519                                                "{0}.distance_unit = \"{1}\""}},
520                               "variable" : "{0}.distance = {1}",
521                               "unit" : "distance_unit",
522                               }
523    SASINSTR_COLL_APER = {
524                          "variable" : None,
525                          "attributes" : {
526                                          "name" : {"variable" : \
527                                                    "{0}.name = \"{1}\""},
528                                          "type" : {"variable" : \
529                                                    "{0}.type = \"{1}\""},
530                                          },
531                          "children" : {
532                                        "size" : SASINSTR_COLL_APER_SIZE,
533                                        "distance" : SASINSTR_COLL_APER_DIST
534                                        }
535                          }
536    SASINSTR_COLL = {
537                     "attributes" : {"name" : {"variable" : \
538                                               "{0}.name = \"{1}\""}},
539                     "variable" : None,
540                     "children" : {
541                                   "length" : {
542                                            "variable" : "{0}.length = {1}",
543                                            "unit" : "length_unit",
544                                            "storeas" : "float",
545                                            "attributes" : {
546                                                            "storeas" : \
547                                                                "content",
548                                                            "unit" : {"variable" : "{0}.length_unit = \"{1}\""}
549                                                            },
550                                            },
551                                   "aperture" : SASINSTR_COLL_APER,
552                                   },
553                     }
554    SASINSTR_DET_SDD = {
555                        "variable" : "{0}.distance = {1}",
556                        "unit" : "distance_unit",
557                        "attributes" : {
558                                        "unit" : {
559                                                  "variable" : \
560                                                  "{0}.distance_unit = \"{1}\"",
561                                                  "storeas" : "content"
562                                                  }
563                                        },
564                        }
565    SASINSTR_DET_OFF_ATTR = {
566                            "unit" : {
567                                      "variable" : "{0}.offset_unit = \"{1}\"",
568                                      "storeas" : "content"
569                                      },
570                            }
571    SASINSTR_DET_OFF_X = {
572                         "variable" : "{0}.offset.x = {1}",
573                         "unit" : "offset_unit",
574                         "attributes" : SASINSTR_DET_OFF_ATTR
575                         }
576    SASINSTR_DET_OFF_Y = {
577                         "variable" : "{0}.offset.y = {1}",
578                         "unit" : "offset_unit",
579                         "attributes" : SASINSTR_DET_OFF_ATTR
580                         }
581    SASINSTR_DET_OFF_Z = {
582                         "variable" : "{0}.offset.z = {1}",
583                         "unit" : "offset_unit",
584                         "attributes" : SASINSTR_DET_OFF_ATTR
585                         }
586    SASINSTR_DET_OFF = {
587                        "variable" : None,
588                        "children" : {
589                                      "x" : SASINSTR_DET_OFF_X,
590                                      "y" : SASINSTR_DET_OFF_Y,
591                                      "z" : SASINSTR_DET_OFF_Z,
592                                      }
593                        }
594    SASINSTR_DET_OR_ATTR = {
595                            "unit" : "{0}.orientation_unit = \"{1}\"",
596                            "storeas" : "content"
597                            }
598    SASINSTR_DET_OR_ROLL = {
599                            "variable" : "{0}.orientation.x = {1}",
600                            "unit" : "orientation_unit",
601                            "attributes" : SASINSTR_DET_OR_ATTR
602                            }
603    SASINSTR_DET_OR_PITCH = {
604                             "variable" : "{0}.orientation.y = {1}",
605                             "unit" : "orientation_unit",
606                             "attributes" : SASINSTR_DET_OR_ATTR
607                             }
608    SASINSTR_DET_OR_YAW = {
609                           "variable" : "{0}.orientation.z = {1}",
610                           "unit" : "orientation_unit",
611                           "attributes" : SASINSTR_DET_OR_ATTR
612                           }
613    SASINSTR_DET_OR = {
614                       "variable" : None,
615                       "children" : {
616                                     "roll" : SASINSTR_DET_OR_ROLL,
617                                     "pitch" : SASINSTR_DET_OR_PITCH,
618                                     "yaw" : SASINSTR_DET_OR_YAW,
619                                     }
620                       }
621    SASINSTR_DET_BC_X = {
622                         "variable" : "{0}.beam_center.x = {1}",
623                         "unit" : "beam_center_unit",
624                         "attributes" : {
625                                         "unit" : \
626                                            "{0}.beam_center_unit = \"{1}\"",
627                                         "storeas" : "content"
628                                         }
629                         }
630    SASINSTR_DET_BC_Y = {
631                         "variable" : "{0}.beam_center.y = {1}",
632                         "unit" : "beam_center_unit",
633                         "attributes" : {
634                                         "unit" : \
635                                            "{0}.beam_center_unit = \"{1}\"",
636                                         "storeas" : "content"
637                                         }
638                         }
639    SASINSTR_DET_BC_Z = {
640                         "variable" : "{0}.beam_center.z = {1}",
641                         "unit" : "beam_center_unit",
642                         "attributes" : {
643                                         "unit" : \
644                                            "{0}.beam_center_unit = \"{1}\"",
645                                         "storeas" : "content"
646                                         }
647                         }
648    SASINSTR_DET_BC = {
649                       "variable" : None,
650                       "children" : {
651                                    "x" : SASINSTR_DET_BC_X,
652                                    "y" : SASINSTR_DET_BC_Y,
653                                    "z" : SASINSTR_DET_BC_Z,
654                                    }
655                      }
656    SASINSTR_DET_PIXEL_X = {
657                        "variable" : "{0}.pixel_size.x = {1}",
658                        "unit" : "pixel_size_unit",
659                        "attributes" : {
660                                        "unit" : \
661                                            "{0}.pixel_size_unit = \"{1}\"",
662                                        "storeas" : "content"
663                                        }
664                        }
665    SASINSTR_DET_PIXEL_Y = {
666                        "variable" : "{0}.pixel_size.y = {1}",
667                        "unit" : "pixel_size_unit",
668                        "attributes" : {
669                                        "unit" : \
670                                            "{0}.pixel_size_unit = \"{1}\"",
671                                        "storeas" : "content"
672                                        }
673                        }
674    SASINSTR_DET_PIXEL_Z = {
675                        "variable" : "{0}.pixel_size.z = {1}",
676                        "unit" : "pixel_size_unit",
677                        "attributes" : {
678                                        "unit" : \
679                                            "{0}.pixel_size_unit = \"{1}\"",
680                                        "storeas" : "content"
681                                        }
682                        }
683    SASINSTR_DET_PIXEL = {
684                      "variable" : None,
685                      "children" : {
686                                    "x" : SASINSTR_DET_PIXEL_X,
687                                    "y" : SASINSTR_DET_PIXEL_Y,
688                                    "z" : SASINSTR_DET_PIXEL_Z,
689                                    }
690                      }
691    SASINSTR_DET_SLIT = {
692                         "variable" : "{0}.slit_length = {1}",
693                         "unit" : "slit_length_unit",
694                         "attributes" : {
695                                         "unit" : {
696                                                   "variable" : "{0}.slit_length_unit = \"{1}\"",
697                                                   "storeas" : "content"
698                                                   }
699                                         }
700                         }
701    SASINSTR_DET = {
702                    "storeas" : "float",
703                    "variable" : None,
704                    "attributes" : {
705                                    "name" : {
706                                              "storeas" : "content",
707                                              "variable" : "{0}.name = \"{1}\"",
708                                              }
709                                    },
710                    "children" : {
711                                  "name" : {
712                                            "storeas" : "content",
713                                            "variable" : "{0}.name = \"{1}\"",
714                                            },
715                                  "SDD" : SASINSTR_DET_SDD,
716                                  "offset" : SASINSTR_DET_OFF,
717                                  "orientation" : SASINSTR_DET_OR,
718                                  "beam_center" : SASINSTR_DET_BC,
719                                  "pixel_size" : SASINSTR_DET_PIXEL,
720                                  "slit_length" : SASINSTR_DET_SLIT,
721                                  }
722                    }
723    SASINSTR = {
724                "variable" : None,
725                "children" : {
726                              "variable" : None,
727                              "name" : {"variable" : \
728                                            "{0}.instrument = \"{1}\""},
729                              "SASsource" : SASINSTR_SRC,
730                              "SAScollimation" : SASINSTR_COLL,
731                              "SASdetector" : SASINSTR_DET,
732                              },
733                }
734    CANSAS_FORMAT = {
735                     "SASentry" : {
736                                   "units_optional" : True,
737                                   "variable" : None,
738                                   "storeas" : "content",
739                                   "attributes" : {"name" : {"variable" : \
740                                        "{0}.run_name[node_value] = \"{1}\""}},
741                                   "children" : {
742                                                 "Title" : TITLE,
743                                                 "Run" : RUN,
744                                                 "SASdata" : SASDATA,
745                                                 "SAStransmission_spectrum" : \
746                                                    SASTRANSSPEC,
747                                                 "SASsample" : SASSAMPLE,
748                                                 "SASinstrument" : SASINSTR,
749                                                 "SASprocess" : SASPROCESS,
750                                                 "SASnote" : SASNOTE,
751                                                 "<any>" : ANY,
752                                                 }
753                                   }
754                     }
755   
756class CurrentLevel:
757    """
758    A helper class to hold information on where you are in the constants tree
759    """
760     
761    current_level = ''
762    ns_variable = ''
763    ns_datatype = ''
764    ns_optional = True
765     
766    def __init__(self):
767        self.current_level = {}
768        self.ns_variable = ''
769        self.ns_datatype = "content"
770        self.ns_optional = True
Note: See TracBrowser for help on using the repository browser.