Changeset 2567


Ignore:
Timestamp:
08/06/07 14:47:23 (12 years ago)
Author:
domlowe
Message:

Fixed problem with relative paths in CSML documents

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

Legend:

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

    r2387 r2567  
    44    '''CSMLContainer object is used to hold features before generating a CSML document. This is useful because it allows you to subset several features sequentially then build a single CSML document containing all the subsetted features ''' 
    55     
    6     def __init__(self,csmlpath='myfile.xml',docID='none',metadata='unspecified'): 
    7         self.csmlpath=csmlpath 
     6    def __init__(self,outputdir, csmlname='myfile.xml',docID='none',metadata='unspecified'): 
     7        self.outputdir =outputdir 
     8        self.csmlname=csmlname 
    89        ''' Initialise CSML Dataset and FeatureCollection and populate with basic Metadata''' 
    910        ''' 
     
    7071        strCSML=csml.parser_extra.PrettyPrint(csmlout) 
    7172        strCSML=csml.parser_extra.removeInlineNS(strCSML) 
    72         f=open(self.csmlpath,'w') 
     73        csml.csmllibs.csmlextra.checkDirExists(self.outputdir) 
     74        filepath=self.outputdir + '/' + self.csmlname 
     75        f=open(filepath,'w') 
    7376        f.write(strCSML) 
    7477        f.close() 
    75         self.containerContents.append(self.csmlpath) 
     78        self.containerContents.append(self.csmlname) 
    7679        for ncfile in self.ncfiles: 
    7780            self.containerContents.append(ncfile) 
  • TI02-CSML/trunk/csml/API/genSubset.py

    r2527 r2567  
    228228    return strTimes, axisorder, units, fulldata, fillvalue 
    229229 
    230 def genericSubset(feature, csmlpath, ncpath, domain, kwargs): 
    231     if ncpath is not None: 
    232         pathToSubsetNetCDF=ncpath 
    233     else: 
    234         pathToSubsetNetCDF='temp.nc' 
     230def genericSubset(feature, outputdir, ncname, domain, kwargs): 
     231    pathToSubsetNetCDF=outputdir+'/' +ncname 
    235232     
    236233    #deal with longitude requests 
  • TI02-CSML/trunk/csml/API/ops_GridSeriesFeature.py

    r2527 r2567  
    8787    return uom 
    8888 
    89 def _subsetGrid(self, csmlpath=None, ncpath=None,**kwargs): 
     89def _subsetGrid(self, **kwargs): 
    9090    '''this takes a selection from a gridseries object (be it a profile, a grid, whatever, it is still just a selection''' 
    9191            
     
    101101    #non-feature specific setup code, mainly handles the time dimension/calendar 
    102102     
    103     pathToSubsetNetCDF, kwargs, timeAxis, timeName, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 
     103    pathToSubsetNetCDF, kwargs, timeAxis, timeName, caltype, times=csml.API.genSubset.genericSubset(self, self.outputdir, self.ncname, self.domain, kwargs) 
    104104       
    105105    ##Get names of variables in file and relate them to the subset selection  
     
    127127    return pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs 
    128128     
    129 def subsetToGridSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     129def subsetToGridSeries(self, outputdir, ncname='gridseries.nc',**kwargs): 
    130130    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    131     pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
     131    self.outputdir=outputdir 
     132    csml.csmllibs.csmlextra.checkDirExists(self.outputdir) 
     133    self.ncname=ncname 
     134    pathToSubsetNetCDF, crs, frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(**kwargs)  
    132135    #Okay, got the data now. Need to write CSML feature and NetCDF files. 
    133136    #Writing out the CSML feature 
     
    150153    rs=csml.parser.RangeSet() 
    151154    sdid=csml.csmllibs.csmlextra.getRandomID() 
    152     descriptor=csml.parser.NetCDFExtract(id=sdid,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
     155    descriptor=csml.parser.NetCDFExtract(id=sdid,fileName=csml.parser.csString(self.ncname),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
    153156    rs=csml.parser.RangeSet() 
    154157    va=csml.parser.ValueArray() 
     
    190193     
    191194 
    192 def subsetToProfileSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     195def subsetToProfileSeries(self, outputdir, ncname='profileseries.nc',**kwargs): 
    193196    #TODO   !!!!!!!!! Need to perform some sort of testing on the kwargs to check it is a profileseries request. 
    194      
     197    self.outputdir=outputdir 
     198    csml.csmllibs.csmlextra.checkDirExists(self.outputdir) 
     199    self.ncname=ncname    
    195200     
    196201    #perform the subset (note this included nearest neighbour searching, so may return a different set of kwargs 
    197     pathToSubsetNetCDF, crs,frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(csmlpath, ncpath,**kwargs)  
     202    pathToSubsetNetCDF, crs,frame, timeName, times, strTimes, caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetGrid(**kwargs)  
    198203    latName=crs.axes[crs.latAxis] 
    199204    lonName=crs.axes[crs.lonAxis] 
     
    236241    rangeSet=csml.parser.RangeSet() 
    237242    descid=csml.csmllibs.csmlextra.getRandomID() 
    238     descriptor=csml.parser.NetCDFExtract(id=descid,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
     243    descriptor=csml.parser.NetCDFExtract(id=descid,fileName=csml.parser.csString(ncname),variableName=csml.parser.csString(self.id),arraySize=csml.parser.csString(totalArraySize)) 
    239244    rs=csml.parser.RangeSet() 
    240245    va=csml.parser.ValueArray() 
     
    287292    return subsettedFeature, pathToSubsetNetCDF, descriptor 
    288293 
    289 def subsetToProfile(self, csmlpath=None, ncpath=None,**kwargs): 
     294def subsetToProfile(self, outputdir, ncname='profile.nc',**kwargs): 
    290295    #Two step process - subset GridSeries to ProfileSeries, then ProfileSeries to Profile 
    291     profileSeries, pSfile=self.subsetToProfileSeries(csmlpath=csmlpath, ncpath=ncpath, **kwargs)    
     296    profileSeries, pSfile=self.subsetToProfileSeries(outputdir, ncname, **kwargs)    
    292297    del kwargs['latitude']    #TODO - need to remove excess kwargs based on the domain of the temporary profileSeries feature 
    293298    del kwargs['longitude'] 
    294     subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToProfile(csmlpath=csmlpath, ncpath=ncpath, **kwargs)     
     299    subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToProfile(ouputdir,ncname, **kwargs)     
    295300    return subsettedFeature, pathToSubsetNetCDF 
    296301 
    297 def subsetToPointSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     302def subsetToPointSeries(self, outputdir, ncname='pointseries.nc',**kwargs): 
    298303    #Two step process - subset GridSeries to ProfileSeries, then ProfileSeries to PointSeries 
    299     profileSeries, pSfile=self.subsetToProfileSeries(csmlpath=csmlpath, ncpath=ncpath, **kwargs)    
     304    profileSeries, pSfile=self.subsetToProfileSeries(outputdir, ncname, **kwargs)    
    300305    del kwargs['latitude']    #TODO - need to remove excess kwargs based on the domain of the temporary profileSeries feature 
    301306    del kwargs['longitude'] 
    302     subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToPointSeries(csmlpath=csmlpath, ncpath=ncpath, **kwargs)     
     307    subsettedFeature, pathToSubsetNetCDF=profileSeries.subsetToPointSeries(outputdir, ncname, **kwargs)     
    303308    return subsettedFeature, pathToSubsetNetCDF 
  • TI02-CSML/trunk/csml/API/ops_PointSeriesFeature.py

    r2565 r2567  
    3535 
    3636     
    37 def subsetToPointSeries(self, csmlpath=None, ncpath=None,times=None): 
    38     pathToSubsetNetCDF=ncpath 
     37def subsetToPointSeries(self, outputdir, ncname='pointseries.nc' ,times=None): 
     38    pathToSubsetNetCDF=outputdir + '/' +ncname 
     39    csml.csmllibs.csmlextra.checkDirExists(outputdir) 
    3940    if type(times) is str: 
    4041        selection = tuple(csml.csmllibs.csmlextra.listify(times)) 
     
    115116     
    116117    totalArraySize=10 
    117     descriptor=csml.parser.NetCDFExtract(id=sdid,fileName=csml.parser.csString(pathToSubsetNetCDF),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
     118    descriptor=csml.parser.NetCDFExtract(id=sdid,fileName=csml.parser.csString(ncname),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
    118119 
    119120     
     
    154155     
    155156     
    156 def subsetToPoint(self, csmlpath=None, ncpath=None,time=None): 
    157     pseriesFeature, pathToSubsetNetCDF, descriptor=self.subsetToPointSeries(csmlpath,ncpath,time) 
    158              
     157def subsetToPoint(self, outputdir, ncname='point.nc',time=None): 
     158    pseriesFeature, pathToSubsetNetCDF, descriptor=self.subsetToPointSeries(outputdir, ncname,time)           
    159159    #now need to take this point series feature containing one time and rewrite it as a point feature. 
    160160    pointFeature=csml.parser.PointFeature() 
  • TI02-CSML/trunk/csml/API/ops_ProfileSeriesFeature.py

    r2550 r2567  
    4040    return self.domain 
    4141 
    42 def _subsetProfileSeries(self, csmlpath=None, ncpath=None,**kwargs): 
     42def _subsetProfileSeries(self, **kwargs): 
    4343    '''this takes a temporal selection from a ProfileSeries object  - i.e. returns one or more 'profiles', can be used to make another ProfileSeriesFeature or a Profile feature in the case of a single selection''' 
    4444            
     
    5353     
    5454    #non-feature specific setup code, mainly handles the time dimension/calendar 
    55     pathToSubsetNetCDF, kwargs, timeAxis, timeName, caltype, times=csml.API.genSubset.genericSubset(self, csmlpath, ncpath, self.domain, kwargs) 
     55    pathToSubsetNetCDF, kwargs, timeAxis, timeName, caltype, times=csml.API.genSubset.genericSubset(self, self.outputdir,self.ncname, self.domain, kwargs) 
    5656       
    5757       
     
    6969             
    7070             
    71 def subsetToProfile(self, csmlpath=None, ncpath=None,**kwargs): 
     71def subsetToProfile(self, outputdir,ncname,**kwargs): 
    7272    #perform the subset  
    73     pathToSubsetNetCDF, crs, timeName, times, strTimes,  caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(csmlpath, ncpath,**kwargs)  
     73    self.outputdir=outputdir 
     74    self.ncname=ncname 
     75    pathToSubsetNetCDF, crs, timeName, times, strTimes,  caltype, axisorder,units, fulldata, fillvalue, kwargs=self._subsetProfileSeries(**kwargs)  
    7476     
    7577    try: 
  • TI02-CSML/trunk/csml/csmllibs/csmlextra.py

    r2409 r2567  
    33import string 
    44import csml.parser 
    5 import sys 
     5import os, sys 
    66 
    77def getRandomID(): 
     
    240240    return strreturn[:-1] 
    241241 
     242def checkDirExists(dirpath): 
     243    if os.path.isdir(dirpath) != True: 
     244        try: 
     245            os.mkdir(dirpath) 
     246        except: 
     247            pass 
     248              
     249 
     250 
    242251def main(): 
    243252    #test to check randomness of getRandomID() 
Note: See TracChangeset for help on using the changeset viewer.