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

ESS_GUI
Last change on this file was 63d773c, checked in by Adam Washington <adam.washington@…>, 7 years ago

Add yacceptance

Needed to correspond to zacceptance for 2D sesans

  • Property mode set to 100644
File size: 20.2 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_datatype = "content"
30        return_me.ns_optional = True
31        for name in namespace:
32            try:
33                if name != "SASentry":
34                    return_me.current_level = \
35                        return_me.current_level.get("children").get(name, "")
36                    if return_me.current_level == "":
37                        return_me.current_level = \
38                                return_me.current_level.get("<any>", "")
39                    cl_datatype = return_me.current_level.get("storeas", "")
40                    cl_units_optional = \
41                             return_me.current_level.get("units_optional", "")
42                    # Where are how to store the variable for the given
43                    # namespace CANSAS_CONSTANTS tree is hierarchical, so
44                    # is no value, inherit
45                    return_me.ns_datatype = cl_datatype if cl_datatype != "" \
46                        else return_me.ns_datatype
47                    return_me.ns_optional = cl_units_optional if \
48                        cl_units_optional != return_me.ns_optional \
49                                        else return_me.ns_optional
50            except AttributeError:
51                return_me.ns_datatype = "content"
52                return_me.ns_optional = True
53        return return_me
54
55    def get_namespace_map(self):
56        """
57        Helper method to get the names namespace list
58        """
59        return self.names
60
61    # CANSAS_NS holds the base namespace and default schema file information
62    CANSAS_NS = {"1.0" : {"ns" : "cansas1d/1.0",
63                          "schema" : "cansas1d_v1_0.xsd"
64                         },
65                 "1.1" : {"ns" : "urn:cansas1d:1.1",
66                          "schema" : "cansas1d_v1_1.xsd"
67                         }
68                }
69
70    # The constants below hold information on where to store the CanSAS data
71    # when loaded in using sasview
72    ANY = {"storeas" : "content"}
73    TITLE = {}
74    SASNOTE = {}
75    SASPROCESS_TERM = {"attributes" : {"unit" : {}, "name" : {}}}
76    SASPROCESS_SASPROCESSNOTE = {"children" : {"<any>" : ANY}}
77    SASPROCESS = {"children" : {"name" : {},
78                                "date" : {},
79                                "description" : {},
80                                "term" : SASPROCESS_TERM,
81                                "SASprocessnote" : SASPROCESS_SASPROCESSNOTE,
82                                "<any>" : ANY
83                               },
84                 }
85    RUN = {"attributes" : {"name" :{}}}
86    SASDATA_IDATA_Q = {"units_optional" : False,
87                       "storeas" : "float",
88                        "unit" : "x_unit",
89                       "attributes" : {"unit" : {"storeas" : "content"}},
90                      }
91    SASDATA_IDATA_I = {"units_optional" : False,
92                       "storeas" : "float",
93                        "unit" : "y_unit",
94                       "attributes" : {"unit" : {"storeas" : "content"}},
95                      }
96    SASDATA_IDATA_IDEV = {"units_optional" : False,
97                          "storeas" : "float",
98                          "unit" : "y_unit",
99                          "attributes" : {"unit" : {"storeas" : "content"}},
100                         }
101    SASDATA_IDATA_QDEV = {"units_optional" : False,
102                          "storeas" : "float",
103                          "unit" : "x_unit",
104                          "attributes" : {"unit" : {"storeas" : "content"}},
105                         }
106    SASDATA_IDATA_DQL = {"units_optional" : False,
107                         "storeas" : "float",
108                         "unit" : "x_unit",
109                         "attributes" : {"unit" : {"storeas" : "content"}},
110                        }
111    SASDATA_IDATA_DQW = {"units_optional" : False,
112                         "storeas" : "float",
113                         "unit" : "x_unit",
114                         "attributes" : {"unit" : {"storeas" : "content"}},
115                        }
116    SASDATA_IDATA_QMEAN = {"unit" : "x_unit",
117                           "attributes" : {"unit" : {}},
118                          }
119    SASDATA_IDATA_SHADOWFACTOR = {}
120    SASDATA_IDATA = {"attributes" : {"name" : {},"timestamp" : {"storeas" : "timestamp"}},
121                     "children" : {"Q" : SASDATA_IDATA_Q,
122                                   "I" : SASDATA_IDATA_I,
123                                   "Idev" : SASDATA_IDATA_IDEV,
124                                   "Qdev" : SASDATA_IDATA_QDEV,
125                                   "dQw" : SASDATA_IDATA_DQW,
126                                   "dQl" : SASDATA_IDATA_DQL,
127                                   "Qmean" : SASDATA_IDATA_QMEAN,
128                                   "Shadowfactor" : SASDATA_IDATA_SHADOWFACTOR,
129                                   "<any>" : ANY
130                                  }
131                    }
132    SASDATA = {"attributes" : {"name" : {}},
133               "variable" : None,
134               "children" : {"Idata" : SASDATA_IDATA,
135                             "Sesans": {"storeas": "content"},
136                             "zacceptance": {"storeas": "float"},
137                             "yacceptance": {"storeas": "float"},
138                             "<any>" : ANY
139                            }
140              }
141    SASTRANSSPEC_TDATA_LAMDBA = {"storeas" : "float",
142                                 "unit" : "wavelength_unit",
143                                 "attributes" : {"unit" : {"storeas" : "content"}}
144                                }
145    SASTRANSSPEC_TDATA_T = {"storeas" : "float",
146                            "unit" : "transmission_unit",
147                            "attributes" : {"unit" : {"storeas" : "content"}}
148                           }
149    SASTRANSSPEC_TDATA_TDEV = {"storeas" : "float",
150                               "unit" : "transmission_deviation_unit",
151                               "attributes" : {"unit" :{"storeas" : "content"}}
152                              }
153    SASTRANSSPEC_TDATA = {"children" : {"Lambda" : SASTRANSSPEC_TDATA_LAMDBA,
154                                        "T" : SASTRANSSPEC_TDATA_T,
155                                        "Tdev" : SASTRANSSPEC_TDATA_TDEV,
156                                        "<any>" : ANY,
157                                       }
158                         }
159    SASTRANSSPEC = {"children" : {"Tdata" : SASTRANSSPEC_TDATA,
160                                  "<any>" : ANY,
161                                 },
162                    "attributes" : {"name" :{}, "timestamp" : {},}
163                   }
164    SASSAMPLE_THICK = {"unit" : "thickness_unit",
165                       "storeas" : "float",
166                       "attributes" : {"unit" :{}},
167                      }
168    SASSAMPLE_TRANS = {"storeas" : "float",}
169    SASSAMPLE_TEMP = {"unit" : "temperature_unit",
170                      "storeas" : "float",
171                      "attributes" :{"unit" :{}},
172                     }
173    SASSAMPLE_POS_ATTR = {"unit" : {}}
174    SASSAMPLE_POS_X = {"unit" : "position_unit",
175                       "storeas" : "float",
176                       "attributes" : SASSAMPLE_POS_ATTR
177                      }
178    SASSAMPLE_POS_Y = {"unit" : "position_unit",
179                       "storeas" : "float",
180                       "attributes" : SASSAMPLE_POS_ATTR
181                      }
182    SASSAMPLE_POS_Z = {"unit" : "position_unit",
183                       "storeas" : "float",
184                       "attributes" : SASSAMPLE_POS_ATTR
185                      }
186    SASSAMPLE_POS = {"children" : {"x" : SASSAMPLE_POS_X,
187                                   "y" : SASSAMPLE_POS_Y,
188                                   "z" : SASSAMPLE_POS_Z,
189                                  },
190                    }
191    SASSAMPLE_ORIENT_ATTR = {"unit" :{}}
192    SASSAMPLE_ORIENT_ROLL = {"unit" : "orientation_unit",
193                             "storeas" : "float",
194                             "attributes" : SASSAMPLE_ORIENT_ATTR
195                            }
196    SASSAMPLE_ORIENT_PITCH = {"unit" : "orientation_unit",
197                              "storeas" : "float",
198                              "attributes" : SASSAMPLE_ORIENT_ATTR
199                             }
200    SASSAMPLE_ORIENT_YAW = {"unit" : "orientation_unit",
201                            "storeas" : "float",
202                            "attributes" : SASSAMPLE_ORIENT_ATTR
203                           }
204    SASSAMPLE_ORIENT = {"children" : {"roll" : SASSAMPLE_ORIENT_ROLL,
205                                      "pitch" : SASSAMPLE_ORIENT_PITCH,
206                                      "yaw" : SASSAMPLE_ORIENT_YAW,
207                                     },
208                       }
209    SASSAMPLE = {"attributes" :
210                 {"name" : {},},
211                 "children" : {"ID" : {},
212                               "thickness" : SASSAMPLE_THICK,
213                               "transmission" : SASSAMPLE_TRANS,
214                               "temperature" : SASSAMPLE_TEMP,
215                               "position" : SASSAMPLE_POS,
216                               "orientation" : SASSAMPLE_ORIENT,
217                               "details" : {},
218                               "<any>" : ANY
219                              },
220                }
221    SASINSTR_SRC_BEAMSIZE_ATTR = {"unit" : ""}
222    SASINSTR_SRC_BEAMSIZE_X = {"unit" : "beam_size_unit",
223                               "storeas" : "float",
224                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR
225                              }
226    SASINSTR_SRC_BEAMSIZE_Y = {"unit" : "beam_size_unit",
227                               "storeas" : "float",
228                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR
229                              }
230    SASINSTR_SRC_BEAMSIZE_Z = {"unit" : "beam_size_unit",
231                               "storeas" : "float",
232                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR
233                              }
234    SASINSTR_SRC_BEAMSIZE = {"attributes" : {"name" : {}},
235                             "children" : {"x" : SASINSTR_SRC_BEAMSIZE_X,
236                                           "y" : SASINSTR_SRC_BEAMSIZE_Y,
237                                           "z" : SASINSTR_SRC_BEAMSIZE_Z,
238                                          }
239                            }
240    SASINSTR_SRC_WL = {"unit" : "wavelength_unit",
241                       "storeas" : "float",
242                       "attributes" : {"unit" :{},
243                       }
244                      }
245    SASINSTR_SRC_WL_MIN = {"unit" : "wavelength_min_unit",
246                           "storeas" : "float",
247                           "attributes" : {"unit" :{"storeas" : "content"},}
248                          }
249    SASINSTR_SRC_WL_MAX = {"unit" : "wavelength_max_unit",
250                           "storeas" : "float",
251                           "attributes" : {"unit" :{"storeas" : "content"},}
252                          }
253    SASINSTR_SRC_WL_SPR = {"unit" : "wavelength_spread_unit",
254                           "storeas" : "float",
255                           "attributes" : {"unit" : {"storeas" : "content"},}
256                          }
257    SASINSTR_SRC = {"attributes" : {"name" : {}},
258                    "children" : {"radiation" : {},
259                                  "beam_size" : SASINSTR_SRC_BEAMSIZE,
260                                  "beam_shape" : {},
261                                  "wavelength" : SASINSTR_SRC_WL,
262                                  "wavelength_min" : SASINSTR_SRC_WL_MIN,
263                                  "wavelength_max" : SASINSTR_SRC_WL_MAX,
264                                  "wavelength_spread" : SASINSTR_SRC_WL_SPR,
265                                 },
266                   }
267    SASINSTR_COLL_APER_ATTR = {"unit" : {}}
268    SASINSTR_COLL_APER_X = {"unit" : "size_unit",
269                            "storeas" : "float",
270                            "attributes" : SASINSTR_COLL_APER_ATTR
271                           }
272    SASINSTR_COLL_APER_Y = {"unit" : "size_unit",
273                            "storeas" : "float",
274                            "attributes" : SASINSTR_COLL_APER_ATTR
275                           }
276    SASINSTR_COLL_APER_Z = {"unit" : "size_unit",
277                            "storeas" : "float",
278                            "attributes" : SASINSTR_COLL_APER_ATTR
279                           }
280    SASINSTR_COLL_APER_SIZE = {"attributes" : {"unit" : {}},
281                               "children" : {"storeas" : "float",
282                                             "x" : SASINSTR_COLL_APER_X,
283                                             "y" : SASINSTR_COLL_APER_Y,
284                                             "z" : SASINSTR_COLL_APER_Z,
285                                            }
286                              }
287    SASINSTR_COLL_APER_DIST = {"storeas" : "float",
288                               "attributes" : {"unit" : {}},
289                               "unit" : "distance_unit",
290                              }
291    SASINSTR_COLL_APER = {"attributes" : {"name" : {}, "type" : {}, },
292                          "children" : {"size" : SASINSTR_COLL_APER_SIZE,
293                                        "distance" : SASINSTR_COLL_APER_DIST
294                                       }
295                         }
296    SASINSTR_COLL = {"attributes" : {"name" : {}},
297                     "children" :
298                         {"length" :
299                          {"unit" : "length_unit",
300                           "storeas" : "float",
301                           "attributes" : {"storeas" : "content", "unit" : {}},
302                          },
303                          "aperture" : SASINSTR_COLL_APER,
304                         },
305                    }
306    SASINSTR_DET_SDD = {"storeas" : "float",
307                        "unit" : "distance_unit",
308                        "attributes" : {"unit" :{}},
309                       }
310    SASINSTR_DET_OFF_ATTR = {"unit" : {"storeas" : "content" }}
311    SASINSTR_DET_OFF_X = {"storeas" : "float",
312                          "unit" : "offset_unit",
313                          "attributes" : SASINSTR_DET_OFF_ATTR
314                         }
315    SASINSTR_DET_OFF_Y = {"storeas" : "float",
316                          "unit" : "offset_unit",
317                          "attributes" : SASINSTR_DET_OFF_ATTR
318                         }
319    SASINSTR_DET_OFF_Z = {"storeas" : "float",
320                          "unit" : "offset_unit",
321                          "attributes" : SASINSTR_DET_OFF_ATTR
322                         }
323    SASINSTR_DET_OFF = {"children" : {"x" : SASINSTR_DET_OFF_X,
324                                      "y" : SASINSTR_DET_OFF_Y,
325                                      "z" : SASINSTR_DET_OFF_Z,
326                                     }
327                       }
328    SASINSTR_DET_OR_ATTR = {}
329    SASINSTR_DET_OR_ROLL = {"storeas" : "float",
330                            "unit" : "orientation_unit",
331                            "attributes" : SASINSTR_DET_OR_ATTR
332                           }
333    SASINSTR_DET_OR_PITCH = {"storeas" : "float",
334                             "unit" : "orientation_unit",
335                             "attributes" : SASINSTR_DET_OR_ATTR
336                            }
337    SASINSTR_DET_OR_YAW = {"storeas" : "float",
338                           "unit" : "orientation_unit",
339                           "attributes" : SASINSTR_DET_OR_ATTR
340                          }
341    SASINSTR_DET_OR = {"children" : {"roll" : SASINSTR_DET_OR_ROLL,
342                                     "pitch" : SASINSTR_DET_OR_PITCH,
343                                     "yaw" : SASINSTR_DET_OR_YAW,
344                                    }
345                      }
346    SASINSTR_DET_BC_X = {"storeas" : "float",
347                         "unit" : "beam_center_unit",
348                         "attributes" : {"storeas" : "content"}
349                        }
350    SASINSTR_DET_BC_Y = {"storeas" : "float",
351                         "unit" : "beam_center_unit",
352                         "attributes" : {"storeas" : "content"}
353                        }
354    SASINSTR_DET_BC_Z = {"storeas" : "float",
355                         "unit" : "beam_center_unit",
356                         "attributes" : {"storeas" : "content"}
357                        }
358    SASINSTR_DET_BC = {"children" : {"x" : SASINSTR_DET_BC_X,
359                                     "y" : SASINSTR_DET_BC_Y,
360                                     "z" : SASINSTR_DET_BC_Z,}
361                      }
362    SASINSTR_DET_PIXEL_X = {"storeas" : "float",
363                            "unit" : "pixel_size_unit",
364                            "attributes" : {"storeas" : "content" }
365                           }
366    SASINSTR_DET_PIXEL_Y = {"storeas" : "float",
367                            "unit" : "pixel_size_unit",
368                            "attributes" : {"storeas" : "content"}
369                           }
370    SASINSTR_DET_PIXEL_Z = {"storeas" : "float",
371                            "unit" : "pixel_size_unit",
372                            "attributes" : {"storeas" : "content"}
373                           }
374    SASINSTR_DET_PIXEL = {"children" : {"x" : SASINSTR_DET_PIXEL_X,
375                                        "y" : SASINSTR_DET_PIXEL_Y,
376                                        "z" : SASINSTR_DET_PIXEL_Z,
377                                       }
378                         }
379    SASINSTR_DET_SLIT = {"storeas" : "float",
380                         "unit" : "slit_length_unit",
381                         "attributes" : {"unit" : {}}
382                        }
383    SASINSTR_DET = {"attributes" : {"name" : {"storeas" : "content"}},
384                    "children" : {"name" : {"storeas" : "content"},
385                                  "SDD" : SASINSTR_DET_SDD,
386                                  "offset" : SASINSTR_DET_OFF,
387                                  "orientation" : SASINSTR_DET_OR,
388                                  "beam_center" : SASINSTR_DET_BC,
389                                  "pixel_size" : SASINSTR_DET_PIXEL,
390                                  "slit_length" : SASINSTR_DET_SLIT,
391                                 }
392                   }
393    SASINSTR = {"children" :
394                {"name" : {},
395                 "SASsource" : SASINSTR_SRC,
396                 "SAScollimation" : SASINSTR_COLL,
397                 "SASdetector" : SASINSTR_DET,
398                },
399               }
400    CANSAS_FORMAT = {"SASentry" :
401                     {"units_optional" : True,
402                      "storeas" : "content",
403                      "attributes" : {"name" : {}},
404                      "children" : {"Title" : TITLE,
405                                    "Run" : RUN,
406                                    "SASdata" : SASDATA,
407                                    "SAStransmission_spectrum" : SASTRANSSPEC,
408                                    "SASsample" : SASSAMPLE,
409                                    "SASinstrument" : SASINSTR,
410                                    "SASprocess" : SASPROCESS,
411                                    "SASnote" : SASNOTE,
412                                    "<any>" : ANY,
413                                   }
414                     }
415                    }
416
417
418class CurrentLevel(object):
419    """
420    A helper class to hold information on where you are in the constants tree
421    """
422
423    current_level = ''
424    ns_datatype = ''
425    ns_optional = True
426
427    def __init__(self):
428        self.current_level = {}
429        self.ns_datatype = "content"
430        self.ns_optional = True
431
432    def get_current_level(self):
433        """
434        Helper method to get the current_level map
435        """
436        return self.current_level
437
438    def get_data_type(self):
439        """
440        Helper method to get the ns_datatype label
441        """
442        return self.ns_datatype
443
444    def get_variable(self):
445        """
446        Helper method to get the ns_variable label
447        """
448        return self.ns_variable
Note: See TracBrowser for help on using the repository browser.