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

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 3241dd2 was 3241dd2, checked in by Jeff Krzywon <jeffery.krzywon@…>, 10 years ago

Fixed the issue as described in ticket 269: "Failure to assign model when using attached data file" and made the change for ticket 264: "Remove .TIF extension from Load Data file extension filter."

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