| 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): |
| | 1311 | |
| | 1312 | # Public method: CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation |
| | 1313 | |
| | 1314 | AddMethodMetadata(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 | |
| | 1324 | CopyArgumentMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'cls', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'cls') |
| | 1325 | |
| | 1326 | AddArgumentMetadata(CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'simulationDirectory', |
| | 1327 | typeMetadata=DirectoryTypeMetadata(mustExist=True), |
| | 1328 | description=_( |
| | 1329 | u"""Existing coral reef connectivity simulation directory that should |
| | 1330 | recieve the currents. |
| | 1331 | |
| | 1332 | The directory must have been created using the Create Coral Reef |
| | 1333 | Connectivity Simulation tool. |
| | 1334 | |
| | 1335 | If you have already loaded Pacific ROMS-CoSiNE currents into the |
| | 1336 | simulation, you can use this tool to add currents for an additional |
| | 1337 | range of dates so long as they are for the same depth as the original |
| | 1338 | currents. If you try to add a different currents product to the |
| | 1339 | simulation (e.g. geostrophic currents from Aviso), or for a different |
| | 1340 | depth, this tool will report an error. |
| | 1341 | |
| | 1342 | If you try to load data for a range of dates that have been already |
| | 1343 | loaded into the simulation, the downloads for those dates will be |
| | 1344 | skipped. There is no way to delete or overwrite the data that has |
| | 1345 | already been loaded into the simulation. If you want to overwrite your |
| | 1346 | existing data (e.g. you want to switch to using a different depth), |
| | 1347 | you must create a new simulation."""), |
| | 1348 | arcGISDisplayName=_(u'Simulation directory to recieve ROMS-CoSiNE currents')) |
| | 1349 | |
| | 1350 | CopyArgumentMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'startDate', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'startDate') |
| | 1351 | CopyArgumentMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'endDate', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'endDate') |
| | 1352 | |
| | 1353 | AddArgumentMetadata(CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'depth', |
| | 1354 | typeMetadata=FloatTypeMetadata(), |
| | 1355 | description=_( |
| | 1356 | u"""Depth of currents layer to download. |
| | 1357 | |
| | 1358 | ROMS-CoSiNE uses a terrain-following vertical coordinate system |
| | 1359 | designed to maximize the accuracy of the simulation in coastal areas |
| | 1360 | and the open ocean simultaneously. There are 30 depth layers but their |
| | 1361 | depths vary on a per-cell basis with latitude, longitude, and time. |
| | 1362 | For example, coastal cells of the 10th depth layer might represent a |
| | 1363 | depth of 10 meters, while cells in the open ocean might represent a |
| | 1364 | depth of 200 meters. This tool interpolates a constant-depth layer |
| | 1365 | from ROMS-CoSiNE's varying-depth layers using a linear interpolation |
| | 1366 | algorithm. |
| | 1367 | |
| | 1368 | The depth 0 represents the surface. The sign of the depth coordinate |
| | 1369 | is ignored (e.g. the values 10 and -10 are both interpreted as 10 m |
| | 1370 | below the surface). |
| | 1371 | |
| | 1372 | This tool was designed primarily to study larvae that float at or near |
| | 1373 | the surface. The default depth is 0. If you are studying larvae that |
| | 1374 | stay submerged, you can choose a deeper depth, but be aware of two |
| | 1375 | important 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 | |
| | 1391 | CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'url', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'url') |
| | 1392 | CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'timeout', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'timeout') |
| | 1393 | CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'maxRetryTime', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'maxRetryTime') |
| | 1394 | CopyArgumentMetadata(ROMSCoSiNE4D.CreateArcGISRasters, u'cacheDirectory', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'cacheDirectory') |
| | 1395 | |
| | 1396 | CopyResultMetadata(CoralReefConnectivity.LoadAvisoGeostrophicCurrentsIntoSimulation, u'updatedSimulationDirectory', CoralReefConnectivity.LoadROMSCoSiNE4DCurrentsIntoSimulation, u'updatedSimulationDirectory') |