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

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

storage descriptor code working in scanner

  • 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                rndID=csml.csmllibs.csmlextra.getRandomID()
44                #arrayDescriptor.id=str(self.extractPrefix+allDimNames[j])
45                arrayDescriptor.id=str(rndID)
46                #SET variableName attribute of file extract
47                arrayDescriptor.variableName=csml.parser.csString(allDimNames[j])
48               
49               
50                #SET arraySize attribute of file extract
51                dimValue =DI.getSizeOfAxis(allDimNames[j])
52                if dimValue == None:
53                    dimValue ='1'  #temporary to fix unlimited problem
54                arrayDescriptor.arraySize=csml.parser.csString(dimValue)
55                #SET filename attribute of file extract
56                arrayDescriptor.fileName = csml.parser.csString(filename)
57           
58    #                   #keep record of extracts/filenames/variables in dictionary
59                idstr = filename + allDimNames[j]
60                self.fileExtractDictionary[idstr] = rndID#self.extractPrefix+allDimNames[j]
61                adlist.append(arrayDescriptor)
62            DI.closeFile()     
63        #Add all the file extracts to the dataset element
64        sd=csml.parser.CSMLStorageDescriptor()
65        sd.descriptors=adlist
66        setattr(self.dataset_element, 'storageDescriptor', sd)
67
68def createSingleExtract(extractType, fileName, variableName, arraySize):
69    #creates a single file extract on demand. (not part of general builder class)
70    #need to incorporate check that a file extract of the same name doesn't already exist.
71    if extractType=='NASAAmesExtract':
72        arrayDescriptor=csml.parser.NASAAmesExtract()
73    if extractType=='NetCDFExtract':
74        arrayDescriptor=csmllibs.Parser.NetCDFExtract()
75    if extractType=='GRIBExtract':
76        arrayDescriptor=csmllibs.Parser.GRIBExtract()
77    if extractType=='PPExtract':
78        arrayDescriptor=csmllibs.Parser.PPExtract()
79    #need to change this so it does the right thing for grib extracts too..
80    arrayDescriptor.id=variableName   #need prefix system here..?
81    arrayDescriptor.fileName = fileName
82    arrayDescriptor.arraySize=[arraySize]
83    arrayDescriptor.variableName=variableName
84    return arrayDescriptor
85
86        #    sys.exit()
87           
88   
89
Note: See TracBrowser for help on using the repository browser.