Changeset ac5b69d in sasview for src/sans/dataloader/readers/cansas_constants.py
- Timestamp:
- May 5, 2014 3:41:43 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c81aa18
- Parents:
- 0089be3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/dataloader/readers/cansas_constants.py
r9e2bc6c rac5b69d 3 3 the cansas_reader.py file to read in any version of the cansas format. 4 4 """ 5 class cansasConstants: 6 7 ns = '' 5 class 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 = '' 8 12 format = '' 9 13 10 14 11 15 def __init__(self): 12 self.n s = self.CANSAS_NS16 self.names = self.CANSAS_NS 13 17 self.format = self.CANSAS_FORMAT 14 18 15 19 16 def _iterate_namespace(self, namespace):20 def iterate_namespace(self, namespace): 17 21 """ 18 22 Method to iterate through a cansas constants tree based on a list of … … 23 27 """ 24 28 # The current level to look through in cansas_constants. 25 return_me = currentLevel()29 return_me = CurrentLevel() 26 30 return_me.current_level = self.CANSAS_FORMAT.get("SASentry") 27 31 # Defaults for variable and datatype … … 30 34 return_me.ns_optional = True 31 35 for name in namespace: 32 if name != "SASentry": 33 return_me.current_level = \ 34 return_me.current_level.get("children").get(name, "") 35 if return_me.current_level == "": 36 try: 37 if name != "SASentry": 36 38 return_me.current_level = \ 37 return_me.current_level.get("<any>", "") 38 cl_variable = return_me.current_level.get("variable", "") 39 cl_datatype = return_me.current_level.get("storeas", "") 40 cl_units_optional = \ 41 return_me.current_level.get("units_required", "") 42 # Where are how to store the variable for the given namespace 43 # CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit 44 return_me.ns_variable = cl_variable if cl_variable != "" else \ 45 return_me.ns_variable 46 return_me.ns_datatype = cl_datatype if cl_datatype != "" else \ 47 return_me.ns_datatype 48 return_me.ns_optional = cl_units_optional if \ 49 cl_units_optional != return_me.ns_optional \ 50 else return_me.ns_optional 39 return_me.current_level.get("children").get(name, "") 40 if return_me.current_level == "": 41 return_me.current_level = \ 42 return_me.current_level.get("<any>", "") 43 cl_variable = return_me.current_level.get("variable", "") 44 cl_datatype = return_me.current_level.get("storeas", "") 45 cl_units_optional = \ 46 return_me.current_level.get("units_required", "") 47 # Where are how to store the variable for the given namespace 48 # CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit 49 return_me.ns_variable = cl_variable if cl_variable != "" else \ 50 return_me.ns_variable 51 return_me.ns_datatype = cl_datatype if cl_datatype != "" else \ 52 return_me.ns_datatype 53 return_me.ns_optional = cl_units_optional if \ 54 cl_units_optional != return_me.ns_optional \ 55 else return_me.ns_optional 56 except AttributeError: 57 return_me.ns_variable = "{0}.meta_data[\"{2}\"] = \"{1}\"" 58 return_me.ns_datatype = "content" 59 return_me.ns_optional = True 51 60 return return_me 52 61 … … 454 463 } 455 464 SASINSTR_SRC = { 456 "attributes" : {"name" : {"variable" : "{0}.source.name = \"{1}\""}}, 465 "attributes" : {"name" : {"variable" : \ 466 "{0}.source.name = \"{1}\""}}, 457 467 "variable" : None, 458 468 "children" : { 459 "radiation" : {"variable" : "{0}.source.radiation = \"{1}\""}, 469 "radiation" : {"variable" : \ 470 "{0}.source.radiation = \"{1}\""}, 460 471 "beam_size" : SASINSTR_SRC_BEAMSIZE, 461 472 "beam_shape" : {"variable" : \ … … 647 658 "unit" : "pixel_size_unit", 648 659 "attributes" : { 649 "unit" : "{0}.pixel_size_unit = \"{1}\"", 660 "unit" : \ 661 "{0}.pixel_size_unit = \"{1}\"", 650 662 "storeas" : "content" 651 663 } … … 655 667 "unit" : "pixel_size_unit", 656 668 "attributes" : { 657 "unit" : "{0}.pixel_size_unit = \"{1}\"", 669 "unit" : \ 670 "{0}.pixel_size_unit = \"{1}\"", 658 671 "storeas" : "content" 659 672 } … … 663 676 "unit" : "pixel_size_unit", 664 677 "attributes" : { 665 "unit" : "{0}.pixel_size_unit = \"{1}\"", 678 "unit" : \ 679 "{0}.pixel_size_unit = \"{1}\"", 666 680 "storeas" : "content" 667 681 } … … 740 754 } 741 755 742 class currentLevel: 756 class CurrentLevel: 757 """ 758 A helper class to hold information on where you are in the constants tree 759 """ 743 760 744 761 current_level = '' … … 748 765 749 766 def __init__(self): 750 self.current_level = ''767 self.current_level = {} 751 768 self.ns_variable = '' 752 769 self.ns_datatype = "content"
Note: See TracChangeset
for help on using the changeset viewer.