Changeset 3296 for TI02-CSML


Ignore:
Timestamp:
04/02/08 12:19:28 (11 years ago)
Author:
domlowe
Message:

fixing example parser and point series subsetting of inline content

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

Legend:

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

    r3271 r3296  
    9191     
    9292     
    93     fileList=[] 
    94     if hasattr(self.value.rangeSet, 'valueArray'): 
    95         fextract=self.value.rangeSet.valueArray.valueComponent.insertedExtract.components 
    96         uom = self.value.rangeSet.valueArray.valueComponent.insertedExtract.uom 
     93    #fileList=[] 
     94         
     95    if self.value.rangeSet.quantityList.CONTENT: 
     96        #inline 
     97        data=self.value.rangeSet.quantityList.CONTENT.split()[minIndex:maxIndex+1] 
     98        fillvalue=None 
     99        units=self.value.rangeSet.quantityList.uom 
    97100    else: 
    98         fextract=self.value.rangeSet.arrayDescriptor.components 
    99         uom = self.value.rangeSet.arrayDescriptor.uom 
    100     for f in fextract.fileList.fileNames.CONTENT.split(): 
    101         fileList.append(f) 
    102      
    103     data, fillvalue=fextract.getDataFromChunks(minIndex, maxIndex) 
    104      
    105     units=[uom.CONTENT] 
     101        #file extract 
     102        if hasattr(self.value.rangeSet, 'valueArray'): 
     103            fextract=self.value.rangeSet.valueArray.valueComponent.insertedExtract.components 
     104            uom = self.value.rangeSet.valueArray.valueComponent.insertedExtract.uom 
     105        else: 
     106            fextract=self.value.rangeSet.arrayDescriptor.components 
     107            uom = self.value.rangeSet.arrayDescriptor.uom 
     108        #for f in fextract.fileList.fileNames.CONTENT.split(): 
     109            #fileList.append(f) 
     110         
     111        data, fillvalue=fextract.getDataFromChunks(minIndex, maxIndex) 
     112         
     113        units=[uom.CONTENT] 
    106114    
    107115    #Now write out the CSML Feature: 
     
    139147     
    140148    totalArraySize=10 
    141     descriptor=csml.parser.NetCDFExtract(id=sdid,fileName=csml.parser.csString(ncname),variableName=self.name,arraySize=csml.parser.csString(totalArraySize)) 
    142  
    143      
     149    if hasattr(self, 'name'): 
     150        varname=self.name 
     151    else: 
     152        varname=self.id 
     153    descriptor=csml.parser.NetCDFExtract(id=sdid,fileName=csml.parser.csString(ncname),variableName=csml.parser.csString(varname),arraySize=csml.parser.csString(totalArraySize)) 
     154 
    144155    #the parameter of the feature is of type Phenomenon, here href creates "xlink:href=..." 
    145156    param=self.parameter 
     
    149160    csmlWrap=csml.csmllibs.csmlfeaturewrap.CSMLWrapper() 
    150161    subsettedFeature=csmlWrap.createPointSeriesFeature(value=cvg,parameter=param,location=self.location,featureID=self.id,description=self.description) 
    151      
    152162       
    153163     
     
    155165    nc=cdms.open(pathToSubsetNetCDF,'w') 
    156166    var=MV.array(data) 
    157     var.id=self.name.CONTENT 
    158     var.name=self.name.CONTENT 
     167    var.id=varname 
     168    var.name=varname 
    159169    var.units=units[0] # hopefully there is just one unit in this list.. 
    160170    setattr(var, 'missing_value' ,fillvalue) 
  • TI02-CSML/trunk/csml/Examples/Parsing/apicalls.py

    r2049 r3296  
    33import csml 
    44 
    5 f='Examples/parsing/test.xml' 
     5f='example.xml' 
     6outputdir = 'out' 
    67 
    78#Initialise the CSML container 
    8 csmlContainer=csml.API.csmlContainer.Container(csmlpath='myfile.xml',docID="mycsmldoc_1", metadata="mymetadatastring") 
     9csmlContainer=csml.API.csmlContainer.Container(outputdir,csmlname='myfile.xml',docID="mycsmldoc_1", metadata="mymetadatastring") 
    910 
    1011#Initialise and parse the dataset 
    11 csmldoc = csml.parser.Dataset() 
    12 csmldoc.parse(f) 
     12csmldoc = csml.parser.Dataset(file=f) 
    1313 
    1414 
     
    1919 
    2020#select a feature by name (gml:id) 
    21 print '\n Selecting feature with gml:id = %s' %flist[4] 
    22 feature=csmldoc.getFeature(flist[4]) 
     21print '\n Selecting feature with gml:id = %s' %flist[0] 
     22feature=csmldoc.getFeature(flist[0]) 
    2323 
    2424f#eature 'bestname' 
     
    2727 
    2828#get the domain of the feature 
    29 print '\n The feature has domain reference:'  
    30 print feature.getDomainReference() 
    31  
    32 #get the domain complement of the feature 
    33 print '\n The feature has domain complement :'  
    34 print feature.getDomainComplement() 
    35  
    36 #get combined domain 
    37 print '\n The feature has domain:'  
    38 #print feature.getDomain() 
     29print '\n The feature has domain: ' 
     30print feature.getDomain() 
    3931 
    4032#get list of allowed subsettings 
     
    4335 
    4436 
    45 #define a selection (based on the domain ref/complement) 
    46 #timeSelection=['2881-3-16T0:0:0.0', '2881-4-16T0:0:0.0', '2881-5-16T0:0:0.0', '2881-6-16T0:0:0.0', '2881-7-16T0:0:0.0', '2881-8-16T0:0:0.0', '2881-9-16T0:0:0.0'] 
    47 timeSelection=['2794-12-1T0:0:0.0', '2844-12-1T0:0:0.0'] 
    48  
    49 spatialSubsetDictionary= {} 
    50 spatialSubsetDictionary['latitude']=(-90,90) 
    51 #spatialSubsetDictionary['longitude']=(330,359) 
    52 spatialSubsetDictionary['longitude']=(-31.265,30.258) 
     37#define a selection (based on the domain) 
     38timeSelection=['2007-08-12T10:45:00', '2007-08-12T11:45:00'] 
    5339 
    5440#request subsetted data from features (can set paths here) and add to container 
    5541#subset a feature 
    56 csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile.nc',**spatialSubsetDictionary)) 
    57 #subset another feature (in fact it's the same feature again, but it proves the concept) 
    58 csmlContainer.add(feature.subsetToGridSeries(timeSelection,  ncpath='myfile2.nc',**spatialSubsetDictionary)) 
     42csmlContainer.add(feature.subsetToPointSeries(times=timeSelection,  ncname='myfile.nc')) 
    5943 
    6044#when you have finished, get the contents of the container 
  • TI02-CSML/trunk/csml/Examples/Parsing/basictest.py

    r3295 r3296  
    22""" 
    33 
    4 import csml 
     4c 
    55 
    66#Name of test file 
  • TI02-CSML/trunk/csml/Examples/Parsing/demoCreateV2.py

    r2400 r3296  
    2121#note, as description is an xml element not an attribute it is of type csString: 
    2222ptsf.description=csml.parser.csString('Station BLUEBIRD') 
     23 
     24ptsf.location=csml.parser.csString('-50.5, 40.3') 
    2325 
    2426#create a PointSeriesCoverage 
  • TI02-CSML/trunk/csml/Examples/Parsing/example.xml

    r3294 r3296  
    1 <Dataset xmlns="http://ndg.nerc.ac.uk/csml"  xmlns:gml="http://www.opengis.net/gml" xmlns:om="http://www.opengis.net/om" xmlns:swe="http://www.opengis.net/swe"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:moles="http://ndg.nerc.ac.uk/moles"  xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://ndg.nerc.ac.uk/csml  csmlDataset.xsd" id="Test001"> 
    2    <CSMLFeatureCollection gml:id="MalAYQjN"> 
    3       <featureMember> 
    4          <PointSeriesFeature gml:id="pointseriesf"> 
    5             <gml:description>Station BLUEBIRD</gml:description> 
    6             <value> 
    7                <PointSeriesCoverage gml:id="SlGLraY4"> 
    8                   <pointSeriesDomain> 
    9                      <TimeSeries gml:id="ShSL846w"> 
    10                         <timePositionList frame="#pred20060427001">-18 -17 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60</timePositionList> 
    11                      </TimeSeries> 
    12                   </pointSeriesDomain> 
    13                   <gml:rangeSet> 
    14                      <gml:QuantityList uom="MLUnits.xml#m">0.27 0.25 0.25 0.23 0.22 0.22 0.21 0.17 0.17 0.14 0.14 0.12 0.10 0.08 0.08 0.08 0.11 0.13 0.11 0.11 0.13 0.10 0.06 0.06 0.06 0.01 -0.03 -0.06 -0.09 -0.11 -0.11 -0.13 -0.16 -0.18 -0.17 -0.16 -0.18 -0.16 -0.12 -0.09 -0.08 -0.07 -0.06 -0.05 -0.04 -0.03 -0.03 -0.04 -0.02 -0.01 -0.02 -0.02 -0.02 -0.03 -0.03 -0.02 -0.01 -0.01 -0.02 -0.02 -0.03 -0.04 -0.04 -0.05 -0.04 -0.05 -0.08 -0.09 -0.11 -0.12 -0.12 -0.12 -0.12 -0.12 -0.13 -0.14 -0.15</gml:QuantityList> 
    15                   </gml:rangeSet> 
    16                </PointSeriesCoverage> 
    17             </value> 
    18             <parameter xlink:href="CFStandardNames.xml#temperature"></parameter> 
    19          </PointSeriesFeature> 
    20       </featureMember> 
    21       <featureMember> 
    22          <ProfileFeature gml:id="profilef"> 
    23             <gml:description>sample profile feature</gml:description> 
    24             <location>75 35</location> 
    25             <time>2003-02-02T00:00:00.0</time> 
    26             <value> 
    27                <ProfileCoverage gml:id="RvN8UkmD"> 
    28                   <profileDomain> 
    29                      <ProfileDomain gml:id="MNEdwTeX"> 
    30                         <gml:pointMembers>1000, 950, 850, 700, 600, 500, 400, 300, 250, 200, 150, 100, 50, 30, 10</gml:pointMembers> 
    31                      </ProfileDomain> 
    32                   </profileDomain> 
    33                   <gml:rangeSet> 
    34                      <gml:QuantityList uom="MLUnits.xml#m">0.27 0.25 0.25 0.23 0.22 0.22 0.21 0.17 0.17 0.14 0.14 0.12 0.10 0.08 0.08</gml:QuantityList> 
    35                   </gml:rangeSet> 
    36                </ProfileCoverage> 
    37             </value> 
    38             <parameter xlink:href="CFStandardNames.xml#temperature"></parameter> 
    39          </ProfileFeature> 
    40       </featureMember> 
    41    </CSMLFeatureCollection> 
    42    <CSMLStorageDescriptor></CSMLStorageDescriptor> 
     1<Dataset xmlns="http://ndg.nerc.ac.uk/csml"  xmlns:gml="http://www.opengis.net/gml" xmlns:om="http://www.opengis.net/om" xmlns:swe="http://www.opengis.net/swe"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:moles="http://ndg.nerc.ac.uk/moles"  xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://ndg.nerc.ac.uk/csml  csmlDataset.xsd" id="mycsmldoc_2"> 
     2<name>tidal dataset</name> 
     3    <CSMLFeatureCollection gml:id="abc12345"> 
     4        <featureMember> 
     5            <PointSeriesFeature gml:id="TWL1"> 
     6                <gml:description>Sheerness Tidal Water Level</gml:description> 
     7                <location srsName="urn:EPSG:geographicCRS:4326">0.8 51.4</location> 
     8                <value> 
     9                        <PointSeriesCoverage gml:id="TWL1.cov"> 
     10                                <pointSeriesDomain> 
     11                                        <TimeSeries gml:id="TWL1.cov.times"> 
     12                                                <timePositionList>2007-08-12T10:15:00 2007-08-12T10:30:00 2007-08-12T10:45:00 2007-08-12T11:00:00 2007-08-12T11:15:00 2007-08-12T11:30:00 2007-08-12T11:45:00 2007-08-12T12:00:00 2007-08-12T12:15:00 2007-08-12T12:30:00 2007-08-12T12:45:00 2007-08-12T13:00:00 2007-08-12T13:15:00 2007-08-12T13:30:00 2007-08-12T13:45:00 2007-08-12T14:00:00 2007-08-12T14:15:00 2007-08-12T14:30:00 2007-08-12T14:45:00 2007-08-12T15:00:00 2007-08-12T15:15:00 2007-08-12T15:30:00 2007-08-12T15:45:00 2007-08-12T16:00:00 2007-08-12T16:15:00 2007-08-12T16:30:00 2007-08-12T16:45:00 2007-08-12T17:00:00 2007-08-12T17:15:00 2007-08-12T17:30:00 2007-08-12T17:45:00 2007-08-12T18:00:00 2007-08-12T18:15:00 2007-08-12T18:30:00 2007-08-12T18:45:00 2007-08-12T19:00:00 2007-08-12T19:15:00 2007-08-12T19:30:00 2007-08-12T20:00:00 2007-08-12T20:15:00 2007-08-12T20:30:00 2007-08-12T20:45:00 2007-08-12T21:00:00 2007-08-12T21:15:00 2007-08-12T21:30:00 2007-08-12T21:45:00 2007-08-12T22:00:00 2007-08-12T22:15:00 2007-08-12T22:30:00 2007-08-12T22:45:00 2007-08-12T23:00:00 2007-08-12T23:15:00 2007-08-12T23:30:00 2007-08-12T23:45:00</timePositionList> 
     13                                        </TimeSeries> 
     14                                </pointSeriesDomain> 
     15                                <gml:rangeSet> 
     16                                        <gml:QuantityList uom="m">4.104 4.512 4.722 4.926 5.211 5.27 5.396 5.576 5.504 5.469 5.364 5.2 4.99 4.74 4.46 4.173 3.886 3.575 3.287 2.991 2.703 2.428 2.164 1.912 1.692 1.502 1.343 1.205 1.082 0.974 0.878 0.789 0.816 0.659 0.631 0.64 0.698 0.808 1.169 1.413 1.682 1.968 2.248 2.51 2.763 3.025 3.297 3.579 3.859 4.142 4.432 4.703 4.97 5.213</gml:QuantityList> 
     17                                </gml:rangeSet> 
     18                        </PointSeriesCoverage> 
     19                </value> 
     20                <parameter> 
     21                        <swe:Phenomenon gml:id="WaterLevel"> 
     22                                <gml:identifier codeSpace="http://www.motiive.net">WaterLevel</gml:identifier> 
     23                        </swe:Phenomenon> 
     24                </parameter> 
     25            </PointSeriesFeature> 
     26        </featureMember> 
     27        <featureMember> 
     28            <PointSeriesFeature gml:id="TWL2"> 
     29                <gml:description>Sheerness Temperature</gml:description> 
     30                <location srsName="urn:EPSG:geographicCRS:4326">0.8 51.4</location> 
     31                <value> 
     32                    <PointSeriesCoverage gml:id="TWL2.cov"> 
     33                        <pointSeriesDomain> 
     34                            <TimeSeries gml:id="TWL2.cov.times"> 
     35                                <timePositionList>2007-08-12T10:15:00 2007-08-12T10:30:00 2007-08-12T10:45:00 2007-08-12T11:00:00 2007-08-12T11:15:00 2007-08-12T11:30:00 2007-08-12T11:45:00 2007-08-12T12:00:00 2007-08-12T12:15:00 2007-08-12T12:30:00 2007-08-12T12:45:00 2007-08-12T13:00:00 2007-08-12T13:15:00 2007-08-12T13:30:00 2007-08-12T13:45:00 2007-08-12T14:00:00 2007-08-12T14:15:00 2007-08-12T14:30:00 2007-08-12T14:45:00 2007-08-12T15:00:00 2007-08-12T15:15:00 2007-08-12T15:30:00 2007-08-12T15:45:00 2007-08-12T16:00:00 2007-08-12T16:15:00 2007-08-12T16:30:00 2007-08-12T16:45:00 2007-08-12T17:00:00 2007-08-12T17:15:00 2007-08-12T17:30:00 2007-08-12T17:45:00 2007-08-12T18:00:00 2007-08-12T18:15:00 2007-08-12T18:30:00 2007-08-12T18:45:00 2007-08-12T19:00:00 2007-08-12T19:15:00 2007-08-12T19:30:00 2007-08-12T20:00:00 2007-08-12T20:15:00 2007-08-12T20:30:00 2007-08-12T20:45:00 2007-08-12T21:00:00 2007-08-12T21:15:00 2007-08-12T21:30:00 2007-08-12T21:45:00 2007-08-12T22:00:00 2007-08-12T22:15:00 2007-08-12T22:30:00 2007-08-12T22:45:00 2007-08-12T23:00:00 2007-08-12T23:15:00 2007-08-12T23:30:00 2007-08-12T23:45:00</timePositionList> 
     36                            </TimeSeries> 
     37                        </pointSeriesDomain> 
     38                        <gml:rangeSet> 
     39                            <gml:QuantityList uom="c">24.304 24.512 24.322 24.926 25.111 25.27 25.396 25.476 15.504 15.469 15.364 15.2 24.99 24.74 24.46 24.173 23.886 23.575 23.287 22.991 22.703 22.428 12.164 11.912 11.692 12.502 21.343 21.205 21.082 12.974 20.878 20.789 20.716 10.859 20.631 20.64 20.698 20.808 21.169 21.413 21.682 21.968 22.248 22.51 22.763 23.025 23.297 23.579 23.859 24.142 24.432 24.703 24.97 15.213</gml:QuantityList> 
     40                        </gml:rangeSet> 
     41                    </PointSeriesCoverage> 
     42                </value> 
     43                <parameter> 
     44                    <swe:Phenomenon gml:id="WaterLevel"> 
     45                        <gml:identifier codeSpace="http://www.motiive.net">Temperature</gml:identifier> 
     46                    </swe:Phenomenon> 
     47                </parameter> 
     48            </PointSeriesFeature> 
     49        </featureMember> 
     50        <featureMember> 
     51            <PointSeriesFeature gml:id="TWL3"> 
     52                <gml:description>Sheerness Precipitation</gml:description> 
     53                <location srsName="urn:EPSG:geographicCRS:4326">0.8 51.4</location> 
     54                <value> 
     55                    <PointSeriesCoverage gml:id="TWL3.cov"> 
     56                        <pointSeriesDomain> 
     57                            <TimeSeries gml:id="TWL3.cov.times"> 
     58                                <timePositionList>2007-08-12T10:15:00 2007-08-12T10:30:00 2007-08-12T10:45:00 2007-08-12T11:00:00 2007-08-12T11:15:00 2007-08-12T11:30:00 2007-08-12T11:45:00 2007-08-12T12:00:00 2007-08-12T12:15:00 2007-08-12T12:30:00 2007-08-12T12:45:00 2007-08-12T13:00:00 2007-08-12T13:15:00 2007-08-12T13:30:00 2007-08-12T13:45:00 2007-08-12T14:00:00 2007-08-12T14:15:00 2007-08-12T14:30:00 2007-08-12T14:45:00 2007-08-12T15:00:00 2007-08-12T15:15:00 2007-08-12T15:30:00 2007-08-12T15:45:00 2007-08-12T16:00:00 2007-08-12T16:15:00 2007-08-12T16:30:00 2007-08-12T16:45:00 2007-08-12T17:00:00 2007-08-12T17:15:00 2007-08-12T17:30:00 2007-08-12T17:45:00 2007-08-12T18:00:00 2007-08-12T18:15:00 2007-08-12T18:30:00 2007-08-12T18:45:00 2007-08-12T19:00:00 2007-08-12T19:15:00 2007-08-12T19:30:00 2007-08-12T20:00:00 2007-08-12T20:15:00 2007-08-12T20:30:00 2007-08-12T20:45:00 2007-08-12T21:00:00 2007-08-12T21:15:00 2007-08-12T21:30:00 2007-08-12T21:45:00 2007-08-12T22:00:00 2007-08-12T22:15:00 2007-08-12T22:30:00 2007-08-12T22:45:00 2007-08-12T23:00:00 2007-08-12T23:15:00 2007-08-12T23:30:00 2007-08-12T23:45:00</timePositionList> 
     59                            </TimeSeries> 
     60                        </pointSeriesDomain> 
     61                        <gml:rangeSet> 
     62                            <gml:QuantityList uom="mm">14.304 4.512 4.822 4.926 15.111 5.27 5.396 5.476 25.504 5.469 5.364 5.2 4.99 14.74 4.46 4.173 3.886 3.575 3.287 2.991 2.703 2.428 2.164 21.912 21.692 31.502 1.343 11.205 1.082 0.974 0.978 20.789 10.716 10.659 10.631 0.64 10.698 0.808 1.169 11.413 1.682 1.968 2.248 2.51 2.763 3.025 3.297 3.579 23.859 4.142 14.432 34.703 4.97 5.213</gml:QuantityList> 
     63                        </gml:rangeSet> 
     64                    </PointSeriesCoverage> 
     65                </value> 
     66                <parameter> 
     67                    <swe:Phenomenon gml:id="WaterLevel"> 
     68                        <gml:identifier codeSpace="http://www.motiive.net">Precipitation</gml:identifier> 
     69                    </swe:Phenomenon> 
     70                </parameter> 
     71            </PointSeriesFeature> 
     72        </featureMember> 
     73    </CSMLFeatureCollection> 
     74    <CSMLStorageDescriptor></CSMLStorageDescriptor>s 
    4375</Dataset> 
     76 
  • TI02-CSML/trunk/csml/testfiles/gridseries/subset.py

    r3288 r3296  
    2727feature=csmldoc.getFeature(flist[4]) 
    2828 
    29 #feature 'bestname' 
     29#get  'gml:id' xml attribute 
    3030print feature.id 
     31 
     32#get the contents of the feature <description> element 
    3133print feature.description.CONTENT 
    3234 
    3335#get the domain of the feature 
    34  
    3536print '\n The feature has domain:'  
    3637print feature.getDomain() 
Note: See TracChangeset for help on using the changeset viewer.