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

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

fixed whitespace issues, namespace issues

  • 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                #SET arraySize attribute of file extract
59                dimValue =DI.getSizeOfAxis(allDimNames[j])
60                if dimValue == None:
61                    dimValue ='1'  #temporary to fix unlimited problem
62                arrayDescriptor.arraySize=str(dimValue)
63                #SET filename attribute of file extract
64                arrayDescriptor.fileName = filename
65           
66    #                   #keep record of extracts/filenames/variables in dictionary
67                idstr = filename + allDimNames[j]
68                self.fileExtractDictionary[idstr] = self.extractPrefix+allDimNames[j]
69                adlist.append(arrayDescriptor)
70            DI.closeFile()     
71        #Add all the file extracts to the dataset element
72        setattr(self.dataset_element, 'arrayDescriptors', adlist)
73   
74        #    sys.exit()
75           
76   
77
Note: See TracBrowser for help on using the repository browser.