Changeset 3988 for nappy/trunk
- Timestamp:
- 04/06/08 14:12:18 (12 years ago)
- Location:
- nappy/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
nappy/trunk/nappy.ini
r3987 r3988 4 4 default_delimiter = __space____space____space____space__ 5 5 default_float_format = %g 6 comment_override_rule = replace 6 7 annotations_file = annotations.ini 7 8 local_attributes_file = local_attributes.ini … … 32 33 file_number_in_set = IVOL 33 34 first_valid_date_of_data = DATE 35 36 -
nappy/trunk/nappy/na_file/na_file.py
r3746 r3988 31 31 wrapLine = nappy.utils.common_utils.annotateLine 32 32 wrapLines = nappy.utils.common_utils.annotateLines 33 stripQuotes = nappy.utils.common_utils.stripQuotes 33 34 34 35 … … 190 191 self.header.write(wrapLine("NLHEAD_FFI", self.annotation, self.delimiter, "%d%s%d\n" % (self.NLHEAD, self.delimiter, self.FFI))) 191 192 #print ("ONAME", self.annotation, self.delimiter, self.ONAME) 192 self.header.write(getAnnotation("ONAME", self.annotation, delimiter = self.delimiter) + `self.ONAME`+ "\n")193 self.header.write(getAnnotation("ORG", self.annotation, delimiter = self.delimiter) + `self.ORG`+ "\n")194 self.header.write(getAnnotation("SNAME", self.annotation, delimiter = self.delimiter) + `self.SNAME`+ "\n")195 self.header.write(getAnnotation("MNAME", self.annotation, delimiter = self.delimiter) + `self.MNAME`+ "\n")193 self.header.write(getAnnotation("ONAME", self.annotation, delimiter = self.delimiter) + stripQuotes(self.ONAME) + "\n") 194 self.header.write(getAnnotation("ORG", self.annotation, delimiter = self.delimiter) + stripQuotes(self.ORG) + "\n") 195 self.header.write(getAnnotation("SNAME", self.annotation, delimiter = self.delimiter) + stripQuotes(self.SNAME) + "\n") 196 self.header.write(getAnnotation("MNAME", self.annotation, delimiter = self.delimiter) + stripQuotes(self.MNAME) + "\n") 196 197 self.header.write(wrapLine("IVOL_NVOL", self.annotation, self.delimiter, "%d%s%d\n" % (self.IVOL, self.delimiter, self.NVOL))) 197 198 line = "%d %d %d%s%d %d %d\n" % (self.DATE[0], self.DATE[1], self.DATE[2], self.delimiter, self.RDATE[0], self.RDATE[1], self.RDATE[2]) -
nappy/trunk/nappy/nc_interface/na_content_collector.py
r3966 r3988 330 330 self.na_dict["VSCAL"].append(1) 331 331 # Populate the variable list with the array 332 self.na_dict["V"].append(var._data) 332 #print var._data.tolist() 333 self.na_dict["V"].append(var.tolist()) 333 334 334 335 # Create independent variable info … … 484 485 """ 485 486 # Check if we should add to it with locally set rules 486 local_attributes = nappy.utils.getConfigDict()["local_attributes"] 487 for att, value in local_attributes.items(): 487 local_attributes = nappy.utils.getLocalAttributesConfigDict() 488 local_nc_atts = local_attributes["nc_attributes"] 489 490 for att, value in local_nc_atts.items(): 488 491 if not nc_to_na_map.has_key(att): 489 492 nc_to_na_map[key] = value -
nappy/trunk/nappy/nc_interface/nc_to_na.py
r3987 r3988 41 41 default_delimiter = nappy.utils.getDefault("default_delimiter") 42 42 default_float_format = nappy.utils.getDefault("default_float_format") 43 comment_override_rule = nappy.utils.getDefault("comment_override_rule") 43 44 44 45 # Define global variables 45 46 permitted_overwrite_metadata = ("DATE", "RDATE", "ANAME", "MNAME", 46 "ONAME", "ORG", "SNAME", "VNAME" )47 "ONAME", "ORG", "SNAME", "VNAME", "SCOM", "NCOM") 47 48 items_as_lists = ["DATE", "RDATE", "ANAME", "VNAME"] 48 49 … … 151 152 full_file_counter = 1 152 153 154 # Get any NASA Ames dictionary values that should be overwritten with local values 155 local_attributes = nappy.utils.getLocalAttributesConfigDict() 156 local_na_atts = local_attributes["na_attributes"] 157 158 # define final override list by using defaults then locally provided changes 159 overriders = local_na_atts 160 for (okey, ovalue) in self.na_items_to_override.items(): 161 overriders[okey] = ovalue 162 153 163 # Now loop through writing the outputs 154 164 for na_dict_and_var_ids in self.na_dict_list: … … 162 172 163 173 # Override content of NASA Ames if they are permitted 164 for key in self.na_items_to_override.keys(): 174 for key in overriders.keys(): 175 165 176 if key in permitted_overwrite_metadata: 166 177 if key in items_as_lists: 167 new_item = self.na_items_to_override[key].split()178 new_item = overriders[key].split() 168 179 else: 169 new_item = self.na_items_to_override[key] 180 new_item = overriders[key] 181 182 # Do specific overwrite for comments by inserting lines at start 183 if key in ("SCOM", "NCOM"): 184 185 # Use rule defined in config file in terms of where to put new comments 186 if comment_override_rule == "replace": 187 comments_list = new_item 188 elif comment_override_rule == "insert": 189 comments_list = new_item + this_na_dict.get(key, []) 190 elif comment_override_rule == "extend": 191 comments_list = this_na_dict.get(key, []) + new_item 192 193 this_na_dict[key] = comments_list 194 this_na_dict["N%sL" % key] = len(comments_list) 195 print "Added to comments:", key 170 196 171 tt = this_na_dict.keys() 172 tt.sort; print tt 173 if new_item != this_na_dict[key]: 197 elif not this_na_dict.has_key(key) or new_item != this_na_dict[key]: 174 198 this_na_dict[key] = new_item 175 199 msg = "Metadata overwritten in output file: '%s' is now '%s'" % (key, this_na_dict[key]) -
nappy/trunk/nappy/utils/__init__.py
r3630 r3988 1 from parse_config import getConfigDict 1 from parse_config import getConfigDict, getLocalAttributesConfigDict 2 2 from common_utils import getDebug, getVersion, getDefault -
nappy/trunk/nappy/utils/common_utils.py
r3630 r3988 131 131 def getDefault(item): 132 132 """ 133 Returns value of item from 'm rain' config file section.133 Returns value of item from 'main' config file section. 134 134 """ 135 135 value = parse_config.getConfigDict()["main"][item] … … 189 189 else: 190 190 return line 191 192 193 def stripQuotes(s): 194 "Strips extra quotes" 195 if type(s) != type("string"): s = str(s) 196 if s[0] in ("'", '"'): s = s[1:] 197 if s[-1] in ("'", '"'): s = s[:-1] 198 return s -
nappy/trunk/nappy/utils/parse_config.py
r3987 r3988 16 16 config_dict = None 17 17 annotations_config_dict = None 18 18 attributes_config_dict = None 19 19 20 20 class MyCasePreservingConfigParser(ConfigParser.ConfigParser): … … 87 87 88 88 89 def makeLocalAttributesConfigDict(laf): 90 """ 91 Parses local attributes config file and returns dictionary. 92 """ 93 lad = {} 94 conf = MyCasePreservingConfigParser() 95 conf.read(laf) 96 97 # Load up dict 98 for sect in ("nc_attributes", "na_attributes"): 99 lad[sect] = {} 100 for item in conf.options(sect): 101 value = conf.get(sect, item) 102 print value 103 lad[sect][item] = value 104 105 return lad 106 107 108 def getLocalAttributesConfigDict(): 109 "Checks if already made and only makes if required." 110 config_dict = getConfigDict() 111 112 local_attributes_config_file = os.environ.get("NAPPY_LOCAL_ATTRIBUTES", None) or \ 113 config_dict["main"]["local_attributes_file"] 114 115 laf = os.path.join(base_dir, local_attributes_config_file) 116 global attributes_config_dict 117 118 if attributes_config_dict == None: 119 attributes_config_dict = makeLocalAttributesConfigDict(laf) 120 return attributes_config_dict 121 122 123 89 124 if __name__=="__main__": 90 125 91 126 print getConfigDict() 92 127 print getAnnotationsConfigDict() 128 print getLocalAttributesConfigDict() 129 -
nappy/trunk/setup_env.sh
r3987 r3988 3 3 export PYTHONPATH=$NAPPY_BASE_DIR:$PYTHONPATH 4 4 unset NAPPY_ANNOTATIONS 5 unset NAPPY_LOCAL_ATTRIBUTES
Note: See TracChangeset
for help on using the changeset viewer.