source: TI02-CSML/trunk/csml/csmllibs/csmlfileextracts.py @ 2003

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

aggregatedArray created outside of rangeSet

  • 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 csml.parser
6import csml.csmllibs
7import sys
8class fileExtractBuilder(object):
9    def __init__(self, dataset_element, ffmap, timedim):
10        self.dataset_element=dataset_element
11        self.ffmap=ffmap
12        self.fileExtractDictionary={} #used to store extract/filename/variable relationship
13        self.createFileExtractsForAxes()
14
15    def createFileExtractsForAxes(self):
16        #given a featurefilemap object, create file extracts for the axes from the "representativeFiles"       
17           
18        fileid=0  #used to distinguish extract names for similar variables from different files
19        #adlist is an empty list object to hold CSML ArrayDescriptors eg. NetCDFExtract, GRIBExtract etc
20        adlist=[]
21        for repfile in self.ffmap.getRepresentativeFiles():
22            fileid=fileid+1
23            filename=repfile.getRepresentativeFileName()
24            DI = csml.csmllibs.csmldataiface.DataInterface()
25            DI = DI.getUnknownInterfaceType(filename)
26            DI.openFile(filename)
27            #creates fileextracts for each variable of each representative file
28            self.extractType = DI.extractType
29            self.extractPrefix = str(fileid)+'_'+DI.extractPrefix
30            #print dir(DI)
31            allDimNames=DI.getListOfAxes()
32            numDomains=len(allDimNames)
33            for j in range (0, len(allDimNames)):
34                if self.extractType=='NASAAmesExtract':
35                    arrayDescriptor=csml.parser.NASAAmesExtract()
36                if self.extractType=='NetCDFExtract':
37                    arrayDescriptor=csml.parser.NetCDFExtract()
38                if self.extractType=='GRIBExtract':
39                    arrayDescriptor=csml.parser.GRIBExtract()
40                if self.extractType=='PPExtract':
41                    arrayDescriptor=csml.parser.PPExtract()
42                #print self.extractType
43                arrayDescriptor.id=str(self.extractPrefix+allDimNames[j])
44   
45                #SET variableName attribute of file extract
46                arrayDescriptor.variableName=csml.parser.csString(allDimNames[j])
47               
48               
49                #SET arraySize attribute of file extract
50                dimValue =DI.getSizeOfAxis(allDimNames[j])
51                if dimValue == None:
52                    dimValue ='1'  #temporary to fix unlimited problem
53                arrayDescriptor.arraySize=csml.parser.csString(dimValue)
54                #SET filename attribute of file extract
55                arrayDescriptor.fileName = csml.parser.csString(filename)
56           
57    #                   #keep record of extracts/filenames/variables in dictionary
58                idstr = filename + allDimNames[j]
59                self.fileExtractDictionary[idstr] = self.extractPrefix+allDimNames[j]
60                adlist.append(arrayDescriptor)
61            DI.closeFile()     
62        #Add all the file extracts to the dataset element
63        print adlist
64        setattr(self.dataset_element, 'fileExtracts', adlist)
65   
66
67def createSingleExtract(extractType, fileName, variableName, arraySize):
68    #creates a single file extract on demand. (not part of general builder class)
69    #need to incorporate check that a file extract of the same name doesn't already exist.
70    if extractType=='NASAAmesExtract':
71        arrayDescriptor=csml.parser.NASAAmesExtract()
72    if extractType=='NetCDFExtract':
73        arrayDescriptor=csmllibs.Parser.NetCDFExtract()
74    if extractType=='GRIBExtract':
75        arrayDescriptor=csmllibs.Parser.GRIBExtract()
76    if extractType=='PPExtract':
77        arrayDescriptor=csmllibs.Parser.PPExtract()
78    #need to change this so it does the right thing for grib extracts too..
79    arrayDescriptor.id=variableName   #need prefix system here..?
80    arrayDescriptor.fileName = fileName
81    arrayDescriptor.arraySize=[arraySize]
82    arrayDescriptor.variableName=variableName
83    return arrayDescriptor
84
85        #    sys.exit()
86           
87   
88
Note: See TracBrowser for help on using the repository browser.