source: sasview/src/sas/sascalc/dataloader/readers/cansas_constants.py @ dd5bf63

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 dd5bf63 was b699768, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Initial commit of the refactored SasCalc? module.

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