public PredictionBreakDownDisplay(PicesDataBase _dbConn, PicesDataBaseImage _image, PicesRaster _raster, TrainingModel2 _trainingModel, PicesInstrumentData _instrumentData, /*!< Instrument data that goes with image, if null will read from database. */ PicesRunLog _runLog ) { if (_runLog == null) { runLog = new PicesRunLog(); } else { runLog = _runLog; } if (_image == null) { return; } fileName = _image.ImageFileName; instrumentData = _instrumentData; trainingModel = _trainingModel; PicesRaster raster = _raster; if (_dbConn != null) { if (raster == null) { raster = _dbConn.ImageFullSizeFind(fileName); } if (instrumentData == null) { instrumentData = _dbConn.InstrumentDataGetByScanLine(_image.SipperFileName, _image.TopLeftRow); } dbFeatureVector = _dbConn.FeatureDataRecLoad(fileName); } if (raster == null) { return; } //raster = raster.ConnectedComponent (); featureCalcImages = new PicesRasterList(); featureVector = new PicesFeatureVector(raster, fileName, featureCalcImages, runLog); if (instrumentData != null) { featureVector.AddInstrumentData(instrumentData); } InitializeComponent(); }
/// <summary> /// Using supplied 'Raster' data it will call each currently active model and return there predictions. /// </summary> /// <param name="raster">Raster of image to predict. .</param> /// <param name="instrumentData">Instrument data that was recorded with the 'raster' .</param> /// <param name="imageFileName">Name of the image file.</param> /// <param name="model1Predictions">The model1 predictions.</param> /// <param name="model2Predictions">The model2 predictions.</param> /// <param name="runLog">The run log.</param> public static void MakePredictions(PicesRaster raster, InstrumentData instrumentData, String imageFileName, ref PicesPredictionList model1Predictions, ref PicesPredictionList model2Predictions, PicesRunLog runLog ) { model1Predictions = null; model2Predictions = null; if (!ModelsAreAvailable()) { return; } ParsedImageFileName pifn = PicesFeatureVector.ParseImageFileName(imageFileName); String sipperFileName = pifn.sipperFileName; uint scanLineNum = pifn.scanLineNum; PicesFeatureVector fv = new PicesFeatureVector(raster, imageFileName, null, runLog); if (instrumentData != null) { fv.AddInstrumentData(instrumentData.Depth(), instrumentData.Salinity(), instrumentData.Oxygen(), instrumentData.Fluorescence() ); } else { PicesDataBase dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); PicesInstrumentData pid = dbConn.InstrumentDataGetByScanLine(sipperFileName, scanLineNum); if (pid != null) { fv.AddInstrumentData(pid); } pid = null; dbConn.Close(); dbConn = null; } if (model1 != null) { model1Predictions = model1.PredictProbabilities(fv); } if (model2 != null) { model2Predictions = model2.PredictProbabilities(fv); } fv = null; return; } /* MakePredictions */
} /* CreateFeatureDataFileThread */ void MakeSureDepthFieldIsIncluded(PicesFeatureVectorList data) { PicesDataBase dbConn = null; PicesRunLog runLog = new PicesRunLog(dialogMsgQueue); data.SortByImageFileName(); String curSipperFileName = ""; float curSipperFileDepth = 0.0f; foreach (PicesFeatureVector fv in data) { if (fv.Depth == 0.0f) { if (dbConn == null) { dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); } uint sacnLineNum = 0; uint scanCol = 0; String nextSipperFileName = ""; PicesFeatureVector.ParseImageFileName(fv.ExampleFileName, ref nextSipperFileName, ref sacnLineNum, ref scanCol); if (nextSipperFileName != curSipperFileName) { curSipperFileDepth = 0.0f; curSipperFileName = nextSipperFileName; PicesSipperFile sf = dbConn.SipperFileRecLoad(curSipperFileName); if (sf != null) { curSipperFileDepth = sf.Depth; } } PicesInstrumentData id = dbConn.InstrumentDataGetByScanLine(curSipperFileName, sacnLineNum); if ((id == null) || (id.Depth == 0.0)) { fv.Depth = curSipperFileDepth; } else { fv.Depth = id.Depth; } } } if (dbConn != null) { dbConn.Close(); dbConn = null; GC.Collect(); } } /* MakeSureDepthFieldIsIncluded */
public PredictionBreakDownDisplayDual(PicesDataBase _dbConn, String _fileName, TrainingModel2 _trainingModel, PicesInstrumentData _instrumentData, /**< Instrument data that goes with image, if null will read from dtabase. */ PicesRunLog _runLog ) { if (_runLog == null) { runLog = new PicesRunLog(); } else { runLog = _runLog; } fileName = _fileName; instrumentData = _instrumentData; trainingModel = _trainingModel; PicesDataBase dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); PicesRaster raster = dbConn.ImageFullSizeFind(fileName); if (raster == null) { return; } if (_dbConn != null) { dbFeatureVector = _dbConn.FeatureDataRecLoad(_fileName); if (instrumentData == null) { PicesDataBaseImage image = dbConn.ImageLoad(fileName); if (image != null) { instrumentData = dbConn.InstrumentDataGetByScanLine(image.SipperFileName, image.TopLeftRow); } } } featureVector = new PicesFeatureVector(raster, fileName, null, runLog); if (instrumentData != null) { featureVector.AddInstrumentData(instrumentData); } dbConn.Close(); dbConn = null; GC.Collect(); InitializeComponent(); }
} /* MakePredictions */ public static void MakePredictions(PicesRaster raster, ref PicesPrediction model1Prediction1, ref PicesPrediction model1Prediction2, ref PicesPrediction model2Prediction1, ref PicesPrediction model2Prediction2, PicesRunLog runLog ) { String imageFileName = raster.FileName; ParsedImageFileName pifn = PicesFeatureVector.ParseImageFileName(imageFileName); String sipperFileName = pifn.sipperFileName; uint scanLineNum = pifn.scanLineNum; PicesFeatureVector fv = new PicesFeatureVector(raster, imageFileName, null, runLog); { PicesDataBase dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); PicesInstrumentData pid = dbConn.InstrumentDataGetByScanLine(sipperFileName, scanLineNum); if (pid != null) { fv.AddInstrumentData(pid); } pid = null; dbConn.Close(); dbConn = null; } MakePredictions(fv, ref model1Prediction1, ref model1Prediction2, ref model2Prediction1, ref model2Prediction2, runLog ); fv = null; }
public ImageViewer(PicesRaster _raster, PicesDataBaseImage _image, PicesClassList _classes ) { runLog = new PicesRunLog(); raster = _raster; classes = _classes; dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); image = _image; sizeCoordinates = image.SizeCoordinates; if (raster == null) { raster = PicesRaster.GetOrigSipperImage(image.SipperFileName, image.ByteOffset, image.TopLeftRow, image.TopLeftCol, image.Height, image.Width, image.ConnectedPixelDist, runLog ); } if (raster == null) { MessageBox.Show("Could not locate source image or SipperFile[" + image.SipperFileName + "]"); return; } { uint scanLine = image.TopLeftRow; scanLine = 4096 * (uint)(scanLine / 4096); instrumentData = dbConn.InstrumentDataGetByScanLine(image.SipperFileName, image.TopLeftRow); sipperFile = dbConn.SipperFileRecLoad(image.SipperFileName); } double pixelsPerScanLine = pixelsPerScanLineDefault; if (instrumentData != null) { if (instrumentData.ActiveColumns > 0) { pixelsPerScanLine = instrumentData.ActiveColumns; } if (instrumentData.FlowRate1 > 0.0) { flowRate1 = instrumentData.FlowRate1; } } if (sipperFile != null) { if (sipperFile.ScanRate > 0.0) { scanRate = sipperFile.ScanRate; } deployment = dbConn.SipperDeploymentLoad(sipperFile.CruiseName, sipperFile.StationName, sipperFile.DeploymentNum); if (deployment != null) { chamberWidth = deployment.ChamberWidth; } } if ((dataFieldAssignments == null) || (DataLabels == null)) { ConfigurationLoad(); } InitializeComponent(); if (image != null) { extractionLogEntry = dbConn.LogEntriesSelect(image.ExtractionLogEntryId); classLogEntry = dbConn.LogEntriesSelect(image.ClassLogEntryId); } mmPerPixelAccrossChamber = chamberWidth * mmPerMeter / pixelsPerScanLine; mmPerPixelWithFlow = mmPerMeter * flowRate1 / scanRate; DataLabels = new Label[4]; DataLabels[0] = DataLabel0; DataLabels[1] = DataLabel1; DataLabels[2] = DataLabel2; DataLabels[3] = DataLabel3; displayDataFields = new TextBox[4]; displayDataFields[0] = DataField0; displayDataFields[1] = DataField1; displayDataFields[2] = DataField2; displayDataFields[3] = DataField3; UpdateDataFields(); ImageFileName.Text = image.ImageFileName; }
private void SavePlanktonDataFile(PicesDataBaseImageList planktonData) { String errMsg = ""; StreamWriter sw = null; try { sw = new StreamWriter(dataFileName); } catch (Exception e1) { errMsg = e1.ToString(); } if (sw == null) { errMsg = "Could not open Data File[" + dataFileName + "]\n" + errMsg; return; } sw.WriteLine("//This file was generated by the PICESComander application."); sw.WriteLine(); sw.WriteLine("DateTime" + "\t" + DateTime.Now.ToString("yyyy/MM/dd - hh:mm:ss")); sw.WriteLine("DataBase" + "\t" + dbConn.ServerDescription()); sw.WriteLine("MachineName" + "\t" + System.Environment.MachineName); sw.WriteLine(); sw.WriteLine("//Selection Criteria"); WriteValue(sw, "GroupName", GroupName.Text); WriteValue(sw, "CruiseName", CruiseName.Text); WriteValue(sw, "StationName", StationName.Text); WriteValue(sw, "DeploymentNum", DeploymentNum.Text); WriteValue(sw, "SipperFile", SipperFile.Text); if (mlClass != null) { WriteValue(sw, "MLClass", mlClass.Name); } sw.WriteLine("Probability Min-Max" + "\t" + (100.0f * probMin).ToString("##0.00") + "\t" + (100.0f * probMax).ToString("##0.00")); if ((depthMin > 0.0f) || (depthMax > 0.0f)) { sw.WriteLine("Depth" + "\t" + depthMin.ToString("###0.00") + "\t" + depthMax.ToString("###0.00")); } if ((sizeMin > 0) || (sizeMax > 0)) { sw.WriteLine("Size" + "\t" + sizeMin.ToString("#####0") + "\t" + sizeMax.ToString("######0")); } sw.WriteLine("ClassKeyToUse" + "\t" + classKeyToUse.ToString()); sw.WriteLine(); sw.WriteLine("Count" + "\t" + planktonData.Count); sw.WriteLine(); sw.WriteLine("//Following specifies column headers."); sw.Write("ImageFileName"); sw.Write("\t"); sw.Write("Class1Name"); sw.Write("\t"); sw.Write("Class1Prob"); sw.Write("\t"); sw.Write("Class2Name"); sw.Write("\t"); sw.Write("Class2Prob"); sw.Write("\t"); sw.Write("Depth(M)"); sw.Write("\t"); sw.Write("PixelCount"); sw.Write("\t"); sw.Write("Height"); sw.Write("\t"); sw.Write("Width"); sw.Write("\t"); sw.Write("TopLeftRow"); sw.Write("\t"); sw.Write("TopLeftCol"); sw.Write("\t"); sw.Write("CtdDate"); sw.Write("\t"); sw.Write("Latitude"); sw.Write("\t"); sw.Write("Longitude"); sw.Write("\t"); sw.Write("Temperature(C)"); sw.WriteLine(); planktonData.Sort(PicesDataBaseImageList.SortOrderType.soSpatial, false); PicesInstrumentData id = null; uint nextScanLineThreshold = 0; String lastSipperFileName = ""; foreach (PicesDataBaseImage i in planktonData) { if ((i.TopLeftRow >= nextScanLineThreshold) || (i.SipperFileName != lastSipperFileName) ) { uint scanLineCleared = 0; uint scanLine = i.TopLeftRow; scanLine = 4096 * (uint)(scanLine / 4096); id = dbConn.InstrumentDataGetByScanLine(i.SipperFileName, scanLine); lastSipperFileName = i.SipperFileName; if (id == null) { scanLineCleared = scanLine; } else { scanLineCleared = id.ScanLine; if (scanLineCleared > scanLine) { if ((scanLineCleared - scanLine) > 4096) { id = null; } } } nextScanLineThreshold = scanLineCleared + 4096; } sw.Write(i.ImageFileName); sw.Write("\t"); sw.Write(i.Class1Name); sw.Write("\t"); sw.Write(i.Class1Prob.ToString("p")); sw.Write("\t"); sw.Write(i.Class2Name); sw.Write("\t"); sw.Write(i.Class2Prob.ToString("p")); sw.Write("\t"); sw.Write(i.Depth); sw.Write("\t"); sw.Write(i.PixelCount); sw.Write("\t"); sw.Write(i.Height); sw.Write("\t"); sw.Write(i.Width); sw.Write("\t"); sw.Write(i.TopLeftRow); sw.Write("\t"); sw.Write(i.TopLeftCol); if (id != null) { sw.Write("\t"); sw.Write(id.CtdDate.ToString("yyyy/MM/dd - HH:mm:ss")); sw.Write("\t"); sw.Write(id.Latitude); sw.Write("\t"); sw.Write(id.Longitude); sw.Write("\t"); sw.Write(id.Temperature); } sw.WriteLine(); ++imagesWritten; } sw.WriteLine("//All Data Written."); sw.Close(); }