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

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

propagating additional args/configs through Scanner code

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