Changeset 864

Show
Ignore:
Timestamp:
12/13/11 16:35:58 (18 months ago)
Author:
jjr8
Message:

Added ROMS-CoSiNE to connectivity tool.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Connectivity/CoralReefConnectivity.py

    r862 r864  
    2424from GeoEco.DataProducts.HYCOM import HYCOMGOMl0044D, _HYCOMGOMl004_LongDescription, HYCOMGLBa008Equatorial4D, _HYCOMGLBa008Equatorial_LongDescription 
    2525from GeoEco.DataProducts.NOAA.OSCAR import OSCAR5DayThirdDegreeCurrents, _OSCAR_LongDescription 
     26from GeoEco.DataProducts.UMaineOMG import ROMSCoSiNE4D, _ROMS_CoSiNE_LongDescription 
    2627from GeoEco.DynamicDocString import DynamicDocString 
    2728from GeoEco.Internationalization import _ 
     
    192193        # projection, extent, and cell size of the reef IDs raster. 
    193194 
    194         cls._FinishLoadingCurrents(simulationDirectory, u'Aviso ' + product, u'Center', 86400, avisoCurrentsDirectory, u'setnull( inputRaster > 1000000 || inputRaster < -1000000, inputRaster / 100)')     # Use Map Algebra to Convert from cm/s to to m/s and mask bogus values introduced by ArcGIS 
     195        cls._FinishLoadingCurrents(simulationDirectory, scp, u'Aviso ' + product, u'Center', 86400, avisoCurrentsDirectory, u'setnull( inputRaster > 1000000 || inputRaster < -1000000, inputRaster / 100)')     # Use Map Algebra to Convert from cm/s to to m/s and mask bogus values introduced by ArcGIS 
    195196 
    196197        # Return successfully. 
     
    227228        # projection, extent, and cell size of the reef IDs raster. 
    228229 
    229         cls._FinishLoadingCurrents(simulationDirectory, u'OSCAR', u'Center', 6*86400, oscarCurrentsDirectory) 
     230        cls._FinishLoadingCurrents(simulationDirectory, scp, u'OSCAR', u'Center', 6*86400, oscarCurrentsDirectory) 
    230231 
    231232        # Return successfully. 
     
    260261        # projection, extent, and cell size of the reef IDs raster. 
    261262 
    262         cls._FinishLoadingCurrents(simulationDirectory, u'HYCOM GOMl0.04  ' + unicode(int(depth)) + u' m', u'Center', 86400, hycomCurrentsDirectory) 
     263        cls._FinishLoadingCurrents(simulationDirectory, scp, u'HYCOM GOMl0.04  ' + unicode(int(depth)) + u' m', u'Center', 86400, hycomCurrentsDirectory) 
    263264 
    264265        # Return successfully. 
     
    293294        # projection, extent, and cell size of the reef IDs raster. 
    294295 
    295         cls._FinishLoadingCurrents(simulationDirectory, u'HYCOM GLBa0.08 Equatorial ' + unicode(int(depth)) + u' m', u'Center', 86400, hycomCurrentsDirectory) 
     296        cls._FinishLoadingCurrents(simulationDirectory, scp, u'HYCOM GLBa0.08 Equatorial ' + unicode(int(depth)) + u' m', u'Center', 86400, hycomCurrentsDirectory) 
    296297 
    297298        # Return successfully. 
     
    300301 
    301302    @classmethod 
    302     def _FinishLoadingCurrents(cls, simulationDirectory, currentsProduct, currentsDateType, maxSecondsBetweenCurrentsImages, originalCurrentsDirectory, mapAlgebraExpression=None): 
     303    def LoadROMSCoSiNE4DCurrentsIntoSimulation(cls, simulationDirectory, startDate, endDate, depth=0., url=u'http://viz.clusters.umaine.edu:8080/thredds/dodsC/pacific/1991-2008', timeout=60, maxRetryTime=120, cacheDirectory=None): 
     304        cls.__doc__.Obj.ValidateMethodInvocation() 
     305 
     306        # Parse and validate the Simulation.ini file. 
     307 
     308        scp, crosses180, currentsLoaded, currentsProduct = cls._ReadCurrentsInfoFromSimulationINI(simulationDirectory) 
     309 
     310        # If the simulation already has currents loaded in it from a 
     311        # different product or depth, report an error. 
     312 
     313        if currentsLoaded and currentsProduct != u'ROMS-CoSiNE ' + unicode(int(depth)) + u' m': 
     314            Logger.RaiseException(ValueError(_(u'Cannot load %(prod1)s currents data into the simulation in directory %(dir)s because that simulation already has %(prod2)s currents data loaded into it. You can load additional %(prod2)s data, if you like, but to use %(prod1)s data, you must create a new simulation.') % {u'dir': simulationDirectory, u'prod1': u'ROMS-CoSiNE ' + unicode(int(depth)) + u' m', u'prod2': currentsProduct})) 
     315 
     316        # First, download and create ROMS-CoSiNE current rasters in a 
     317        # ROMS-CoSiNE-specific directory. These will have the 
     318        # ROMS-CoSiNE projection, extent, and cell size. We still need 
     319        # to project them to the simulation's projection, extent, and 
     320        # cell size. 
     321 
     322        romsCurrentsDirectory = os.path.join(simulationDirectory, 'OriginalROMSCurrents') 
     323        ROMSCoSiNE4D.CreateArcGISRasters(u'u', [depth], romsCurrentsDirectory, rasterNameExpressions=['%(VariableName)s', '%%Y', '%(VariableName)s%%Y%%j0000.img'], startDate=startDate, endDate=endDate, timeout=timeout, maxRetryTime=maxRetryTime, cacheDirectory=cacheDirectory) 
     324        ROMSCoSiNE4D.CreateArcGISRasters(u'v', [depth], romsCurrentsDirectory, rasterNameExpressions=['%(VariableName)s', '%%Y', '%(VariableName)s%%Y%%j0000.img'], startDate=startDate, endDate=endDate, timeout=timeout, maxRetryTime=maxRetryTime, cacheDirectory=cacheDirectory) 
     325 
     326        # Record in the Simulation.ini file that we downloaded some 
     327        # currents and then project, snap, and clip them to the 
     328        # projection, extent, and cell size of the reef IDs raster. 
     329 
     330        cls._FinishLoadingCurrents(simulationDirectory, scp, u'ROMS-CoSiNE ' + unicode(int(depth)) + u' m', u'Center', 73*3600, romsCurrentsDirectory) 
     331 
     332        # Return successfully. 
     333 
     334        return simulationDirectory 
     335 
     336    @classmethod 
     337    def _FinishLoadingCurrents(cls, simulationDirectory, scp, currentsProduct, currentsDateType, maxSecondsBetweenCurrentsImages, originalCurrentsDirectory, mapAlgebraExpression=None): 
    303338 
    304339        # Write the Simulation.ini file, so that any new rasters 
     
    11951230  center of the Gulf of Mexico. 
    11961231"""), 
    1197     arcGISDisplayName=_(u'Minimum depth')) 
     1232    arcGISDisplayName=_(u'Depth')) 
    11981233 
    11991234CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'timeout', CoralReefConnectivity.LoadHYCOMGOMl0044DCurrentsIntoSimulation, u'timeout') 
     
    12661301  regions. 
    12671302"""), 
    1268     arcGISDisplayName=_(u'Minimum depth')) 
     1303    arcGISDisplayName=_(u'Depth')) 
    12691304 
    12701305CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'extendYExtent', CoralReefConnectivity.LoadHYCOMGLBa0084DEquatorialCurrentsIntoSimulation, u'extendYExtent') 
     
    12741309 
    12751310CopyResultMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'updatedSimulationDirectory', CoralReefConnectivity.LoadHYCOMGLBa0084DEquatorialCurrentsIntoSimulation, u'updatedSimulationDirectory') 
     1311 
     1312# Public method: CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation 
     1313 
     1314AddMethodMetadata(CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, 
     1315    shortDescription=_(u'Downloads Pacific ROMS-CoSiNE ocean currents into a coral reef connectivity simulation.'), 
     1316    longDescription=_ROMS_CoSiNE_LongDescription % {u'name': 'tool'}, 
     1317    isExposedToPythonCallers=True, 
     1318    isExposedByCOM=True, 
     1319    isExposedAsArcGISTool=True, 
     1320    arcGISDisplayName=_(u'Load Pacific ROMS-CoSiNE Currents Into Coral Reef Connectivity Simulation'), 
     1321    arcGISToolCategory=_(u'Connectivity Analysis\\Coral Reef Larval Connectivity'), 
     1322    dependencies=[ArcGISDependency(9, 2), ArcGISExtensionDependency(u'spatial'), PythonAggregatedModuleDependency('numpy')]) 
     1323 
     1324CopyArgumentMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'cls', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'cls') 
     1325 
     1326AddArgumentMetadata(CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'simulationDirectory', 
     1327    typeMetadata=DirectoryTypeMetadata(mustExist=True), 
     1328    description=_( 
     1329u"""Existing coral reef connectivity simulation directory that should 
     1330recieve the currents. 
     1331 
     1332The directory must have been created using the Create Coral Reef 
     1333Connectivity Simulation tool. 
     1334 
     1335If you have already loaded Pacific ROMS-CoSiNE currents into the 
     1336simulation, you can use this tool to add currents for an additional 
     1337range of dates so long as they are for the same depth as the original 
     1338currents. If you try to add a different currents product to the 
     1339simulation (e.g. geostrophic currents from Aviso), or for a different 
     1340depth, this tool will report an error. 
     1341 
     1342If you try to load data for a range of dates that have been already 
     1343loaded into the simulation, the downloads for those dates will be 
     1344skipped. There is no way to delete or overwrite the data that has 
     1345already been loaded into the simulation. If you want to overwrite your 
     1346existing data (e.g. you want to switch to using a different depth), 
     1347you must create a new simulation."""), 
     1348    arcGISDisplayName=_(u'Simulation directory to recieve ROMS-CoSiNE currents')) 
     1349 
     1350CopyArgumentMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'startDate', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'startDate') 
     1351CopyArgumentMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'endDate', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'endDate') 
     1352 
     1353AddArgumentMetadata(CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'depth', 
     1354    typeMetadata=FloatTypeMetadata(), 
     1355    description=_( 
     1356u"""Depth of currents layer to download. 
     1357 
     1358ROMS-CoSiNE uses a terrain-following vertical coordinate system 
     1359designed to maximize the accuracy of the simulation in coastal areas 
     1360and the open ocean simultaneously. There are 30 depth layers but their 
     1361depths vary on a per-cell basis with latitude, longitude, and time. 
     1362For example, coastal cells of the 10th depth layer might represent a 
     1363depth of 10 meters, while cells in the open ocean might represent a 
     1364depth of 200 meters. This tool interpolates a constant-depth layer 
     1365from ROMS-CoSiNE's varying-depth layers using a linear interpolation 
     1366algorithm. 
     1367 
     1368The depth 0 represents the surface. The sign of the depth coordinate 
     1369is ignored (e.g. the values 10 and -10 are both interpreted as 10 m 
     1370below the surface). 
     1371 
     1372This tool was designed primarily to study larvae that float at or near 
     1373the surface. The default depth is 0. If you are studying larvae that 
     1374stay submerged, you can choose a deeper depth, but be aware of two 
     1375important points: 
     1376 
     1377* This tool assumes the larvae remain at that depth for the entire 
     1378  simulation. It does not implement vertical migration or other 
     1379  behaviors that might be appropriate for your species. A newer 
     1380  version of this tool, to be released in 2012, will support vertical 
     1381  migration. 
     1382 
     1383* Be aware that the spatial extent of available currents data will 
     1384  shrink as depth increases. For example, if you choose a deep depth 
     1385  such as 250 m, there will be no data available for regions close to 
     1386  shore because the ocean is typically shallower than 250 m in those 
     1387  regions. 
     1388"""), 
     1389    arcGISDisplayName=_(u'Depth')) 
     1390 
     1391CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'url', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'url') 
     1392CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'timeout', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'timeout') 
     1393CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'maxRetryTime', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'maxRetryTime') 
     1394CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'cacheDirectory', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'cacheDirectory') 
     1395 
     1396CopyResultMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'updatedSimulationDirectory', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'updatedSimulationDirectory') 
    12761397 
    12771398# Public method: CoralReefConnectivity.RunSimulation