public static Bathymetry Extract(string databaseFile, string extractionProgram, float selectedResolution, GeoRect region, PercentProgress progress = null) { if (progress != null) { progress.MaximumValue = 4; progress.Report(0); } var outputPath = Path.GetTempFileName(); outputPath = outputPath.Remove(outputPath.Length - 4, 4); var outputDirectory = Path.GetDirectoryName(outputPath); var commandArgs = string.Format(" area \"{0}\" 0.05min 2.00min nearest 0 meters G {1} {2} {3} {4} {5:0.0##} YXZ=\"{6}\"", databaseFile, region.South, region.West, region.North, region.East, selectedResolution, string.Format("{0}.yxz", Path.GetFileName(outputPath))); //extract the area and look for success or failure in the output string. if (progress != null) lock (progress) progress.Report(1); var result = NAVOExtractionProgram.Execute(extractionProgram, commandArgs, outputDirectory).Result; var resarray = result.Split('\n'); foreach (var line in resarray.Where(line => line.Contains("ERROR"))) throw new ApplicationException("DigitalBathymetricDatabase: Error extracting requested area: " + line); if (progress != null) lock (progress) progress.Report(2); var bathymetry = Bathymetry.FromYXZ(Path.Combine(outputPath + ".yxz"), -1); bathymetry.Samples.TrimToNearestPoints(region); if (progress != null) lock (progress) progress.Report(3); File.Delete(outputPath + ".yxz"); File.Delete(outputPath + ".yxz_SECURITY_README.txt"); if (progress != null) lock (progress) progress.Report(4); return bathymetry; }
public static Sediment Extract(string bstDirectory, GeoRect region, float resolution, PercentProgress progress = null) { if (progress != null) lock (progress) progress.Report(0); var north = (float)Math.Round(region.North + 1); var south = (float)Math.Round(region.South - 1); var east = (float)Math.Round(region.East + 1); var west = (float)Math.Round(region.West - 1); if (progress != null) progress.MaximumValue = (((north - south) * (east - west)) + 3); var totalProgress = 0; var fileId = H5F.open(bstDirectory, H5F.OpenMode.ACC_RDONLY); var highResGroup = H5G.open(fileId, "0.10000/G/UNCLASSIFIED/"); var lowResGroup = H5G.open(fileId, "5.00000/G/UNCLASSIFIED/"); var dedupeList = new HashedArrayList<SedimentSample>(); for (var lat = south; lat < north; lat++) for (var lon = west; lon < east; lon++) { //var data = ReadDataset(highResGroup, 0.1, lowResGroup, 5.0, resolution, (int)lat, (int)lon); var data = ReadDatasetHierarchical(highResGroup, 0.1, lowResGroup, 5.0, resolution, (int)lat, (int)lon); if (data != null) dedupeList.AddAll(data); if (progress != null) lock (progress) progress.Report(totalProgress++); } var sediment = new Sediment(); if (progress != null) lock (progress) progress.Report(totalProgress++); sediment.Samples.AddRange(dedupeList); sediment.Samples.Sort(); sediment.Samples.TrimToNearestPoints(region); if (progress != null) lock (progress) progress.Report(totalProgress++); if (lowResGroup != null) H5G.close(lowResGroup); if (highResGroup != null) H5G.close(highResGroup); H5F.close(fileId); if (progress != null) lock (progress) progress.Report(totalProgress); return sediment; }
void ReleaseDesignerOutlets() { if (BackButton != null) { BackButton.Dispose(); BackButton = null; } if (BottomConstraint != null) { BottomConstraint.Dispose(); BottomConstraint = null; } if (DistanceText != null) { DistanceText.Dispose(); DistanceText = null; } if (EditSelf != null) { EditSelf.Dispose(); EditSelf = null; } if (EditSelfBack != null) { EditSelfBack.Dispose(); EditSelfBack = null; } if (EditSelfHeader != null) { EditSelfHeader.Dispose(); EditSelfHeader = null; } if (EditSpacer != null) { EditSpacer.Dispose(); EditSpacer = null; } if (HeaderBackground != null) { HeaderBackground.Dispose(); HeaderBackground = null; } if (HideButton != null) { HideButton.Dispose(); HideButton = null; } if (LastActiveDate != null) { LastActiveDate.Dispose(); LastActiveDate = null; } if (LikeButton != null) { LikeButton.Dispose(); LikeButton = null; } if (LocationTime != null) { LocationTime.Dispose(); LocationTime = null; } if (MapBottomSeparator != null) { MapBottomSeparator.Dispose(); MapBottomSeparator = null; } if (MapSatellite != null) { MapSatellite.Dispose(); MapSatellite = null; } if (MapStreet != null) { MapStreet.Dispose(); MapStreet = null; } if (MapTopSeparator != null) { MapTopSeparator.Dispose(); MapTopSeparator = null; } if (MenuBlock != null) { MenuBlock.Dispose(); MenuBlock = null; } if (MenuContainer != null) { MenuContainer.Dispose(); MenuContainer = null; } if (MenuIcon != null) { MenuIcon.Dispose(); MenuIcon = null; } if (MenuLayer != null) { MenuLayer.Dispose(); MenuLayer = null; } if (MenuReport != null) { MenuReport.Dispose(); MenuReport = null; } if (Name != null) { Name.Dispose(); Name = null; } if (NavigationSpacer != null) { NavigationSpacer.Dispose(); NavigationSpacer = null; } if (NextButton != null) { NextButton.Dispose(); NextButton = null; } if (PercentProgress != null) { PercentProgress.Dispose(); PercentProgress = null; } if (PreviousButton != null) { PreviousButton.Dispose(); PreviousButton = null; } if (ProfileImageContainer != null) { ProfileImageContainer.Dispose(); ProfileImageContainer = null; } if (ProfileImageScroll != null) { ProfileImageScroll.Dispose(); ProfileImageScroll = null; } if (ProfileViewDescription != null) { ProfileViewDescription.Dispose(); ProfileViewDescription = null; } if (ProfileViewMap != null) { ProfileViewMap.Dispose(); ProfileViewMap = null; } if (ProfileViewScroll != null) { ProfileViewScroll.Dispose(); ProfileViewScroll = null; } if (RegisterDate != null) { RegisterDate.Dispose(); RegisterDate = null; } if (ResponseRate != null) { ResponseRate.Dispose(); ResponseRate = null; } if (RippleImageNext != null) { RippleImageNext.Dispose(); RippleImageNext = null; } if (RippleImagePrev != null) { RippleImagePrev.Dispose(); RippleImagePrev = null; } if (RippleProfileView != null) { RippleProfileView.Dispose(); RippleProfileView = null; } if (RoundBottom != null) { RoundBottom.Dispose(); RoundBottom = null; } if (ScrollBottomConstraint != null) { ScrollBottomConstraint.Dispose(); ScrollBottomConstraint = null; } if (SendLocation != null) { SendLocation.Dispose(); SendLocation = null; } if (Snackbar != null) { Snackbar.Dispose(); Snackbar = null; } if (SnackBottomConstraint != null) { SnackBottomConstraint.Dispose(); SnackBottomConstraint = null; } if (SnackTopConstraint != null) { SnackTopConstraint.Dispose(); SnackTopConstraint = null; } if (Username != null) { Username.Dispose(); Username = null; } if (ViewportConstraint != null) { ViewportConstraint.Dispose(); ViewportConstraint = null; } }
void Run(TimeSpan timeStepSize, CancellationToken token) { Geo<float> firstAnimatPosition = null; Task<bool> processTask = null; var timeStepCount = (int)Math.Round(((TimeSpan)Scenario.Duration).TotalSeconds / timeStepSize.TotalSeconds); if (MovingAnimats) Initialize3MB(); PercentProgress = new PercentProgress<Simulation>(this) { MinimumValue = 0, MaximumValue = timeStepCount - 1 }; Actors = new List<Actor>(); foreach (var platform in Scenario.Platforms) { platform.PlatformBehavior = new PlatformBehavior(platform, timeStepSize, timeStepCount); var behaviors = platform.PlatformBehavior.PlatformStates.ToArray(); _platformStates.Add(behaviors); var curPlatform = platform; Globals.Dispatcher.InvokeIfRequired(() => { curPlatform.RemoveMapLayers(); curPlatform.UpdateMapLayers(); var mapLayers = CreateFootprintMapLayers(curPlatform, behaviors[0]).ToArray(); _modeFootprintMapLayers.Add(mapLayers); foreach (var layer in mapLayers) { MediatorMessage.Send(MediatorMessage.AddMapLayer, layer); MediatorMessage.Send(MediatorMessage.HideMapLayer, layer); } }); var actor = new Actor { ID = platform.ActorID, Platform = platform }; Actors.Add(actor); } _exposuresBySpecies = new int[Scenario.ScenarioSpecies.Count]; _speciesActorIDStart = new int[Scenario.ScenarioSpecies.Count]; _speciesActorIDEnd = new int[Scenario.ScenarioSpecies.Count]; for (var j = 0; j < Scenario.ScenarioSpecies.Count; j++) { var species = Scenario.ScenarioSpecies[j]; _speciesActorIDStart[j] = species.StartActorID; _speciesActorIDEnd[j] = species.StartActorID + species.Animat.Locations.Count - 1; if (firstAnimatPosition == null) firstAnimatPosition = new Geo<float>(species.Animat.Locations[0].Latitude, species.Animat.Locations[0].Longitude) { Data = species.Animat.Locations[0].Data }; for (var i = 0; i < species.Animat.Locations.Count; i++) Actors.Add(new Actor { ID = species.StartActorID + i, Species = species }); } var actorCount = Scenario.ScenarioSpecies.Last().StartActorID + Scenario.ScenarioSpecies.Last().Animat.Locations.Count; var logBlock = new ActionBlock<SimulationTimeStepRecord>(block => SimulationLog.Add(block), new ExecutionDataflowBlockOptions { BoundedCapacity = 1, MaxDegreeOfParallelism = 1 }); logBlock.Completion.ContinueWith(t => SimulationLog.Close()); var logBuffer = new BufferBlock<SimulationTimeStepRecord>(); logBuffer.LinkTo(logBlock); logBuffer.Completion.ContinueWith(t => logBlock.Complete()); Task moveTask = null; for (var timeStepIndex = 0; timeStepIndex < timeStepCount; timeStepIndex++) { if (MovingAnimats) moveTask = MoveAnimatsAsync(); var actorPositionRecords = new ActorPositionRecord[actorCount]; var actionBlockCompletions = new List<Task>(); var bufferBlocks = new List<BufferBlock<int>>(); foreach (var platform in Scenario.Platforms) { var platformState = _platformStates[platform.ActorID][timeStepIndex]; actorPositionRecords[platform.ActorID] = new ActorPositionRecord(platformState.PlatformLocation.Location, platformState.PlatformLocation.Depth); foreach (var activeMode in platformState.ModeActiveTimes.Keys) { var platformModeLayers = _modeFootprintMapLayers[Scenario.Platforms.IndexOf(platform)]; var activeModeLayerName = string.Format("{0}-footprint", activeMode.Guid); var curModeLayer = (from l in platformModeLayers where l.Name == activeModeLayerName select l).FirstOrDefault(); if (curModeLayer != null) { UpdateFootprintMapLayer(activeMode, platformState, curModeLayer); var isActive = platformState.ModeActiveTimes[activeMode].Ticks > 0; Globals.Dispatcher.InvokeIfRequired(() => { MediatorMessage.Send(AnimateSimulation && isActive ? MediatorMessage.ShowMapLayer : MediatorMessage.HideMapLayer, curModeLayer); MediatorMessage.Send(MediatorMessage.RefreshMapLayer, curModeLayer); }); } var mode = activeMode; var platformLocation = platformState.PlatformLocation.Location; var thisPlatform = platform; var scenario = Scenario; var geoArc = new GeoArc(platformLocation, Geo.DegreesToRadians(platformState.PlatformLocation.Course + mode.RelativeBeamAngle), Geo.DegreesToRadians(mode.HorizontalBeamWidth), Geo.MetersToRadians(mode.MaxPropagationRadius)); var actionBlock = new ActionBlock<int>(async index => { // Don't expose a platform to itself if (thisPlatform.ActorID == index) return; var record = actorPositionRecords[index]; var actorGeo = new Geo(record.Latitude, record.Longitude); var radiansToActor = platformLocation.DistanceRadians(actorGeo); var azimuthToActor = platformLocation.Azimuth(actorGeo); if (!geoArc.Contains(radiansToActor, azimuthToActor)) return; // At this point we know the actor will be exposed to this mode // Find the nearest radial var closestRadial = scenario.ClosestTransmissionLoss(platformLocation, mode) .ClosestRadial(Geo.RadiansToDegrees(azimuthToActor)); // Load it into the cache if it's not already there var tlTask = _transmissionLossCache[closestRadial]; await tlTask; // Look up the TL value at the actor's range and depth var transmissionLoss = tlTask.Result.ShadeFile[Geo.RadiansToMeters(radiansToActor), -record.Depth]; // Only generate an exposure record if the appropriate transmissionLoss is not NaN if (!float.IsNaN(transmissionLoss)) { var peakSPL = mode.SourceLevel - transmissionLoss; //Debug.Assert(platformState != null, "platformState != null"); //Debug.Assert(platformState.ModeActiveTimes != null, "platformState.ModeActiveTimes != null"); //Debug.Assert(platformState.ModeActiveTimes.ContainsKey(mode), "platformState.ModeActiveTimes does not contain key"); //Debug.Assert(record != null, "record != null"); //Debug.Assert(record.Exposures != null, "record.Exposures != null"); var energy = (float)(peakSPL + (10 * Math.Log10(platformState.ModeActiveTimes[mode].TotalSeconds))); record.Expose(new ActorExposureRecord(index, mode, peakSPL, energy)); Interlocked.Increment(ref _totalExposureCount); for (var i = 0; i < Scenario.ScenarioSpecies.Count; i++) if (_speciesActorIDStart[i] <= index && index <= _speciesActorIDEnd[i]) Interlocked.Increment(ref _exposuresBySpecies[i]); //var actorRecord = SimulationLog.RecordFromActorID(index) as SpeciesNameGuid; //if (actorRecord != null) Interlocked.Increment(ref _exposuresBySpecies[SimulationLog.SpeciesRecords.IndexOf(actorRecord)]); } }, new ExecutionDataflowBlockOptions { BoundedCapacity = -1, MaxDegreeOfParallelism = -1 }); var bufferBlock = new BufferBlock<int>(); bufferBlock.LinkTo(actionBlock); bufferBlocks.Add(bufferBlock); actionBlockCompletions.Add(actionBlock.Completion); bufferBlock.Completion.ContinueWith(t => actionBlock.Complete()); } } foreach (var species in Scenario.ScenarioSpecies) { for (var animatIndex = 0; animatIndex < species.Animat.Locations.Count; animatIndex++) { var actorID = species.StartActorID + animatIndex; actorPositionRecords[actorID] = new ActorPositionRecord(species.Animat.Locations[animatIndex]); } } foreach (var bufferBlock in bufferBlocks) { //Debug.WriteLine("Sending actor IDs to an active mode"); for (var actorID = 0; actorID < actorCount; actorID++) bufferBlock.Post(actorID); bufferBlock.Complete(); } //Debug.WriteLine("Actor IDs sent. Waiting for completion."); Task.WhenAll(actionBlockCompletions).Wait(); PercentProgress.Report(timeStepIndex); var timeStepRecord = new SimulationTimeStepRecord(); timeStepRecord.ActorPositionRecords.AddRange(actorPositionRecords); if (processTask != null) processTask.Wait(); processTask = ModeThresholdHistogram.Process(timeStepRecord, Globals.Dispatcher); if (timeStepIndex % 10 == 0) { processTask.Wait(); Globals.Dispatcher.InvokeIfRequired(UpdateHistogramDisplay); } //SpeciesThresholdHistogram.Process(timeStepRecord); logBuffer.Post(timeStepRecord); if (moveTask != null) { // Wait for 3MB to finish moving the animats moveTask.Wait(); // Pull in updated animat positions from 3MB for the next time step UpdateAnimatPositions(); } //var distance = Scenario.ScenarioSpecies[0].Animat.Locations[0].DistanceKilometers(firstAnimatPosition); //if (distance > 0.01) Debug.WriteLine(string.Format("{0}: First animat has moved {1:0.##} km from initial location", DateTime.Now, distance)); //Debug.WriteLine(string.Format("{0}: Finished time step {1} of {2}: {3:0%} complete", DateTime.Now, timeStepIndex, timeStepCount, Math.Round((float)timeStepIndex / timeStepCount, 3))); if (MovingAnimats & AnimateSimulation) Globals.Dispatcher.InvokeIfRequired(() => { foreach (var species in Scenario.ScenarioSpecies) species.UpdateMapLayers(); }); if (token.IsCancellationRequested) break; } if (processTask != null) processTask.Wait(); Globals.Dispatcher.InvokeIfRequired(UpdateHistogramDisplay); foreach (var layer in _modeFootprintMapLayers.SelectMany(layerSet => layerSet)) { var curLayer = layer; Globals.Dispatcher.InvokeIfRequired(() => MediatorMessage.Send(MediatorMessage.RemoveMapLayer, curLayer)); } Globals.Dispatcher.InvokeIfRequired(() => MediatorMessage.Send(MediatorMessage.RefreshMap, true)); logBuffer.Complete(); logBlock.Completion.Wait(); if (MovingAnimats) Shutdown3MB(); Debug.WriteLine("{0}: Simulation complete. Exposure count: {1}", DateTime.Now, _totalExposureCount); Debug.WriteLine("{0}: Exposures by species:", DateTime.Now); for (var i = 0; i < _exposuresBySpecies.Length; i++) Debug.WriteLine("{0}: Species: {1}, Exposures: {2}", DateTime.Now, Scenario.ScenarioSpecies[i].LatinName, _exposuresBySpecies[i]); //SpeciesThresholdHistogram.Display(); //NewModeThresholdHistogram.DebugDisplay(); }
private void ReportLoadSomethingProgress(PercentProgress progress) { LoadPercent = progress.Percent; StatusText = progress.Status; }