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