Changeset 2569


Ignore:
Timestamp:
11/06/07 10:36:57 (12 years ago)
Author:
domlowe
Message:

fixing ID/naming issues and paths

Location:
TI02-CSML/trunk/csml
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/csml/API/csmlContainer.py

    r2567 r2569  
    11import csml 
     2OUTPUTDIR=None 
     3 
     4class globalContainer(object): 
     5    '''container for (optional) shared variables (eg outputdir)''' 
     6    OUTPUTDIR=None 
     7     
    28 
    39class Container(object): 
     
    612    def __init__(self,outputdir, csmlname='myfile.xml',docID='none',metadata='unspecified'): 
    713        self.outputdir =outputdir 
     14        globalContainer.OUTPUTDIR=outputdir 
    815        self.csmlname=csmlname 
    916        ''' Initialise CSML Dataset and FeatureCollection and populate with basic Metadata''' 
  • TI02-CSML/trunk/csml/API/genSubset.py

    r2567 r2569  
    229229 
    230230def genericSubset(feature, outputdir, ncname, domain, kwargs): 
    231     pathToSubsetNetCDF=outputdir+'/' +ncname 
     231    if outputdir is not None: 
     232        pathToSubsetNetCDF=outputdir+'/' +ncname 
     233    else: 
     234        pathToSubsetNetCDF=ncname 
    232235     
    233236    #deal with longitude requests 
  • TI02-CSML/trunk/csml/API/ops_FileExtract.py

    r2562 r2569  
    3030 
    3131def getData(self,  fileposition=None,**kwargs): 
     32    if csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     33        directory=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
     34    else: 
     35        directory=None 
     36     
    3237    #file position defines the position of the filename if a list of filenames exists 
    3338    #**kwargs can hold subsetting request. 
     
    4651    DI = csml.csmllibs.csmldataiface.DataInterface() 
    4752    DI=DI.getUnknownInterfaceType(file) 
    48     DI.openFile(file) 
     53    try: 
     54        DI.openFile(file) 
     55    except: 
     56        if directory is not None: 
     57            file=directory +'/' + file 
     58            DI.openFile(file) 
    4959    DI.setAxis(self.variableName.CONTENT) 
    5060    try: 
     
    5666        units=None 
    5767    except: 
     68        print DI.file 
     69        print DI.getListofVariables() 
     70         
    5871        DI.setVariable(self.variableName.CONTENT) 
    5972        #get fill value (if there is one)    
     
    7992    minIndex=minIdx 
    8093    maxIndex=maxIdx 
     94    if csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     95        directory=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
     96    else: 
     97        directory=None     
    8198    data=[] 
    8299    totalarraylength = 0     
     
    84101        DI=csml.csmllibs.csmldataiface.DataInterface() 
    85102        DI=DI.getUnknownInterfaceType(file)  
    86         DI.openFile(file) 
     103        try: 
     104            DI.openFile(file) 
     105        except: 
     106            if directory is not None: 
     107                file=directory +'/' + file 
     108                DI.openFile(file) 
    87109        DI.setVariable(self.variableName.CONTENT) 
    88110        datachunk=DI.getDataForVar()                    
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2567 r2569  
    127127    return pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs 
    128128     
    129 def subsetToGridSeries(self, outputdir, ncname='gridseries.nc',**kwargs): 
     129def subsetToGridSeries(self, outputdir=None, ncname='gridseries.nc',**kwargs): 
    130130    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    131     self.outputdir=outputdir 
     131    if outputdir is not None: 
     132        self.outputdir=outputdir 
     133    elif csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     134        self.outputdir=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
    132135    csml.csmllibs.csmlextra.checkDirExists(self.outputdir) 
    133136    self.ncname=ncname 
     
    187190    for a in axisorder: 
    188191        axislist.append(self.gridnames[a]) 
    189     nc.genWriteVar(self.id,ords, times, caltype, axislist, units, fulldata, fillvalue) 
     192    nc.genWriteVar(self.name.CONTENT,ords, times, caltype, axislist, units, fulldata, fillvalue) 
    190193    nc.closeFinishedFile() 
    191194    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
     
    193196     
    194197 
    195 def subsetToProfileSeries(self, outputdir, ncname='profileseries.nc',**kwargs): 
     198def subsetToProfileSeries(self, outputdir=None, ncname='profileseries.nc',**kwargs): 
    196199    #TODO   !!!!!!!!! Need to perform some sort of testing on the kwargs to check it is a profileseries request. 
    197     self.outputdir=outputdir 
     200    if outputdir is not None: 
     201        self.outputdir=outputdir 
     202    elif csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     203        self.outputdir=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
    198204    csml.csmllibs.csmlextra.checkDirExists(self.outputdir) 
    199205    self.ncname=ncname    
     
    241247    rangeSet=csml.parser.RangeSet() 
    242248    descid=csml.csmllibs.csmlextra.getRandomID() 
    243     descriptor=csml.parser.NetCDFExtract(id=descid,fileName=csml.parser.csString(ncname),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     249    descriptor=csml.parser.NetCDFExtract(id=descid,fileName=csml.parser.csString(ncname),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
    244250    rs=csml.parser.RangeSet() 
    245251    va=csml.parser.ValueArray() 
     
    287293    for a in axisorder: 
    288294        axislist.append(self.gridnames[a]) 
    289     nc.genWriteVar(self.id,ords, times, caltype, axislist, units, fulldata, fillvalue, latitude=kwargs[latName], longitude=kwargs[lonName]) 
     295 
     296    nc.genWriteVar(self.name.CONTENT,ords, times, caltype, axislist, units, fulldata, fillvalue, latitude=kwargs[latName], longitude=kwargs[lonName]) 
    290297    nc.closeFinishedFile() 
    291298     
    292299    return subsettedFeature, pathToSubsetNetCDF, descriptor 
    293300 
    294 def subsetToProfile(self, outputdir, ncname='profile.nc',**kwargs): 
     301def subsetToProfile(self, outputdir = None, ncname='profile.nc',**kwargs): 
    295302    #Two step process - subset GridSeries to ProfileSeries, then ProfileSeries to Profile 
    296303    profileSeries, pSfile=self.subsetToProfileSeries(outputdir, ncname, **kwargs)    
     
    300307    return subsettedFeature, pathToSubsetNetCDF 
    301308 
    302 def subsetToPointSeries(self, outputdir, ncname='pointseries.nc',**kwargs): 
     309def subsetToPointSeries(self, outputdir =None, ncname='pointseries.nc',**kwargs): 
    303310    #Two step process - subset GridSeries to ProfileSeries, then ProfileSeries to PointSeries 
    304311    profileSeries, pSfile=self.subsetToProfileSeries(outputdir, ncname, **kwargs)    
  • TI02-CSML/trunk/csml/API/ops_PointSeriesFeature.py

    r2567 r2569  
    3535 
    3636     
    37 def subsetToPointSeries(self, outputdir, ncname='pointseries.nc' ,times=None): 
    38     pathToSubsetNetCDF=outputdir + '/' +ncname 
    39     csml.csmllibs.csmlextra.checkDirExists(outputdir) 
     37def subsetToPointSeries(self, outputdir=None, ncname='pointseries.nc' ,times=None): 
     38    if outputdir is not None: 
     39        self.outputdir=outputdir 
     40    elif csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     41        self.outputdir=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
     42       
     43    if self.outputdir is not None: 
     44        pathToSubsetNetCDF=self.outputdir + '/' +ncname 
     45    else:  
     46        pathToSubsetNetCDF=ncname 
     47    if self.outputdir is not None: 
     48        csml.csmllibs.csmlextra.checkDirExists(self.outputdir) 
     49   
    4050    if type(times) is str: 
    4151        selection = tuple(csml.csmllibs.csmlextra.listify(times)) 
     
    155165     
    156166     
    157 def subsetToPoint(self, outputdir, ncname='point.nc',time=None): 
    158     pseriesFeature, pathToSubsetNetCDF, descriptor=self.subsetToPointSeries(outputdir, ncname,time)           
     167def subsetToPoint(self, outputdir=None, ncname='point.nc',time=None): 
     168    if outputdir is not None: 
     169        self.outputdir=outputdir 
     170    elif csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     171        self.outputdir=csml.API.csmlContainer.globalContainer.OUTPUTDIR  
     172    pseriesFeature, pathToSubsetNetCDF, descriptor=self.subsetToPointSeries(self.outputdir, ncname,time)           
    159173    #now need to take this point series feature containing one time and rewrite it as a point feature. 
    160174    pointFeature=csml.parser.PointFeature() 
  • TI02-CSML/trunk/csml/API/ops_ProfileSeriesFeature.py

    r2567 r2569  
    6969             
    7070             
    71 def subsetToProfile(self, outputdir,ncname,**kwargs): 
     71def subsetToProfile(self, outputdir=None,ncname ='profile.nc',**kwargs): 
    7272    #perform the subset  
    73     self.outputdir=outputdir 
     73    if outputdir is not None: 
     74        self.outputdir=outputdir 
     75    elif csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     76        self.outputdir=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
    7477    self.ncname=ncname 
    7578    pathToSubsetNetCDF, crs, timeName, times, strTimes,  caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(**kwargs)  
     
    107110    #rangeSet.arrayDescriptor=csml.parser.NetCDFExtract(id=self.id,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
    108111    descid=csml.csmllibs.csmlextra.getRandomID() 
    109     descriptor=csml.parser.NetCDFExtract(id=descid,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     112    descriptor=csml.parser.NetCDFExtract(id=descid,fileName=csml.parser.csString(ncname),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
    110113    rs=csml.parser.RangeSet() 
    111114    va=csml.parser.ValueArray() 
     
    165168    otherdims['latitude']=float(loc.CONTENT.split()[0]) 
    166169    otherdims['longitude']=float(loc.CONTENT.split()[1]) 
    167     nc.genWriteVar(descid,ords, times,  caltype, axislist, units, fulldata, fillvalue, **otherdims) 
     170    nc.genWriteVar(self.name.CONTENT,ords, times,  caltype, axislist, units, fulldata, fillvalue, **otherdims) 
    168171    nc.closeFinishedFile() 
    169172    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
    170173    return subsettedFeature, pathToSubsetNetCDF,descriptor 
    171174 
    172 def subsetToPointSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     175def subsetToPointSeries(self, outputdir=None,  ncname='pointseries.nc',**kwargs): 
     176    #this operation needs more testing. 
    173177    #perform the subset  
    174     pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs)  
     178    if outputdir is not None: 
     179        self.outputdir=outputdir 
     180    elif csml.API.csmlContainer.globalContainer.OUTPUTDIR is not None: 
     181        self.outputdir=csml.API.csmlContainer.globalContainer.OUTPUTDIR 
     182     
     183    pathToSubsetNetCDF, crs, timeName, times, strTimes, calunits, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(**kwargs)  
    175184     
    176185    (time, lat, lon)=(crs.axes[crs.timeAxis],crs.axes[crs.latAxis], crs.axes[crs.lonAxis]) 
     
    222231    otherdims['longitude']=float(loc.CONTENT.split()[1]) 
    223232     
    224      
    225     nc.genWriteVar(self.id,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue, **otherdims) 
     233    nc.genWriteVar(self.name.CONTENT,ords, times, calunits, caltype, axislist, units, fulldata, fillvalue, **otherdims) 
    226234    nc.closeFinishedFile() 
    227235    print 'NetCDF file written to %s'%pathToSubsetNetCDF 
  • TI02-CSML/trunk/csml/testfiles/gridseries/subset.py

    r2520 r2569  
    33import csml,sys 
    44 
    5 f='../gridseries/testout.xml' 
     5f='/home/dom/svn/trunk/csml/testfiles/gridseries/testout.xml' 
     6outputdir='GSout' 
    67 
    78#Initialise the CSML container 
    8 csmlContainer=csml.API.csmlContainer.Container(csmlpath='out.xml',docID="mycsmldoc_1", metadata="mymetadatastring") 
     9csmlContainer=csml.API.csmlContainer.Container(outputdir,  csmlname='out.xml',docID="mycsmldoc_1", metadata="mymetadatastring") 
    910 
    1011#Initialise and parse the dataset 
     
    4950#request subsetted data from features (can set paths here) and add to container 
    5051#subset a feature 
    51 csmlContainer.add(feature.subsetToGridSeries(ncpath='mygridseries.nc',**subsetDictionary)) 
     52csmlContainer.add(feature.subsetToGridSeries(outputdir,ncname='mygridseries.nc',**subsetDictionary)) 
    5253 
    5354#subset another feature (in fact it's the same feature again, but this time subsetting to a profileseries) 
     
    5960##assigning profileseries feature to variable 
    6061#print 'subset grid to profileseries' 
    61 psfeature, file, descriptor =feature.subsetToProfileSeries(ncpath='myprofileseries.nc',**subsetDictionary) 
     62psfeature, file, descriptor =feature.subsetToProfileSeries(outputdir, ncname='myprofileseries.nc',**subsetDictionary) 
    6263csmlContainer.add([psfeature,file, descriptor]) 
    6364 
     
    6667#subsetDictionary={} 
    6768#subsetDictionary['time']=('2794-12-1T0:0:0.0') 
    68 #csmlContainer.add(psfeature.subsetToProfile(ncpath='myprofile1.nc',**subsetDictionary)) 
     69#csmlContainer.add(psfeature.subsetToProfile(outputdir, ncname='myprofile1.nc',**subsetDictionary)) 
    6970 
    7071 
     
    7475#subsetDictionary['latitude']=(80) 
    7576#subsetDictionary['longitude']=(55) 
    76 #csmlContainer.add(feature.subsetToProfile(ncpath='myprofile.nc',**subsetDictionary)) 
     77#csmlContainer.add(feature.subsetToProfile(outputdir, ncname='myprofile.nc',**subsetDictionary)) 
    7778 
    7879#Now try the subset to PointSeries method of the grid series feature 
     
    8283#subsetDictionary['longitude']=(55) 
    8384##subsetDictionary['pressure']=(0)  #BROKEN 
    84 #csmlContainer.add(feature.subsetToPointSeries(ncpath='mypointseries.nc',**subsetDictionary)) 
     85#csmlContainer.add(feature.subsetToPointSeries(outputdir,ncname='mypointseries.nc',**subsetDictionary)) 
    8586 
    8687 
Note: See TracChangeset for help on using the changeset viewer.