Changeset 927
- Timestamp:
- 02/26/12 23:30:01 (15 months ago)
- Location:
- MGET/Branches/Jason/PythonPackage/src/GeoEco
- Files:
-
- 11 modified
-
DataProducts/Aviso.py (modified) (2 diffs)
-
DataProducts/HYCOM.py (modified) (5 diffs)
-
DataProducts/NASA/OceanColor.py (modified) (2 diffs)
-
DataProducts/NASA/PODAAC.py (modified) (4 diffs)
-
DataProducts/NOAA/NODC.py (modified) (3 diffs)
-
DataProducts/NOAA/OSCAR.py (modified) (2 diffs)
-
DataProducts/UMaineOMG.py (modified) (6 diffs)
-
Datasets/ArcGIS.py (modified) (6 diffs)
-
Datasets/Collections.py (modified) (2 diffs)
-
Datasets/Virtual.py (modified) (1 diff)
-
Logging.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/Aviso.py
r925 r927 280 280 281 281 @classmethod 282 def _Get OtherTimeCoordinates(cls, queryableAttributeValues):282 def _GetTimeCoordsFromQueryableAttributeValues(cls, queryableAttributeValues): 283 283 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime) or u'TemporalResolution' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'TemporalResolution'], basestring) or queryableAttributeValues[u'TemporalResolution'].lower() not in [u'daily', u'weekly']: 284 return [None, None ]284 return [None, None, None] 285 285 dateTime = queryableAttributeValues[u'DateTime'] 286 286 if queryableAttributeValues[u'TemporalResolution'].lower() == u'daily': 287 return [dateTime - datetime.timedelta(0.5), dateTime + datetime.timedelta(0.5)]288 return [dateTime - datetime.timedelta(3.5), dateTime + datetime.timedelta(3.5)]287 return [dateTime - datetime.timedelta(0.5), dateTime, dateTime + datetime.timedelta(0.5) - datetime.timedelta(seconds=1)] 288 return [dateTime - datetime.timedelta(3.5), dateTime, dateTime + datetime.timedelta(3.5) - datetime.timedelta(seconds=1)] 289 289 290 290 @classmethod … … 297 297 workspace.ImportDatasets(GridSliceCollection(grid, tQACoordType=u'center').QueryDatasets(), mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 298 298 if rasterCatalog is not None: 299 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=cls._Get OtherTimeCoordinates, overwriteExisting=True)299 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=cls._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 300 300 finally: 301 301 grid.Close() -
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/HYCOM.py
r925 r927 268 268 workspace.ImportDatasets(GridSliceCollection(grid, tQACoordType=u'center').QueryDatasets(), mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 269 269 if rasterCatalog is not None: 270 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'] + datetime.timedelta(0.5)], overwriteExisting=True)270 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'], qav[u'DateTime'] + datetime.timedelta(0.5) - datetime.timedelta(seconds=1)], overwriteExisting=True) 271 271 finally: 272 272 grid.Close() … … 662 662 workspace.ImportDatasets(grids, mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 663 663 if rasterCatalog is not None: 664 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'] + datetime.timedelta(0.5)], overwriteExisting=True)664 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'], qav[u'DateTime'] + datetime.timedelta(0.5) - datetime.timedelta(seconds=1)], overwriteExisting=True) 665 665 666 666 finally: … … 1307 1307 if j < len(gridTCoords) and gridTCoords[j] == tCoords[i]: 1308 1308 if datasetIs4D: 1309 for k in range( sliceList[1].start, sliceList[1].stop):1309 for k in range(0, sliceList[1].stop - sliceList[1].start): 1310 1310 result[i, k, ySliceToWrite, xSliceToWrite] = numpy.take(data[i, k], indicesToTake) 1311 1311 else: … … 1398 1398 workspace.ImportDatasets(GridSliceCollection(grid, tQACoordType=u'center').QueryDatasets(), mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 1399 1399 if rasterCatalog is not None: 1400 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'] + datetime.timedelta(0.5)], overwriteExisting=True)1400 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'], qav[u'DateTime'] + datetime.timedelta(0.5) - datetime.timedelta(seconds=1)], overwriteExisting=True) 1401 1401 finally: 1402 1402 grid.Close() … … 1694 1694 workspace.ImportDatasets(grids, mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 1695 1695 if rasterCatalog is not None: 1696 workspace.ToRasterCatalog(rasterCatalog, grid .GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'] + datetime.timedelta(0.5)], overwriteExisting=True)1696 workspace.ToRasterCatalog(rasterCatalog, grids[0].GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=lambda qav: [qav[u'DateTime'] - datetime.timedelta(0.5), qav[u'DateTime'], qav[u'DateTime'] + datetime.timedelta(0.5) - datetime.timedelta(seconds=1)], overwriteExisting=True) 1697 1697 1698 1698 finally: -
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/NASA/OceanColor.py
r925 r927 363 363 return None 364 364 365 queryableAttributeValues['TemporalResolutionCode'] = components[ 0].upper()365 queryableAttributeValues['TemporalResolutionCode'] = components[1].upper() 366 366 367 367 if components[-1].lower() not in ['4', '9', '4km', '9km']: … … 506 506 return self._DisplayName 507 507 508 def _GetOtherTimeCoordinates(self, queryableAttributeValues): 509 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 510 return [None, None] 508 @classmethod 509 def _GetTimeCoordsFromQueryableAttributeValues(cls, queryableAttributeValues): 511 510 try: 512 i = self.MinCoords['t', :].index(queryableAttributeValues[u'DateTime']) 511 if u'DateTime' in queryableAttributeValues and isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 512 startDate = queryableAttributeValues[u'DateTime'] 513 temporalResolution = None 514 515 if u'TemporalResolution' in queryableAttributeValues and isinstance(queryableAttributeValues[u'TemporalResolution'], basestring) and queryableAttributeValues[u'TemporalResolution'] in [u'daily', '8day', 'monthly', 'annual']: 516 temporalResolution = queryableAttributeValues[u'TemporalResolution'] 517 elif u'TemporalResolutionCode' in queryableAttributeValues and isinstance(queryableAttributeValues[u'TemporalResolutionCode'], basestring) and queryableAttributeValues[u'TemporalResolutionCode'] in [u'DAY', '8D', 'MO', 'YR']: 518 temporalResolution = queryableAttributeValues[u'TemporalResolutionCode'] 519 else: 520 return [startDate, None, None] 521 522 if temporalResolution in [u'daily', u'DAY']: 523 return [startDate, startDate + datetime.timedelta(0.5), startDate + datetime.timedelta(1) - datetime.timedelta(seconds=1)] 524 525 if temporalResolution in [u'8day', u'8D']: 526 if startDate.month == 12 and startDate.day >= 24: 527 endDate = datetime.datetime(startDate.year + 1, 1, 1) 528 return [startDate, startDate + (endDate - startDate) / 2, endDate - datetime.timedelta(seconds=1)] 529 else: 530 return [startDate, startDate + datetime.timedelta(4), startDate + datetime.timedelta(8) - datetime.timedelta(seconds=1)] 531 532 if temporalResolution in [u'monthly', u'MO']: 533 if startDate.month == 12: 534 endDate = datetime.datetime(startDate.year + 1, 1, 1) 535 else: 536 endDate = datetime.datetime(startDate.year, startDate.month + 1, 1) 537 return [startDate, startDate + (endDate - startDate) / 2, endDate - datetime.timedelta(seconds=1)] 538 539 if temporalResolution in [u'annual', u'YR']: 540 return [startDate, datetime.datetime(startDate.year, 7, 1), datetime.datetime(startDate.year + 1, 1, 1) - datetime.timedelta(seconds=1)] 541 542 return [None, None, None] 513 543 except: 514 return [None, None] 515 return [self.CenterCoords['t', i], self.MaxCoords['t', i]] 544 return [None, None, None] 516 545 517 546 @classmethod 518 547 def CreateArcGISRasters(cls, sensor, temporalResolution, spatialResolution, product, 519 outputWorkspace, mode=u'add', rasterNameExpressions=[u'%(Sensor)s', u'%(TemporalResolution)s', u'%(SpatialResolution)s', u'%(ProductCode)s', u'%%Y', u'%(SensorCode) s%%Y%%j%(EndDate)s.L3m_%(TemporalResolutionCode)s_%(ProductCode)s_%(SpatialResolution)s.img'], rasterCatalog=None, cacheDirectory=None,548 outputWorkspace, mode=u'add', rasterNameExpressions=[u'%(Sensor)s', u'%(TemporalResolution)s', u'%(SpatialResolution)s', u'%(ProductCode)s', u'%%Y', u'%(SensorCode).1s%%Y%%j%(EndDate)s.L3m_%(TemporalResolutionCode).3s_%(ProductCode)s_%(SpatialResolution)s.img'], rasterCatalog=None, cacheDirectory=None, 520 549 rotationOffset=None, spatialExtent=None, startDate=None, endDate=None, 521 550 timeout=60, maxRetryTime=300, 522 551 calculateStatistics=True, buildPyramids=False): 523 552 cls.__doc__.Obj.ValidateMethodInvocation() 524 fullGrid = cls(sensor, temporalResolution, spatialResolution, product, timeout, maxRetryTime, cacheDirectory)553 grid = cls(sensor, temporalResolution, spatialResolution, product, timeout, maxRetryTime, cacheDirectory) 525 554 try: 526 555 from GeoEco.Datasets.ArcGIS import ArcGISWorkspace, ArcGISRaster 527 grid = cls._RotateAndClip( fullGrid, rotationOffset, spatialExtent, startDate, endDate)556 grid = cls._RotateAndClip(grid, rotationOffset, spatialExtent, startDate, endDate) 528 557 workspace = ArcGISWorkspace(outputWorkspace, ArcGISRaster, pathCreationExpressions=rasterNameExpressions, cacheTree=True, queryableAttributes=tuple(grid.GetAllQueryableAttributes() + [QueryableAttribute(u'DateTime', _(u'Date'), DateTimeTypeMetadata())])) 529 558 workspace.ImportDatasets(GridSliceCollection(grid).QueryDatasets(), mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 530 559 if rasterCatalog is not None: 531 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'min', tCoordFunction= fullGrid._GetOtherTimeCoordinates, overwriteExisting=True)560 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'min', tCoordFunction=cls._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 532 561 finally: 533 fullGrid.Close()562 grid.Close() 534 563 return outputWorkspace 535 564 -
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/NASA/PODAAC.py
r925 r927 104 104 105 105 def __getattribute__(self, name): 106 if name.startswith('__') or name in ['_WrappedGrid', '_Get OtherTimeCoordinates', '_GetQueryableAttributesForTimeSlices', '_GetLazyPropertyValuesForTimeSlices', 'CreateArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']:106 if name.startswith('__') or name in ['_WrappedGrid', '_GetTimeCoordsFromQueryableAttributeValues', '_GetQueryableAttributesForTimeSlices', '_GetLazyPropertyValuesForTimeSlices', 'CreateArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']: 107 107 return object.__getattribute__(self, name) 108 108 return object.__getattribute__(object.__getattribute__(self, '_WrappedGrid'), name) 109 109 110 110 def __setattr__(self, name, value): 111 if name.startswith('__') or name in ['_WrappedGrid', '_Get OtherTimeCoordinates', '_GetQueryableAttributesForTimeSlices', '_GetLazyPropertyValuesForTimeSlices', 'CreateArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']:111 if name.startswith('__') or name in ['_WrappedGrid', '_GetTimeCoordsFromQueryableAttributeValues', '_GetQueryableAttributesForTimeSlices', '_GetLazyPropertyValuesForTimeSlices', 'CreateArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']: 112 112 object.__setattr__(self, name, value) 113 113 else: 114 114 setattr(object.__getattribute__(self, '_WrappedGrid'), name, value) 115 116 def _GetOtherTimeCoordinates(self, queryableAttributeValues):117 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime):118 return [None, None]119 try:120 i = self.MinCoords['t', :].index(queryableAttributeValues[u'DateTime'])121 except:122 return [None, None]123 return [self.CenterCoords['t', i], self.MaxCoords['t', i]]124 115 125 116 @classmethod … … 205 196 206 197 @classmethod 198 def _GetTimeCoordsFromQueryableAttributeValues(cls, queryableAttributeValues): 199 try: 200 if u'DateTime' in queryableAttributeValues and isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 201 startDate = queryableAttributeValues[u'DateTime'] 202 temporalResolution = None 203 204 if u'GeophysicalParameter' in queryableAttributeValues and isinstance(queryableAttributeValues[u'GeophysicalParameter'], basestring) and queryableAttributeValues[u'GeophysicalParameter'].lower() in [u'nsst', u'sst4']: 205 tOffset = datetime.timedelta(-0.5) 206 else: 207 tOffset = datetime.timedelta(0) 208 209 if u'TemporalResolution' in queryableAttributeValues and isinstance(queryableAttributeValues[u'TemporalResolution'], basestring) and queryableAttributeValues[u'TemporalResolution'] in [u'daily', '8day', 'monthly', 'annual']: 210 temporalResolution = queryableAttributeValues[u'TemporalResolution'] 211 elif u'TemporalResolutionCode' in queryableAttributeValues and isinstance(queryableAttributeValues[u'TemporalResolutionCode'], basestring) and queryableAttributeValues[u'TemporalResolutionCode'] in [u'DAY', '8D', 'MO', 'YR']: 212 temporalResolution = queryableAttributeValues[u'TemporalResolutionCode'] 213 else: 214 return [startDate + tOffset, None, None] 215 216 if temporalResolution in [u'daily', u'DAY']: 217 return [startDate + tOffset, startDate + datetime.timedelta(0.5) + tOffset, startDate + datetime.timedelta(1) + tOffset - datetime.timedelta(seconds=1)] 218 219 if temporalResolution in [u'8day', u'8D']: 220 if startDate.month == 12 and startDate.day >= 24: 221 endDate = datetime.datetime(startDate.year + 1, 1, 1) 222 return [startDate + tOffset, startDate + (endDate - startDate) / 2 + tOffset, endDate + tOffset - datetime.timedelta(seconds=1)] 223 else: 224 return [startDate + tOffset, startDate + datetime.timedelta(4) + tOffset, startDate + datetime.timedelta(8) + tOffset - datetime.timedelta(seconds=1)] 225 226 if temporalResolution in [u'monthly', u'MO']: 227 if startDate.month == 12: 228 endDate = datetime.datetime(startDate.year + 1, 1, 1) 229 else: 230 endDate = datetime.datetime(startDate.year, startDate.month + 1, 1) 231 return [startDate + tOffset, startDate + (endDate - startDate) / 2 + tOffset, endDate + tOffset - datetime.timedelta(seconds=1)] 232 233 if temporalResolution in [u'annual', u'YR']: 234 return [startDate + tOffset, datetime.datetime(startDate.year, 7, 1) + tOffset, datetime.datetime(startDate.year + 1, 1, 1) + tOffset - datetime.timedelta(seconds=1)] 235 236 return [None, None, None] 237 except: 238 return [None, None, None] 239 240 @classmethod 207 241 def CreateArcGISRasters(cls, satellite, temporalResolution, spatialResolution, geophysicalParameter, variableName, 208 outputWorkspace, mode=u'add', rasterNameExpressions=[u'%(Satellite)s', u'%(Wavelength)s', u'%(SpatialResolution)s', u'%(TemporalResolution)s', u'%%Y', u'%(SatelliteCode) s%%Y%%j%(EndDate)s.L3m_%(TemporalResolutionCode)s_%(GeophysicalParameter)s_%(SpatialResolutionCode)s_%(VariableName)s.img'], rasterCatalog=None,242 outputWorkspace, mode=u'add', rasterNameExpressions=[u'%(Satellite)s', u'%(Wavelength)s', u'%(SpatialResolution)s', u'%(TemporalResolution)s', u'%%Y', u'%(SatelliteCode).1s%%Y%%j%(EndDate)s.L3m_%(TemporalResolutionCode).3s_%(GeophysicalParameter)s_%(SpatialResolutionCode).1s_%(VariableName)s.img'], rasterCatalog=None, 209 243 qualityLevel=0, 210 244 rotationOffset=None, spatialExtent=None, startDate=None, endDate=None, … … 216 250 # clip it as requested. 217 251 218 fullGrid = MODISL3SSTTimeSeries(satellite, temporalResolution, spatialResolution, geophysicalParameter, variableName, qualityLevel, timeout, maxRetryTime, cacheDirectory)252 grid = MODISL3SSTTimeSeries(satellite, temporalResolution, spatialResolution, geophysicalParameter, variableName, qualityLevel, timeout, maxRetryTime, cacheDirectory) 219 253 220 254 try: 221 grid = fullGrid222 255 if rotationOffset is not None: 223 256 grid = RotatedGlobalGrid(grid, rotationOffset, u'Map units') … … 245 278 246 279 if rasterCatalog is not None: 247 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'min', tCoordFunction= fullGrid._GetOtherTimeCoordinates, overwriteExisting=True)280 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'min', tCoordFunction=cls._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 248 281 249 282 finally: 250 fullGrid.Close()283 grid.Close() 251 284 252 285 # Return successfully. -
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/NOAA/NODC.py
r925 r927 575 575 576 576 def __getattribute__(self, name): 577 if name.startswith('__') or name in ['_WrappedGrid', '_Get OtherTimeCoordinates', 'CreateArcGISRasters', 'CreateClimatologicalArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']:577 if name.startswith('__') or name in ['_WrappedGrid', '_GetTimeCoordsFromQueryableAttributeValues', 'CreateArcGISRasters', 'CreateClimatologicalArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']: 578 578 return object.__getattribute__(self, name) 579 579 return object.__getattribute__(object.__getattribute__(self, '_WrappedGrid'), name) 580 580 581 581 def __setattr__(self, name, value): 582 if name.startswith('__') or name in ['_WrappedGrid', '_Get OtherTimeCoordinates', 'CreateArcGISRasters', 'CreateClimatologicalArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']:582 if name.startswith('__') or name in ['_WrappedGrid', '_GetTimeCoordsFromQueryableAttributeValues', 'CreateArcGISRasters', 'CreateClimatologicalArcGISRasters', 'InterpolateAtArcGISPoints', 'CreateCayulaCornillonFrontsAsArcGISRasters']: 583 583 object.__setattr__(self, name, value) 584 584 else: 585 585 setattr(object.__getattribute__(self, '_WrappedGrid'), name, value) 586 586 587 def _GetOtherTimeCoordinates(self, queryableAttributeValues): 588 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 589 return [None, None] 587 @classmethod 588 def _GetTimeCoordsFromQueryableAttributeValues(cls, queryableAttributeValues): 590 589 try: 591 i = self.MinCoords['t', :].index(queryableAttributeValues[u'DateTime']) 590 if u'DateTime' in queryableAttributeValues and isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime) and u'TemporalResolution' in queryableAttributeValues and isinstance(queryableAttributeValues[u'TemporalResolution'], basestring) and queryableAttributeValues[u'TemporalResolution'] in [u'daily', '5day', '8day', 'monthly', 'yearly']: 591 startDate = queryableAttributeValues[u'DateTime'] 592 temporalResolution = queryableAttributeValues[u'TemporalResolution'] 593 594 if u'ObservationTime' in queryableAttributeValues and isinstance(queryableAttributeValues[u'ObservationTime'], basestring) and queryableAttributeValues[u'ObservationTime'].lower() == u'nighttime': 595 tOffset = datetime.timedelta(-0.5) 596 else: 597 tOffset = datetime.timedelta(0) 598 599 if temporalResolution == u'daily': 600 return [startDate + tOffset, startDate + datetime.timedelta(0.5) + tOffset, startDate + datetime.timedelta(1) + tOffset - datetime.timedelta(seconds=1)] 601 602 if temporalResolution == u'5day': 603 if startDate.month == 12 and startDate.day >= 24: 604 endDate = datetime.datetime(startDate.year + 1, 1, 1) 605 return [startDate + tOffset, startDate + (endDate - startDate) / 2 + tOffset, endDate + tOffset - datetime.timedelta(seconds=1)] 606 else: 607 return [startDate + tOffset, startDate + datetime.timedelta(2.5) + tOffset, startDate + datetime.timedelta(5) + tOffset - datetime.timedelta(seconds=1)] 608 609 if temporalResolution == u'8day': 610 if startDate.month == 12 and startDate.day >= 24: 611 endDate = datetime.datetime(startDate.year + 1, 1, 1) 612 return [startDate + tOffset, startDate + (endDate - startDate) / 2 + tOffset, endDate + tOffset - datetime.timedelta(seconds=1)] 613 else: 614 return [startDate + tOffset, startDate + datetime.timedelta(4) + tOffset, startDate + datetime.timedelta(8) + tOffset - datetime.timedelta(seconds=1)] 615 616 if temporalResolution == u'monthly': 617 if startDate.month == 12: 618 endDate = datetime.datetime(startDate.year + 1, 1, 1) 619 else: 620 endDate = datetime.datetime(startDate.year, startDate.month + 1, 1) 621 return [startDate + tOffset, startDate + (endDate - startDate) / 2 + tOffset, endDate + tOffset - datetime.timedelta(seconds=1)] 622 623 if temporalResolution == u'yearly': 624 return [startDate + tOffset, datetime.datetime(startDate.year, 7, 1) + tOffset, datetime.datetime(startDate.year + 1, 1, 1) + tOffset - datetime.timedelta(seconds=1)] 625 626 return [None, None, None] 592 627 except: 593 return [None, None] 594 return [self.CenterCoords['t', i], self.MaxCoords['t', i]] 628 return [None, None, None] 595 629 596 630 @classmethod … … 606 640 # and clip it as requested. 607 641 608 fullGrid = AVHRRPathfinderSSTTimeSeries(temporalResolution, observationTime, parameter, maskLand, minOverallQualityFlag, maskIfBrightnessTempTestFailed, maskIfCloudTestFailed, maskIfUniformityTest1Failed, maskIfUniformityTest2Failed, maskIfZenithAngleTest1Failed, maskIfZenithAngleTest2Failed, maskIfReferenceTestFailed, maskIfStraySunlightTestFailed, maskIfEdgeTestFailed, maskIfGlintTestFailed, maskIfSSTTestFailed, timeout, maxRetryTime, cacheDirectory)642 grid = AVHRRPathfinderSSTTimeSeries(temporalResolution, observationTime, parameter, maskLand, minOverallQualityFlag, maskIfBrightnessTempTestFailed, maskIfCloudTestFailed, maskIfUniformityTest1Failed, maskIfUniformityTest2Failed, maskIfZenithAngleTest1Failed, maskIfZenithAngleTest2Failed, maskIfReferenceTestFailed, maskIfStraySunlightTestFailed, maskIfEdgeTestFailed, maskIfGlintTestFailed, maskIfSSTTestFailed, timeout, maxRetryTime, cacheDirectory) 609 643 610 644 try: 611 grid = fullGrid612 645 if rotationOffset is not None: 613 646 grid = RotatedGlobalGrid(grid, rotationOffset, u'Map units') … … 635 668 636 669 if rasterCatalog is not None: 637 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'min', tCoordFunction= fullGrid._GetOtherTimeCoordinates, overwriteExisting=True)670 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'min', tCoordFunction=cls._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 638 671 639 672 finally: 640 fullGrid.Close()673 grid.Close() 641 674 642 675 # Return successfully. -
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/NOAA/OSCAR.py
r925 r927 211 211 return data.reshape(data.shape[0], data.shape[2], data.shape[3]), noDataValue 212 212 213 def _Get OtherTimeCoordinates(self, queryableAttributeValues):213 def _GetTimeCoordsFromQueryableAttributeValues(self, queryableAttributeValues): 214 214 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 215 return [None, None] 215 return [None, None, None] 216 import numpy 216 217 try: 217 i = self.CenterCoords['t', :].index(queryableAttributeValues[u'DateTime'])218 i = numpy.where(self.CenterCoords['t', :] == queryableAttributeValues[u'DateTime'])[0][0] 218 219 except: 219 return [None, None ]220 return [self.MinCoords['t', i], self.MaxCoords['t', i]]220 return [None, None, None] 221 return [self.MinCoords['t', i], queryableAttributeValues[u'DateTime'], self.MaxCoords['t', i] - datetime.timedelta(seconds=1)] 221 222 222 223 @classmethod … … 322 323 workspace.ImportDatasets(GridSliceCollection(grid, tQACoordType=u'center').QueryDatasets(), mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 323 324 if rasterCatalog is not None: 324 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction= self._GetOtherTimeCoordinates, overwriteExisting=True)325 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=fullGrid._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 325 326 finally: 326 327 fullGrid.Close() -
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/UMaineOMG.py
r925 r927 310 310 return mean, self.NoDataValue 311 311 312 def _Get OtherTimeCoordinates(self, queryableAttributeValues):312 def _GetTimeCoordsFromQueryableAttributeValues(self, queryableAttributeValues): 313 313 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 314 return [None, None] 314 return [None, None, None] 315 import numpy 315 316 try: 316 i = self.CenterCoords['t', :].index(queryableAttributeValues[u'DateTime'])317 i = numpy.where(self.CenterCoords['t', :] == queryableAttributeValues[u'DateTime'])[0][0] 317 318 except: 318 return [None, None ]319 return [self.MinCoords['t', i], self.MaxCoords['t', i]]319 return [None, None, None] 320 return [self.MinCoords['t', i], queryableAttributeValues[u'DateTime'], self.MaxCoords['t', i] - datetime.timedelta(seconds=1)] 320 321 321 322 @classmethod … … 380 381 from GeoEco.Datasets.ArcGIS import ArcGISWorkspace, ArcGISRaster 381 382 from GeoEco.Datasets.Virtual import GridSliceCollection 383 fullGrid = grid 382 384 grid = cls._Clip(grid, spatialExtent, linearUnit, startDate=startDate, endDate=endDate) 383 385 workspace = ArcGISWorkspace(outputWorkspace, ArcGISRaster, pathCreationExpressions=rasterNameExpressions, cacheTree=True, queryableAttributes=tuple(grid.GetAllQueryableAttributes() + [QueryableAttribute(u'DateTime', _(u'Date'), DateTimeTypeMetadata())])) 384 386 workspace.ImportDatasets(GridSliceCollection(grid, tQACoordType=u'center').QueryDatasets(), mode, calculateStatistics=calculateStatistics, buildPyramids=buildPyramids) 385 387 if rasterCatalog is not None: 386 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=grid._GetOtherTimeCoordinates, overwriteExisting=True)388 workspace.ToRasterCatalog(rasterCatalog, fullGrid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=fullGrid._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 387 389 finally: 388 390 grid.Close() … … 942 944 return mean, self.NoDataValue 943 945 944 def _Get OtherTimeCoordinates(self, queryableAttributeValues):946 def _GetTimeCoordsFromQueryableAttributeValues(self, queryableAttributeValues): 945 947 if u'DateTime' not in queryableAttributeValues or not isinstance(queryableAttributeValues[u'DateTime'], datetime.datetime): 946 return [None, None] 948 return [None, None, None] 949 import numpy 947 950 try: 948 i = self.CenterCoords['t', :].index(queryableAttributeValues[u'DateTime'])951 i = numpy.where(self.CenterCoords['t', :] == queryableAttributeValues[u'DateTime'])[0][0] 949 952 except: 950 return [None, None ]951 return [self.MinCoords['t', i], self.MaxCoords['t', i]]953 return [None, None, None] 954 return [self.MinCoords['t', i], queryableAttributeValues[u'DateTime'], self.MaxCoords['t', i] - datetime.timedelta(seconds=1)] 952 955 953 956 @classmethod 954 957 def CreateArcGISRasters(cls, variableName, depths, 955 outputWorkspace, mode=u'add', rasterNameExpressions=['%(VariableName)s', '%%Y', 'Depth_%(Depth) gm', '%(VariableName)s_%%Y%%j_%%H%%M_%(Depth)gm.img'], rasterCatalog=None,958 outputWorkspace, mode=u'add', rasterNameExpressions=['%(VariableName)s', '%%Y', 'Depth_%(Depth)04.0fm', '%(VariableName)s_%%Y%%j_%%H%%M_%(Depth)04.0fm.img'], rasterCatalog=None, 956 959 spatialExtent=None, linearUnit=u'Degrees', startDate=None, endDate=None, 957 960 url=u'http://viz.clusters.umaine.edu:8080/thredds/dodsC/pacific/1991-2008', timeout=60, maxRetryTime=120, cacheDirectory=None, … … 963 966 grid = ROMSCoSiNE4D(variableName, url, timeout, maxRetryTime, cacheDirectory) 964 967 try: 968 fullGrid = grid 965 969 grid = ROMSCoSiNE3D._Clip(grid, spatialExtent, linearUnit, startDate=startDate, endDate=endDate) 966 970 … … 995 999 996 1000 if rasterCatalog is not None: 997 workspace.ToRasterCatalog(rasterCatalog, grid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=grid._GetOtherTimeCoordinates, overwriteExisting=True)1001 workspace.ToRasterCatalog(rasterCatalog, fullGrid.GetSpatialReference(u'ArcGIS'), tQACoordType=u'center', tCoordFunction=fullGrid._GetTimeCoordsFromQueryableAttributeValues, overwriteExisting=True) 998 1002 999 1003 finally: … … 1009 1013 def CreateClimatologicalArcGISRasters(cls, variableName, depths, 1010 1014 statistic, binType, 1011 outputWorkspace, mode=u'add', rasterNameExpressions=[u'%(VariableName)s', u'%(ClimatologyBinType)s_Climatology', 'Depth_%(Depth) gm', u'%(VariableName)s_%(Depth)gm_%(ClimatologyBinName)s_%(Statistic)s.img'],1015 outputWorkspace, mode=u'add', rasterNameExpressions=[u'%(VariableName)s', u'%(ClimatologyBinType)s_Climatology', 'Depth_%(Depth)04.0fm', u'%(VariableName)s_%(Depth)04.0fm_%(ClimatologyBinName)s_%(Statistic)s.img'], 1012 1016 binDuration=1, startDayOfYear=1, 1013 1017 spatialExtent=None, linearUnit=u'Degrees', startDate=None, endDate=None, -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Datasets/ArcGIS.py
r925 r927 467 467 for item in level: 468 468 qa = item[1] 469 if qa.Name not in qaToFieldName :469 if qa.Name not in qaToFieldName and qa.Name.lower() not in ['startdate', 'centerdate', 'enddate']: 470 470 qaToFieldName[qa.Name] = qa.Name 471 471 … … 592 592 # Note that not all printf syntax is supported. 593 593 594 elif re.match(r'%\([^\)]+\)[#0\- +]?[\d]*(?:\ \\.[\d]+)?[hlL]?[diouxXeEfFgGcrs]', pce[i:]) is not None:594 elif re.match(r'%\([^\)]+\)[#0\- +]?[\d]*(?:\.[\d]+)?[hlL]?[diouxXeEfFgGcrs]', pce[i:]) is not None: 595 595 596 596 # Parse components of the formatter. … … 644 644 645 645 elif conversion in 'fF': 646 ppe += r'(?P<' + qaName + '>[+\- ]*\d+\.\d*)' 646 if precision is not None: 647 if precision > 0: 648 ppe += r'(?P<' + qaName + '>[+\- ]*\d+\.\d{' + str(precision) + '})' 649 else: 650 ppe += r'(?P<' + qaName + '>[+\- ]*\d+)' 651 else: 652 ppe += r'(?P<' + qaName + '>[+\- ]*\d+\.?\d*)' 647 653 648 654 elif conversion in 's': 649 ppe += r'(?P<' + qaName + '>.+)' 655 if precision is not None: # For NASA OceanColor L3 data, we need the ability to specify the maximum string length 656 ppe += r'(?P<' + qaName + '>.{0,' + str(precision) + '})' 657 else: 658 ppe += r'(?P<' + qaName + '>.*)' 650 659 651 660 else: … … 716 725 # the queryable attribute dictionaries. 717 726 718 pathsAndQA sList = self.QueryDatasets(getQueryableAttributesOnly=True)727 pathsAndQAVsList = self.QueryDatasets(getQueryableAttributesOnly=True) 719 728 720 pathToQA s = {}721 for result in pathsAndQA sList:722 pathToQA s[os.path.join(self.Path, *result[0]).lower()] = result[1]729 pathToQAVs = {} 730 for result in pathsAndQAVsList: 731 pathToQAVs[os.path.join(self.Path, *result[0]).lower()] = result[1] 723 732 724 733 # Open an update cursor on the raster catalog. For each … … 728 737 self._LogInfo(_(u'Updating the fields of each row of the raster catalog.')) 729 738 730 otherFields = None731 739 cur = catalogTable.OpenUpdateCursor(rowCount=catalogTable.GetRowCount(), rowDescriptionSingular=_(u'row'), rowDescriptionPlural=_(u'rows')) 732 740 try: 733 741 while cur.NextRow(): 734 742 path = oidToPath[cur.GetOID()] 735 if path not in pathToQA s:743 if path not in pathToQAVs: 736 744 continue 737 745 738 qa s = pathToQAs[path]746 qav = pathToQAVs[path] 739 747 for qaName, fieldName in qaToFieldName.items(): 740 cur.SetValue(fieldName, qas[qaName])741 748 742 749 # If this is queryable attribute is named 743 750 # 'DateTime' and the caller provided a 744 # function that can calculate the other two745 # dates given this one, calculate those dates746 # and set those fields.751 # function that can calculate the dates from 752 # the queryable attribute values, calculate 753 # the dates and set the fields. 747 754 748 755 if qaName.lower() == u'datetime' and tCoordFunction is not None: 749 if otherFields is None: 750 otherFields = [u'StartDate', u'CenterDate', u'EndDate'] 751 otherFields.remove(fieldName) 752 753 values = tCoordFunction(qas) 754 cur.SetValue(otherFields[0], values[0]) 755 cur.SetValue(otherFields[1], values[1]) 756 values = tCoordFunction(qav) 757 cur.SetValue(u'StartDate', values[0]) 758 cur.SetValue(u'CenterDate', values[1]) 759 cur.SetValue(u'EndDate', values[2]) 760 else: 761 cur.SetValue(fieldName, qav[qaName]) 756 762 757 763 cur.UpdateRow() … … 1545 1551 1546 1552 if progressReporter is not None: 1547 progressReporter.ReportProgress( )1553 progressReporter.ReportProgress(reinitializeArcGISProgressor=True) 1548 1554 1549 1555 @classmethod -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Datasets/Collections.py
r925 r927 211 211 # us, so we do not pass them through to _ConstructFoundObject. 212 212 213 closeDatasets = False 214 getQueryableAttributesOnly = False 215 213 216 if options is not None: 214 217 constructOptions = {} … … 225 228 raise RuntimeError(u'Programming error in this tool: DatasetCollectionTree._QueryRecursive(): queryType must be \'normal\' when getQueryableAttributesOnly is True. Please contact the author of this tool for assistance.') 226 229 else: 227 closeDatasets = False228 getQueryableAttributesOnly = False229 230 constructOptions = options 230 231 -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Datasets/Virtual.py
r920 r927 1335 1335 1336 1336 for i in range(len(mask.Dimensions)): 1337 gridCoords = numpy.cast['float32'](self.CenterCoords[mask.Dimensions[i]]) 1338 maskCoords = numpy.cast['float32'](mask.CenterCoords[mask.Dimensions[i]]) 1337 if mask.Dimensions[i] != 't': 1338 gridCoords = numpy.cast['float32'](self.CenterCoords[mask.Dimensions[i]]) 1339 maskCoords = numpy.cast['float32'](mask.CenterCoords[mask.Dimensions[i]]) 1340 else: 1341 gridCoords = self.CenterCoords[mask.Dimensions[i]] 1342 maskCoords = mask.CenterCoords[mask.Dimensions[i]] 1339 1343 1340 1344 if gridCoords[0] < maskCoords[0] or gridCoords[-1] > maskCoords[-1]: -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Logging.py
r911 r927 587 587 self.Stop() 588 588 589 def ReportProgress(self, operationsCompleted=1 ):589 def ReportProgress(self, operationsCompleted=1, reinitializeArcGISProgressor=False): 590 590 assert self.HasStarted, u'This ProgressReporter has not been started' 591 591 … … 646 646 self._ClockNextReportTime = clockNow + 60.0 647 647 648 if self._UseArcGISProgressor() and int(math.floor(float(self._OperationsCompleted) / float(self._TotalOperations) * 1000.)) > int(math.floor(float(self._OperationsCompleted - 1) / float(self._TotalOperations) * 1000.)):648 if self._UseArcGISProgressor() and (reinitializeArcGISProgressor or int(math.floor(float(self._OperationsCompleted) / float(self._TotalOperations) * 1000.)) > int(math.floor(float(self._OperationsCompleted - 1) / float(self._TotalOperations) * 1000.))): 649 649 from GeoEco.ArcGIS import GeoprocessorManager 650 650 gp = GeoprocessorManager.GetWrappedGeoprocessor() 651 651 try: 652 if reinitializeArcGISProgressor: 653 gp.SetProgressor('step', self.ArcGISProgressorLabel, 0, 1000, 1) 652 654 gp.SetProgressorPosition(min(1000, int(math.floor(float(self._OperationsCompleted) / float(self._TotalOperations) * 1000.)))) 653 655 except:
