Ignore:
Timestamp:
May 5, 2014 3:41:43 PM (10 years ago)
Author:
Jeff Krzywon <jeffery.krzywon@…>
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
Message:

Ticket #249 fix: Saving and loading projects and analysis is now working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sans/dataloader/readers/cansas_constants.py

    r9e2bc6c rac5b69d  
    33the cansas_reader.py file to read in any version of the cansas format. 
    44""" 
    5 class cansasConstants: 
    6      
    7     ns = '' 
     5class CansasConstants: 
     6    """ 
     7    The base class to define where all of the data is to be saved by 
     8    cansas_reader.py. 
     9    """ 
     10     
     11    names = '' 
    812    format = '' 
    913     
    1014     
    1115    def __init__(self): 
    12         self.ns = self.CANSAS_NS 
     16        self.names = self.CANSAS_NS 
    1317        self.format = self.CANSAS_FORMAT 
    1418     
    1519     
    16     def _iterate_namespace(self, namespace): 
     20    def iterate_namespace(self, namespace): 
    1721        """ 
    1822        Method to iterate through a cansas constants tree based on a list of 
     
    2327        """ 
    2428        # The current level to look through in cansas_constants. 
    25         return_me = currentLevel() 
     29        return_me = CurrentLevel() 
    2630        return_me.current_level = self.CANSAS_FORMAT.get("SASentry") 
    2731        # Defaults for variable and datatype 
     
    3034        return_me.ns_optional = True 
    3135        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": 
    3638                    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 
    5160        return return_me     
    5261     
     
    454463                           } 
    455464    SASINSTR_SRC = { 
    456                     "attributes" : {"name" : {"variable" : "{0}.source.name = \"{1}\""}}, 
     465                    "attributes" : {"name" : {"variable" : \ 
     466                                              "{0}.source.name = \"{1}\""}}, 
    457467                    "variable" : None, 
    458468                    "children" : { 
    459                                   "radiation" : {"variable" : "{0}.source.radiation = \"{1}\""}, 
     469                                  "radiation" : {"variable" : \ 
     470                                            "{0}.source.radiation = \"{1}\""}, 
    460471                                  "beam_size" : SASINSTR_SRC_BEAMSIZE, 
    461472                                  "beam_shape" : {"variable" : \ 
     
    647658                        "unit" : "pixel_size_unit", 
    648659                        "attributes" : { 
    649                                         "unit" : "{0}.pixel_size_unit = \"{1}\"", 
     660                                        "unit" : \ 
     661                                            "{0}.pixel_size_unit = \"{1}\"", 
    650662                                        "storeas" : "content" 
    651663                                        } 
     
    655667                        "unit" : "pixel_size_unit", 
    656668                        "attributes" : { 
    657                                         "unit" : "{0}.pixel_size_unit = \"{1}\"", 
     669                                        "unit" : \ 
     670                                            "{0}.pixel_size_unit = \"{1}\"", 
    658671                                        "storeas" : "content" 
    659672                                        } 
     
    663676                        "unit" : "pixel_size_unit", 
    664677                        "attributes" : { 
    665                                         "unit" : "{0}.pixel_size_unit = \"{1}\"", 
     678                                        "unit" : \ 
     679                                            "{0}.pixel_size_unit = \"{1}\"", 
    666680                                        "storeas" : "content" 
    667681                                        } 
     
    740754                     } 
    741755    
    742 class currentLevel: 
     756class CurrentLevel: 
     757    """ 
     758    A helper class to hold information on where you are in the constants tree 
     759    """ 
    743760      
    744761    current_level = '' 
     
    748765      
    749766    def __init__(self): 
    750         self.current_level = '' 
     767        self.current_level = {} 
    751768        self.ns_variable = '' 
    752769        self.ns_datatype = "content" 
Note: See TracChangeset for help on using the changeset viewer.