Changeset 268
- Timestamp:
- 12/02/09 15:27:23
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sodar/branches/scintec-branch/sodar/scintec/maindata.py
r267 r268 166 166 for block 167 167 in blocks[2:]]) 168 168 169 def __call__(self,timestamp,start=False): 170 """ 171 Get a profile by timestamp 172 173 maindata_instance(timestamp[,start]) -> <Profile object> 174 175 Where: 176 177 timestamp is a datetime.datetime object representing either 178 the start or stop timestamp of the Profile object returned. 179 180 start is a bool object. If start is False (default), then 181 timestamp is matched to the stop timestamp of the returned 182 Profile object. Otherwise, if start is True, then timestamp is 183 matched to the start timestamp of the returned Profile object. 184 185 Access profiles by timestamp: 186 >>> main_data = MainData(good_mnd) 187 >>> main_data(datetime(2009, 11, 17, 0, 30)).stop 188 datetime.datetime(2009, 11, 17, 0, 30) 189 >>> main_data(datetime(2009, 11, 17, 0, 0),True).start 190 datetime.datetime(2009, 11, 17, 0, 0) 191 >>> main_data(datetime(2009, 11, 18, 0, 0)).stop 192 datetime.datetime(2009, 11, 18, 0, 0) 193 >>> main_data(datetime(2009, 11, 17, 23, 0),True).start 194 datetime.datetime(2009, 11, 17, 23, 0) 195 >>> main_data(datetime(2009, 11, 16, 0, 30)) 196 Traceback (most recent call last): 197 ... 198 IndexError: 'MainData' object index out of range 199 >>> main_data('OK') 200 Traceback (most recent call last): 201 ... 202 TypeError: 'MainData' object indices must be datetime.datetime 203 instances 204 """ 205 206 for profile in self: 207 if start: 208 boundary = profile.start 209 else: 210 boundary = profile.stop 211 if boundary == timestamp: 212 return profile 213 if isinstance(timestamp,datetime): 214 raise IndexError, ' '.join([repr(self.__class__.__name__), 215 'object index out of range',]) 216 else: 217 raise TypeError, ' '.join([repr(self.__class__.__name__), 218 'object indices must be', 219 'datetime.datetime instances',]) 169 220 170 221 class Profile(list): … … 188 239 ['z', 'speed', 'dir', 'W', 'sigW', 'bck', 'error'] 189 240 190 Access profiles by sequence number and variables by attribute name:241 Access observations by sequence number and variables by attribute name: 191 242 >>> profile[0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 192 243 ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', … … 202 253 '99.99' 203 254 204 Access profiles by elevation and variables by attribute name:255 Access observations by elevation and variables by attribute name: 205 256 >>> profile['10'] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 206 257 ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', … … 241 292 ['z', 'speed', 'dir', 'W', 'sigW', 'bck', 'error'] 242 293 243 Access profiles by sequence number and variables by attribute name:294 Access observations by sequence number and variables by attribute name: 244 295 >>> profile[0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', 245 296 ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', … … 292 343 def __getitem__(self,key): 293 344 """ 294 Get a profileby elevation.345 Get a observation by elevation. 295 346 296 347 profile_instance[elevation] -> <Observation object> … … 301 352 (value keyed by 'z') of the Observation object. 302 353 303 Access profiles by elevation and variables by attribute name:354 Access observations by elevation and variables by attribute name: 304 355 >>> profile = Profile(good_profile) 305 356 >>> profile['10'] == {'z':'10', 'speed':'99.99', 'dir':'999.9', … … 315 366 >>> profile['200'].W 316 367 '-0.07' 368 >>> profile[100000] 369 Traceback (most recent call last): 370 ... 371 IndexError: list index out of range 372 >>> profile['100000'] 373 Traceback (most recent call last): 374 ... 375 TypeError: list indices must be integers 317 376 """ 318 377 … … 625 684 ... 626 685 TypeError: 'Profile' instance's items are read-only 627 628 686 629 687 Without affecting the observations: