source: TI02-CSML/trunk/Scanner/csmllibs/csmlfileextracts.py @ 898

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/Scanner/csmllibs/csmlfileextracts.py@898
Revision 898, 3.3 KB checked in by domlowe, 14 years ago (diff)

cleaned up excess print statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2
3#!/usr/bin/env python
4import os
5import csmllibs
6import sys
7class fileExtractBuilder:
8    def __init__(self, dataset_element, ffmap):
9        self.dataset_element=dataset_element
10        self.ffmap=ffmap
11        self.createFileExtracts()
12   
13    def createFileExtracts(self):
14        #print "REPRESENTATIVE FILES:"
15        #print self.ffmap.getRepresentativeFiles()
16       
17        #given a featurefilemap object, create file extracts from the "representativeFiles"     
18        #used to store extract/filename/variable relationship
19        #referenced when creating features
20        self.fileExtractDictionary={}
21   
22        fileid=0  #used to distinguish extract names for similar variables from different files
23        #adlist is an empty list object to hold CSML ArrayDescriptors eg. NetCDFExtract, GRIBExtract etc
24        adlist=[]
25        for repfile in self.ffmap.getRepresentativeFiles():
26            fileid=fileid+1
27            filename=repfile.getRepresentativeFileName()
28            #print 'representative file:'
29            #print repfile.getRepresentativeFileName()
30            #print 'feature type:'
31            #print repfile.getFeatureType()     
32            DI = csmllibs.csmldataiface.DataInterface()
33            DI = DI.getUnknownInterfaceType(filename)
34            DI.openFile(filename)
35            #creates fileextracts for each variable of each representative file
36            self.extractType = DI.extractType
37            self.extractPrefix = str(fileid)+'_'+DI.extractPrefix
38            #print dir(DI)
39            allDimNames=DI.getListOfAxes()
40            numDomains=len(allDimNames)
41            for j in range (0, len(allDimNames)):
42                #print self.extractType
43                #print self.extractPrefix
44                if self.extractType=='NASAAmesExtract':
45                    arrayDescriptor=csmllibs.Parser.NASAAmesExtract()
46                if self.extractType=='NetCDFExtract':
47                    arrayDescriptor=csmllibs.Parser.NetCDFExtract()
48                if self.extractType=='GRIBExtract':
49                    arrayDescriptor=csmllibs.Parser.GRIBExtract()
50                if self.extractType=='PPExtract':
51                    arrayDescriptor=csmllibs.Parser.PPExtract()
52                #print self.extractType
53                arrayDescriptor.id=str(self.extractPrefix+allDimNames[j])
54   
55                #SET variableName attribute of file extract
56                arrayDescriptor.variableName=str(allDimNames[j])
57               
58               
59                #SET arraySize attribute of file extract
60                dimValue =DI.getSizeOfAxis(allDimNames[j])
61                if dimValue == None:
62                    dimValue ='1'  #temporary to fix unlimited problem
63                arrayDescriptor.arraySize=str(dimValue)
64                #SET filename attribute of file extract
65                arrayDescriptor.fileName = filename
66           
67    #                   #keep record of extracts/filenames/variables in dictionary
68                idstr = filename + allDimNames[j]
69                self.fileExtractDictionary[idstr] = self.extractPrefix+allDimNames[j]
70                adlist.append(arrayDescriptor)
71            DI.closeFile()     
72        #Add all the file extracts to the dataset element
73        setattr(self.dataset_element, 'arrayDescriptors', adlist)
74   
75        #    sys.exit()
76           
77   
78
Note: See TracBrowser for help on using the repository browser.