Index: sodar/branches/scintec-branch/sodar/scintec/maindata.py =================================================================== --- sodar/branches/scintec-branch/sodar/scintec/maindata.py (revision 261) +++ sodar/branches/scintec-branch/sodar/scintec/maindata.py (revision 262) @@ -12,5 +12,5 @@ class MainData(list): """ - Contain data from Scintec sodar .mnd files. + Contain data from a Scintec sodar .mnd file. Parse a known good .mnd file: @@ -41,8 +41,12 @@ ... 'sigW', 'bck', 'error'] True - >>> main_data[0][0] - '10 99.99 999.9 -0.05 0.40 5.46E+03 0' - >>> main_data[0][-1] - '200 99.99 999.9 -0.07 99.99 9.99E+37 0' + >>> main_data[0][0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', + ... 'error':'0'} + True + >>> main_data[0][-1] == {'z':'200', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.07', 'sigW':'99.99', 'bck':'9.99E+37', + ... 'error':'0'} + True Parse the last profile: @@ -54,8 +58,12 @@ ... 'sigW', 'bck', 'error'] True - >>> main_data[-1][0] - '10 99.99 999.9 -0.32 99.99 9.99E+37 0' - >>> main_data[-1][-1] - '200 15.05 71.8 -0.19 0.53 9.99E+37 0' + >>> main_data[-1][0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.32', 'sigW':'99.99', 'bck':'9.99E+37', + ... 'error':'0'} + True + >>> main_data[-1][-1] == {'z':'200', 'speed':'15.05', 'dir':'71.8', + ... 'W':'-0.19', 'sigW':'0.53', 'bck':'9.99E+37', + ... 'error':'0'} + True """ @@ -71,8 +79,8 @@ Scintec .mnd daily sodar file including all line endings, - file_name is an optional string object representing a file name for + file_name is an optional str object representing a file name for a file which contains the referenced .mnd daily sodar file, - file_path is an optional string object representing the path to + file_path is an optional str object representing the path to file_name. @@ -118,5 +126,5 @@ class Profile(list): """ - Contain data for single profile from Scintec sodar .mnd files. + Contain data for single profile from a Scintec sodar .mnd file. Parse a known good profile block: @@ -127,8 +135,12 @@ ... 'sigW', 'bck', 'error'] True - >>> profile[0] - '10 99.99 999.9 -0.05 0.40 5.46E+03 0' - >>> profile[-1] - '200 99.99 999.9 -0.07 99.99 9.99E+37 0' + >>> profile[0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', + ... 'error':'0'} + True + >>> profile[-1] == {'z':'200', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.07', 'sigW':'99.99', 'bck':'9.99E+37', + ... 'error':'0'} + True """ @@ -151,8 +163,12 @@ ... 'sigW', 'bck', 'error'] True - >>> profile[0] - '10 99.99 999.9 -0.05 0.40 5.46E+03 0' - >>> profile[-1] - '200 99.99 999.9 -0.07 99.99 9.99E+37 0' + >>> profile[0] == {'z':'10', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', + ... 'error':'0'} + True + >>> profile[-1] == {'z':'200', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.07', 'sigW':'99.99', 'bck':'9.99E+37', + ... 'error':'0'} + True """ @@ -161,5 +177,42 @@ self.timestamp = profile_block[0] self.variables = profile_block[1].split()[1:] - self.extend(profile_block[2:]) + self.extend([Observation(observation.split(),self.variables) + for observation in profile_block[2:]]) + +class Observation(dict): + """ + Contain data for single observation from a Scintec sodar .mnd files. + + Parse a known good observation: + >>> observation = Observation(good_observation,good_variables) + >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', + ... 'error':'0'} + True + """ + + def __init__(self,data,variables): + """ + Parse an observation from a main daily Scintec sodar .mnd file. + + Observation(data,variables) -> + + Where: + + data is a list of str object representing variable values, + + variables is a list of str objects representing variable labels. + + Parse a known good observation: + >>> observation = Observation(good_observation,good_variables) + >>> observation == {'z':'10', 'speed':'99.99', 'dir':'999.9', + ... 'W':'-0.05', 'sigW':'0.40', 'bck':'5.46E+03', + ... 'error':'0'} + True + """ + + super(Observation, self).__init__() + + self.update(dict(zip(variables,data))) def _test(): @@ -172,9 +225,12 @@ import doctest from sodar.tests import suite - mnd_path,mnd_file,mnd,profile = suite.setUpGoodMndData() + mnd_path,mnd_file,mnd,profile,variables,observation = \ + suite.setUpGoodMndData() doctest.testmod(extraglobs=dict(good_mnd=mnd, good_name=mnd_file, good_path=mnd_path, - good_profile=profile), + good_profile=profile, + good_variables=variables, + good_observation=observation), optionflags=doctest.NORMALIZE_WHITESPACE) Index: sodar/branches/scintec-branch/sodar/tests/suite.py =================================================================== --- sodar/branches/scintec-branch/sodar/tests/suite.py (revision 259) +++ sodar/branches/scintec-branch/sodar/tests/suite.py (revision 262) @@ -45,5 +45,7 @@ profile = mnd.split('\n\n')[2].split('\n') profile = [line.strip() for line in profile if line] - return (mnd_path,mnd_file,mnd,profile,) + variables = profile[1].split()[1:] + observation = profile[2].split() + return (mnd_path,mnd_file,mnd,profile,variables,observation,) def setUpGoodMnd(test): @@ -52,9 +54,11 @@ """ - mnd_path,mnd_file,mnd,profile = setUpGoodMndData() + mnd_path,mnd_file,mnd,profile,variables,observation = setUpGoodMndData() test.globs.update(good_mnd=mnd, good_name=mnd_file, good_path=mnd_path, - good_profile=profile) + good_profile=profile, + good_variables=variables, + good_observation=observation) def test_suite():