- Timestamp:
- 07/02/07 12:18:50 (14 years ago)
- Location:
- TI02-CSML/trunk/csml/csmllibs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI02-CSML/trunk/csml/csmllibs/csmlbuilder.py
r2071 r2121 76 76 if self.mapping=='onetomany': 77 77 self.ffmap = fmm.onetomany() 78 elif self.mapping=='onetoseveral': 79 self.ffmap = fmm.onetoseveral() 78 80 elif self.mapping=='onetoone': 79 81 self.ffmap = fmm.onetoone() -
TI02-CSML/trunk/csml/csmllibs/csmldataiface.py
r2112 r2121 44 44 #this function to examine the file and return the correct interface (if it exists). 45 45 fileExtension = str(filename)[-3:] 46 print 'fe: %s'%fileExtension47 46 if fileExtension == '.nc': 48 47 return cdunifInterface() -
TI02-CSML/trunk/csml/csmllibs/csmlfiles.py
r1887 r2121 4 4 import sys 5 5 import csml.csmllibs.csmldirectory 6 import csml.csmllibs.csmldataiface 6 7 7 8 … … 54 55 ffmap.addRepresentativeFile(repfile) 55 56 return ffmap 56 57 58 def onetoseveral(self): 59 ''' like one to many, but a directory may contain several representative files e.g. 5 files containing one (or more) feature(s), and then 5 files containing one (or more) different feature(s) etc. Need to examine the contents of each file to see if it's like another. Might be slow on large datsets as it examines the files individually.''' 60 tree = csml.csmllibs.csmldirectory.DirectoryTree() 61 tree.setTopDirectory(self.topdir) 62 tree.readDirectory() 63 subdirs = tree.getSubDirectories() 64 ffmap = csml.csmllibs.csmlfeaturefilemap.FeatureFileMap() 65 66 def __lookForSame(repFile, otherfiles): 67 '''recursively looks in list of otherfiles for files that match file in terms of dimensions (name + shape) and variables)''' 68 #this section compares the dimensions (name and shape) and variables in the other files with this representative file 69 repShapes=[] 70 DI=csml.csmllibs.csmldataiface.DataInterface() 71 DI=DI.getUnknownInterfaceType(file) 72 DI.openFile(repFile.getRepresentativeFileName()) 73 repVars=DI.getListofVariables() 74 tmpDims=DI.getListOfAxes() 75 repDims=[] 76 for dim in tmpDims: 77 if dim[:5] == 'axis_': #this is just to ignore the autogenerated axis_n dimensions used by cdms... 78 pass 79 else: 80 repDims.append(dim) 81 for dim in repDims: 82 DI.setAxis(dim) 83 repShapes.append(DI.getSizeOfAxis(dim)) 84 DI.closeFile() 85 nextotherfiles=[] 86 for otherfile in otherfiles: 87 compareShapes=[] 88 DI=csml.csmllibs.csmldataiface.DataInterface() 89 DI=DI.getUnknownInterfaceType(otherfile) 90 DI.openFile(otherfile) 91 compareVars=DI.getListofVariables() 92 tmpDims=DI.getListOfAxes() 93 compareDims=[] 94 for dim in tmpDims: 95 if dim[:5] == 'axis_': #again, skip the auto axis as they aren't a reliable measure 96 pass 97 else: 98 compareDims.append(dim) 99 for dim in compareDims: 100 DI.setAxis(dim) 101 compareShapes.append(DI.getSizeOfAxis(dim)) 102 if compareShapes + compareVars + compareDims == repShapes + repVars + repDims: 103 #found a match, add relatedFile to representativeFile 104 relfile = csml.csmllibs.csmlfeaturefilemap.relatedFile(otherfile) 105 relfile.setFeatureType(self.ft) 106 repFile.addRelatedFile(relfile) 107 else: 108 #keep this file for the next check 109 nextotherfiles.append(otherfile) #can't delete from list and loop at same time so use new list. 110 DI.closeFile() 111 otherfiles=nextotherfiles 112 ffmap.addRepresentativeFile(repFile) 113 if otherfiles !=[]: 114 nextfile=otherfiles[0] 115 nextrepFile=csml.csmllibs.csmlfeaturefilemap.representativeFile(nextfile) 116 nextrepFile.setFeatureType(self.ft) 117 otherfiles=__lookForSame(nextrepFile, otherfiles) 118 return otherfiles 119 120 121 for dir in subdirs: 122 file=tree.getFirstInSubDir(dir) 123 if file == None: 124 continue 125 #create first representative file 126 repfile=csml.csmllibs.csmlfeaturefilemap.representativeFile(file) 127 repfile.setFeatureType(self.ft) 128 try: 129 otherfiles=tree.getAllCSMLFilesExceptFirst(dir) 130 errtest=otherfiles[0] 131 except: 132 print 'no other csml files in this directory' 133 ffmap.addRepresentativeFile(repfile) 134 continue 135 otherfiles=__lookForSame(repfile, otherfiles) 136 return ffmap 137 57 138 def onetoone(self): 58 139 """ onetoone means each feature is self contained within any individual file
Note: See TracChangeset
for help on using the changeset viewer.