} /* RunLogAddMsg */ private void RunLogMsgQueueFlush() { String msg = runLogMsgQueue.GetNextMsg(); while (msg != null) { RunLog.AppendText(msg + "\n"); backGroundLog.Writeln(msg); msg = runLogMsgQueue.GetNextMsg(); } } /* RunLogMsgQueueFlush */
} /* ToCmdLine */ private void ImportImagesIntoDeploymentProcess() { importingRunning = true; importingCompleted = false; PicesDataBase.ThreadInit(); PicesRunLog runLog = new PicesRunLog(); PicesDataBase threadConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); extractionLogEntryId = threadConn.LogEntriesProcessStart("II", "ImportImagesIntoDeployment", ExecutableDateTimeStamp(), ToCmdLine(), "" ); totalImagesUpdated = 0; ImportImagesFromDirectoryStructure(threadConn, sourceDirectory); if (cancelImporting) { runLog.Writeln("\n" + "Importing Images has been Canceled." + "\n\n"); } else { runLog.Writeln("\n\n" + "Total Images[" + totalImagesUpdated.ToString("###,##0") + "\n\n"); } threadConn.Close(); threadConn = null; GC.Collect(); PicesDataBase.ThreadEnd(); importingRunning = false; importingCompleted = true; } /* ImportImagesIntoDeploymentProcess */
} /* RunLogAddMsg */ private void RunLogMsgQueueFlush() { runLogGoalie.StartBlock(); if (runLogMsgQueue != null) { while (runLogMsgQueue.Count > 0) { String msg = runLogMsgQueue.Dequeue(); RunLog.AppendText(msg + "\n"); backGroundLog.Writeln(msg); } } runLogGoalie.EndBlock(); } /* RunLogMsgQueueFlush */
} /* SuperScriptExponent */ private void UpdateChartAreas() { if (integratedDensityDistribution == null) { return; } goalie.StartBlock(); String t1 = "Abundance by Size"; switch (statistic) { case '0': t1 = "Abundance by Size"; break; case '1': t1 = "Abundance by Estimated Diameter"; break; case '2': t1 = "Abundance by Estimated Spheroid Volume"; break; case '3': t1 = "Abundance by Estimated Ellipsoid Volume"; break; } String t2 = "Cruise: " + cruise + " Station: " + station; if (String.IsNullOrEmpty(deployment)) { t2 += " Deployment: " + deployment; } t2 += " Class: " + classToPlot.Name; ProfileChart.Titles.Clear(); ProfileChart.Titles.Add(new Title(t1, Docking.Top, titleFont, Color.Black)); ProfileChart.Titles.Add(new Title(t2, Docking.Top, titleFont, Color.Black)); if (!String.IsNullOrEmpty(criteriaStr)) { ProfileChart.Titles.Add(new Title(criteriaStr, Docking.Top, titleFont, Color.Black)); } ProfileChart.Series.Clear(); ChartArea ca = ProfileChart.ChartAreas[0]; Series s = new Series("Size Distribution"); s.ChartArea = "ChartArea1"; s.ChartType = SeriesChartType.Column; float[] startValues = bucketsDisplayed.SizeStartValues(); float[] endValues = bucketsDisplayed.SizeEndValues(); float minX = float.MaxValue; float minY = float.MaxValue; float maxX = float.MinValue; float maxY = float.MinValue; List <CustomLabel> customLabels = new List <CustomLabel> (); for (int x = 0; x < integratedDensityDistribution.Length; ++x) { float sv = startValues[x]; float ev = sv * growthRate; if (sv <= 0.0f) { sv = initialSizeValue / growthRate; ev = initialSizeValue; } float midPoint = (sv + ev) / 2.0f; { double svLog10 = Math.Log10(sv); double evLog10 = Math.Log10(ev); CustomLabel cl = null; if (midPoint < 1.0f) { cl = new CustomLabel(svLog10, evLog10, midPoint.ToString("#0.000"), 0, LabelMarkStyle.SideMark); } else if (midPoint < 10.0f) { cl = new CustomLabel(svLog10, evLog10, midPoint.ToString("#0.00"), 0, LabelMarkStyle.SideMark); } else if (midPoint < 100.0f) { cl = new CustomLabel(svLog10, evLog10, midPoint.ToString("##0.0"), 0, LabelMarkStyle.SideMark); } else { cl = new CustomLabel(svLog10, evLog10, midPoint.ToString("##,##0"), 0, LabelMarkStyle.SideMark); } customLabels.Add(cl); } double d = (double)integratedDensityDistribution[x]; float log10D = (float)Math.Log10(d + 1.0); minY = Math.Min(minY, log10D); maxY = Math.Max(maxY, log10D); minX = Math.Min(minX, midPoint); maxX = Math.Max(maxX, midPoint); DataPoint dp = new DataPoint(midPoint, log10D); s.Points.Add(dp); } s.XAxisType = AxisType.Primary; s.YAxisType = AxisType.Primary; ProfileChart.ChartAreas[0].AxisY.LogarithmBase = 10.0; ProfileChart.ChartAreas[0].AxisY.LabelStyle.Format = "##,###,##0"; { ca.AxisX.CustomLabels.Clear(); ca.AxisX.CustomLabels.Add(customLabels[1]); int n = 8; float interSpace = (float)customLabels.Count / (float)(n + 1); for (int x = 1; x <= n; ++x) { int idx = 1 + (int)((float)x * interSpace + 0.5f); ca.AxisX.CustomLabels.Add(customLabels[idx]); } ca.AxisX.CustomLabels.Add(customLabels[customLabels.Count - 1]); } ca.AxisY.Title = SubInSuperScriptExponent("Log 10 Abundance"); switch (statistic) { case '0': ca.AxisX.Title = SubInSuperScriptExponent("area(m-2)"); //ca.AxisX.LabelStyle.Format = "##,##0.000"; break; case '1': ca.AxisX.Title = SubInSuperScriptExponent("Length(mili-meters)"); //ca.AxisX.LabelStyle.Format = "##00.00"; break; case '2': ca.AxisX.Title = SubInSuperScriptExponent("Volume(mm-3)"); //ca.AxisX.LabelStyle.Format = "##0.0000"; break; case '3': ca.AxisX.Title = SubInSuperScriptExponent("Volume(mm-3)"); //ca.AxisX.LabelStyle.Format = "##0.0000"; break; } ca.AxisX.IsLogarithmic = true; //ca.AxisX.Minimum = 0.0; ca.AxisX.Maximum = maxX; ca.AxisX.LabelStyle.Angle = 45; ca.AxisX.LabelStyle.Font = axisLabelFont; ca.AxisX.TitleFont = axisLabelFont; ca.AxisY.Minimum = 0.0; ca.AxisY.IsLogarithmic = false; ca.AxisY.LabelStyle.Font = axisLabelFont; ca.AxisY.TitleFont = axisLabelFont; //ca.AxisX.IsLogarithmic = true; s.BorderWidth = 2; ProfileChart.Series.Add(s); try { ProfileChart.ChartAreas[0].RecalculateAxesScale(); } catch (Exception e) { runLog.Writeln(e.ToString()); } goalie.EndBlock(); } /* UpdateChartAreas */
} /* StartReconciliationThread */ private void ReconciliationThread() { reconcilingRunLog.SetLoggingLevel(10); reconcilingRunLog.Writeln("Source Directory [" + SourceDirectory.Text + "]" + "\n"); reconcilingRunLog.Writeln("Start Date/Time [" + DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss") + "]" + "\n"); reconcilingRunLog.Writeln("Active DataBase [" + dbConn.Server.Description + "]" + "\n"); reconcilingRunning = true; String rootDir = SourceDirectory.Text; DirectoryInfo di = null; try { di = new DirectoryInfo(rootDir); } catch (Exception) { di = null; } if (di == null) { return; } CountDirectory(di); if (!cancelReconciling) { reconcilingRunLog.Writeln("Total Images To Process[" + runStatsTotalImages.ToString("###,###,##0") + "]" + "\n"); ProcessDirectory(di); } reconcilingRunLog.Writeln("Total Images" + "\t" + runStatsTotalImages.ToString("###,###,##0")); reconcilingRunLog.Writeln("In Database" + "\t" + runStatsImagesInDataBase.ToString("###,###,##0")); reconcilingRunLog.Writeln("Not Found" + "\t" + runStatsImagesNotInDataBase.ToString("###,###,##0")); reconcilingRunLog.Writeln("Fixed" + "\t" + runStatsImagesFixed.ToString("###,###,##0")); reconcilingRunning = false; } /* ProcessAllDirectories */
} /* SuperScriptExponent */ private void UpdateChartAreas() { goalie.StartBlock(); bool plotLogDensity = PlotLogDensity.Checked; String t1 = "Abundance by Size"; switch (statistic) { case '0': t1 = "Abundance by Size"; break; case '1': t1 = "Abundance by Diameter (ESD)"; break; case '2': t1 = "Abundance by Volume (EBv"; break; case '3': t1 = "Abundance by Estimated Ellipsoid Volume"; break; } String t2 = cruise + "-" + station; if (!String.IsNullOrEmpty(deployment)) { t2 += ("-" + deployment); } t2 += (" " + classToPlot.Name); t2 += " "; t2 += (cast + "-Cast" + " Size-Range(" + sizeStart.ToString() + " - " + sizeEnd.ToString() + ")"); ProfileChart.Titles.Clear(); ProfileChart.Titles.Add(new Title(t1, Docking.Top, titleFont, Color.Black)); ProfileChart.Titles.Add(new Title(t2, Docking.Top, titleFont, Color.Black)); //ProfileChart.Titles.Add (new Title (t3, Docking.Top, titleFont, Color.Black)); ProfileChart.Series.Clear(); ChartArea ca1 = ProfileChart.ChartAreas[0]; ChartArea ca2 = ProfileChart.ChartAreas[1]; Series s = new Series("Size Distribution"); s.ChartArea = "ChartArea1"; s.ChartType = SeriesChartType.Line; Series s2 = new Series("Volume Sampled"); s2.ChartArea = "ChartArea2"; s2.ChartType = SeriesChartType.Line; float minX = float.MaxValue; float minY = float.MaxValue; float maxX = float.MinValue; float maxY = float.MinValue; int numDepthBins = sizeDistribution.NumDepthBins; for (uint depthBin = 0; depthBin < numDepthBins; ++depthBin) { PicesImageSizeDistributionRow row = sizeDistribution.GetDepthBin(depthBin); if (row == null) { continue; } float depth = row.Depth; double density = 0.0; if (depthBin < depthProfile.Length) { density = (double)depthProfile[depthBin]; } if (plotLogDensity) { density = (float)Math.Log10(density + 1.0); } minX = Math.Min(minX, (float)density); maxX = Math.Max(maxX, (float)density); minY = Math.Min(minY, depth); maxY = Math.Max(maxY, depth); DataPoint dp = new DataPoint(density, depth); s.Points.Add(dp); double vs = 0.0; if (depthBin < volumeSampled.Length) { vs = volumeSampled[depthBin]; } DataPoint dp2 = new DataPoint(vs, depth); s2.Points.Add(dp2); } s.XAxisType = AxisType.Primary; s.YAxisType = AxisType.Primary; s2.XAxisType = AxisType.Primary; s2.YAxisType = AxisType.Primary; s2.Color = Color.Black; if (plotLogDensity) { ca1.AxisX.Title = SubInSuperScriptExponent("Log 10 Abundance"); } else { ca1.AxisX.Title = SubInSuperScriptExponent("Abundance"); } ca1.AxisY.Title = SubInSuperScriptExponent("Depth (Meters)"); ca1.AxisY.LabelStyle.Format = "##,##0"; ca1.AxisX.IsLogarithmic = false; ca1.AxisX.Minimum = 0.0; //ca1.AxisX.Maximum = maxX; ca1.AxisX.LabelStyle.Angle = 90; ca1.AxisX.LabelStyle.Font = axisLabelFont; ca1.AxisX.TitleFont = axisLabelFont; ca1.AxisY.Minimum = 0.0; ca1.AxisY.IsLogarithmic = false; ca1.AxisY.LabelStyle.Font = axisLabelFont; ca1.AxisY.TitleFont = axisLabelFont; if (plotLogDensity) { ca1.AxisX.LabelStyle.Format = "##,##0.0"; } else { ca1.AxisX.LabelStyle.Format = "##,##0"; } ca2.AxisX.Title = SubInSuperScriptExponent("Volume Sampled (mm-3)"); ca2.AxisX.Minimum = 0.0; ca2.AxisX.IsLogarithmic = false; ca2.AxisX.LabelStyle.Font = axisLabelFont; ca2.AxisX.TitleFont = axisLabelFont; ca2.AxisX.LabelStyle.Format = "##0.00"; ca2.AxisX.LabelStyle.Angle = 90; s.BorderWidth = 2; ProfileChart.Series.Add(s); ProfileChart.Series.Add(s2); try { ProfileChart.ChartAreas[0].RecalculateAxesScale(); } catch (Exception e) { runLog.Writeln(e.ToString()); } goalie.EndBlock(); } /* UpdateChartAreas */
private void ImportImage(PicesDataBase threadConn, String sipperFileRootName, String fileName, ref bool successful ) { successful = false; String rootName = OSservices.GetRootName(fileName); String picesRootName = sipperFileRootName + "_" + rootName; PicesDataBaseImage dbi = threadConn.ImageLoad(picesRootName); if (dbi != null) { return; } PicesRaster r = new PicesRaster(fileName); r = r.RemoveZooscanBrackets(); PicesFeatureVector fv = new PicesFeatureVector(r, picesRootName, null, runLog); fv.ExampleFileName = picesRootName; int imageId = 0; uint centroidRow = (uint)(0.5f + fv.CentroidRow); uint centroidCol = (uint)(0.5f + fv.CentroidCol); if ((centroidRow < 0) || (centroidRow > r.Height)) { centroidRow = (uint)(r.Height / 2); } if ((centroidCol < 0) || (centroidCol > r.Width)) { centroidCol = (uint)(r.Width / 2); } threadConn.ImageInsert(r, picesRootName, sipperFileRootName, 0, 0, 0, (uint)r.Height, (uint)r.Width, (uint)fv.OrigSize, 3, extractionLogEntryId.LogEntryId, extractionLogEntryId.LogEntryId, centroidRow, centroidCol, unknownClass, 1.0f, null, 0.0f, null, 0.0f, // depth, 0.0f, // Image Size null, ref imageId, ref successful ); if (successful) { threadConn.FeatureDataInsertRow(sipperFileRootName, fv); } else { runLog.Writeln("RootName[" + rootName + "] Failed: " + threadConn.LastErrorDesc() + "\n"); } } /* ImportImage */
} /* ProcessOneFeatureVector */ private PicesClass UpdateClassId(PicesClass mlClass) { // We lock 'predictionUpdateQueue' because all other classification processes refer to it. // lock (predictionUpdateQueue) { // Maybe another Classification process already updated the database and hence updated the classId field. if (mlClass.ClassId >= 0) { //int zed = 888; } else { String className = mlClass.Name; String parentName = mlClass.ParentName; if (String.IsNullOrEmpty(parentName)) { parentName = "AllClasses"; mlClass.Parent = PicesClassList.GetUniqueClass(parentName, ""); } if (runLog == null) { runLog = new PicesRunLog(); } PicesDataBase dbConn = null; if (dbServer == null) { dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); } else { dbConn = new PicesDataBase(dbServer, runLog); } mlClass.Description = "Added by 'Classification'"; dbConn.MLClassInsert(mlClass); if (mlClass.ClassId < 0) { PicesClass pc = dbConn.MLClassLoad(className); if (mlClass.ClassId < 0) { runLog.Writeln("ClassifierProcess.UpdateClassId ***ERROR*** mlClass.ClassId < 0 ClassName[" + className + "]"); } } // I do not know what the impact of opening and closing a lot of connections // to the MySQL data base will be, and since this method should only get called // when a new MLClass is introduced I want to sleep a little to make // sure that we do not over stress resources that I am not aware of. Thread.Sleep(100); //dbConn.Close (); dbConn = null; GC.Collect(); } } return(mlClass); }