/// <summary> /// Will construct a InstrumentDataList from a PicesInstrumenDataBase. Keep in kind that /// PicesInstrumentData is a managed wrapper class for the unmanaged class 'InstrumentData' /// from the 'SipperInstruments' library. /// </summary> /// <param name="dbInstData"></param> public InstrumentDataList(PicesInstrumentDataList dbInstData) { if (dbInstData == null) { return; } foreach (PicesInstrumentData id in dbInstData) { Add(new InstrumentData(id)); } }
} /* LoadAllImages */ /* * 2013-03-14 Kurt Kramer, as per email from A. Remsen * Commenting out this procedure because the database only consists of Oil cruises * It was originally created when there were only a few deployments that had images * identified as oil. * * * private List<ImageEntry> LoadOilDeploymentImages () * { * RunLogAddMsg ("Loading Source Images\n"); * * List<ImageEntry> allImages = new List<ImageEntry> (); * * { * List<String[]> sipperFileNamesList = new List<String[]>(); * sipperFileNamesList.Add(dbConn.SipperFileGetList ("SMP751001", "034", "")); * sipperFileNamesList.Add(dbConn.SipperFileGetList ("SMP751001", "035", "")); * sipperFileNamesList.Add(dbConn.SipperFileGetList ("SMP751001", "037", "")); * * int totalNumSipperFiles = sipperFileNamesList[0].Length + sipperFileNamesList[1].Length + sipperFileNamesList[2].Length; * sipperFileNames = new String[totalNumSipperFiles]; * int sipperFileNum = 0; * foreach (String[] names in sipperFileNamesList) * { * foreach (String sipperFileName in names) * { * sipperFileNames[sipperFileNum] = sipperFileName; * sipperFileNum++; * } * } * } * * foreach (String sipperFileName in sipperFileNames) * { * if (cancelHarvesting) * break; * * RunLogAddMsg ("Loading Sipper File[" + sipperFileName + "]" + "\n"); * * PicesDataBaseImageList images = dbConn.ImagesQuery (null, // ImageGroup * sipperFileName, * selClass, // * classKeyToUse, // * 0.0f, 1.0f, // Prob Min and Max * sizeMin, sizeMax, // Size Min and Max * 0, 0, // Depth Min and Max * 0, // restartImageFileName * -1, // limit to load -1 = Load All * false // false = Don't load thumbnail * ); * * if (images == null) * { * RunLogAddMsg ("Loading Sipper File[" + sipperFileName + "] No images found in database." + "\n"); * } * else * { * foreach (PicesDataBaseImage i in images) * { * float depth = i.Depth; * if (depth >= minimumDepth) * allImages.Add (new ImageEntry (i.ImageId, depth)); * } * RunLogAddMsg ("Loading Sipper File[" + sipperFileName + "] [" + images.Count.ToString ("##,###,##0") + "] Loaded" + "\n"); * } * } * * return allImages; * } /* LoadOilDeploymentImages * / */ //* Will build an array that will represent the times spent at each depth increment. //* This will be done by scanning the InstrumentData for all the sipper files involved //* and counting the number of scan lines at each depth. private double[] LoadDepthTimeProfile(PicesDataBase connThread) { RunLogAddMsg("Extracting Depth/Time profile" + "\n"); int numIncrements = (int)Math.Floor((float)maxDepth / (float)depthIncrement); double[] depthTimeProfile = new double[numIncrements]; foreach (String sipperFileName in sipperFileNames) { if (cancelHarvesting) { break; } RunLogAddMsg("Loading InstrumentData Sipper File[" + sipperFileName + "]" + "\n"); PicesInstrumentDataList data = connThread.InstrumentDataLoad(sipperFileName); if ((data == null) || (data.Count < 1)) { RunLogAddMsg("Loading InstrumentData Sipper File[" + sipperFileName + "] NO DATA LOADED" + "\n"); } else { RunLogAddMsg("Loading InstrumentData Sipper File[" + sipperFileName + "] [" + data.Count.ToString("###,##0") + "] Entries loaded" + "\n"); uint lastScanLine = data[0].ScanLine; for (int idx = 1; idx < data.Count; idx++) { PicesInstrumentData id = data[idx]; uint scanLine = id.ScanLine; uint deltaScanLines = scanLine - lastScanLine; int depthIdx = (int)Math.Floor(id.Depth / depthIncrement); if (depthIdx < 0) { depthIdx = 0; } else if (depthIdx >= depthTimeProfile.Length) { depthIdx = depthTimeProfile.Length - 1; } depthTimeProfile[depthIdx] += (double)deltaScanLines; lastScanLine = scanLine; } } } return(depthTimeProfile); } /* LoadDepthTimeProfile */
} /* FindScanRates */ private PicesInstrumentDataList StripOutObviouslyBadrecs(PicesInstrumentDataList src) { PicesInstrumentDataList dst = new PicesInstrumentDataList(); foreach (PicesInstrumentData id in src) { if ((id.Temperature > 0.0f) && (id.Temperature <= 40.0f) && (id.Salinity > 20.0f) && (id.Salinity <= 40.0f) && (id.Density > 18.0f) && (id.Density <= 40.0f) && (id.Fluorescence > 0.0f) && (id.CtdDate.Year > 2000) ) { dst.Add(id); } } return(dst); } /* StripOutObviouslyBadrecs */
} /* ProcessSipperFiles*/ void ProcessSipperFile(String sfn) { PicesSipperFile sipperFile = dbConn.SipperFileRecLoad(sfn); if (sipperFile == null) { RunLogAddMsg("\n\n ***ERROR*** Sipper File[" + sfn + "] not defined in database.\n\n"); return; } if (instrumentDataFileManager == null) { instrumentDataFileManager = new PicesInstrumentDataFileManager(); } PicesInstrumentDataList data = instrumentDataFileManager.ReExtractInstrumentDataForSipperFile(sfn, sipperFile, runLog); if (cancelRequested) { return; } if (data == null) { RunLogAddMsg("\n\n ***ERROR*** Sipper File[" + sfn + "] returned no Instrument Data.\n\n"); return; } RunLogAddMsg("Saving Instrument Data; SipperFileName[" + sfn + "].\n"); dbConn.InstrumentDataSaveListForOneSipperFile(sfn, data); if (cancelRequested) { return; } uint lastScanLine = 0; { RunLogAddMsg("Updating Images Table; SipperFileName[" + sfn + "].\n"); int c1 = 0; foreach (PicesInstrumentData id in data) { if (cancelRequested) { break; } if (id.ScanLine > 0) { dbConn.ImageUpdateInstrumentDataFields(id, sfn, lastScanLine, id.ScanLine); } lastScanLine = id.ScanLine; c1++; if ((c1 % 25) == 0) { RunLogAddMsg("Updating Images Table; SipperFileName[" + sfn + "] ScanLine[" + lastScanLine.ToString("###,###,##0") + "]\n"); } } } } /* ProcessSipperFile*/
} /* DatePicesInstrumentComparer */ private void SummarizeInstrumentDataForADeployment() { PicesInstrumentDataList data = dbConn.InstrumentDataLoad(cruiseName, stationName, deploymentNum); // We will assume that all entries are in order of date and time. We want // to first decide where the break in UpCast and Down cast occur. if ((data == null) || (data.Count < 1)) { MessageBox.Show("There is no Instrument Data for Cruise[" + cruiseName + "] Station[" + stationName + " Deployment [" + deploymentNum + "]"); return; } // Will now locate the InstrumentData record that separates the DownCast from the UpCast data.Sort(DatePicesInstrumentComparer); int idx; float maxDepth = -9999.9f; int maxDepthIdx = -9999; for (idx = 0; idx < data.Count; idx++) { if (data[idx].Depth > maxDepth) { maxDepth = data[idx].Depth; maxDepthIdx = idx; } } DateTime refTime = new DateTime(1999, 1, 1); DateTime startTime = new DateTime(1999, 1, 1); bool startTimeSet = false; InstrumentDataList downCast = new InstrumentDataList(); InstrumentDataList upCast = new InstrumentDataList(); for (idx = 0; idx < data.Count; idx++) { PicesInstrumentData pid = data[idx]; if (pid.CtdDate.CompareTo(refTime) < 0) { continue; } if ((idx % 4) == 0) { if (!startTimeSet) { startTime = pid.CtdDate; startTimeSet = true; } if (idx <= maxDepthIdx) { downCast.Add(new InstrumentData(pid)); } else { upCast.Add(new InstrumentData(pid)); } } } DateTime endTime = data[data.Count - 1].CtdDate; data = null; String title = cruiseName + "-" + stationName + "-" + deploymentNum + " From [" + startTime.ToString("u") + "] to [" + endTime.ToString("u") + "]"; { upCastPlot = new DepthPlot2(configRec, downCast, title + " Down Cast"); upCastPlot.Show(parent); } { downCastPlot = new DepthPlot2(configRec, upCast, title + " Up Cast"); downCastPlot.Show(parent); } } /* SummarizeInstrumentDataForADeployment */
} /* LoadImageDepthStats */ private void SummarizeInstrumentDataForADeployment(PicesDataBase threadConn, String cruiseName, String stationName, String deploymentNum ) { RunLogAddMsg("\nStart Report " + cruiseName + "-" + stationName + "-" + deploymentNum); PicesInstrumentDataList data = threadConn.InstrumentDataLoad(cruiseName, stationName, deploymentNum); // We will assume that all entries are in order of date and time. We want // to first decide where the break in UpCast and Down cast occur. if (cancelBackGround) { return; } data = StripOutObviouslyBadrecs(data); if ((data == null) || (data.Count < 1)) { RunLogAddMsg("There is no Instrument Data for Cruise[" + cruiseName + "] Station[" + stationName + "] Deployment [" + deploymentNum + "]"); return; } RunLogAddMsg("Number Entries Loaded[" + data.Count.ToString() + "]"); data.Sort(DatePicesInstrumentComparer); int idx; float maxDepth = -9999.9f; int maxDepthIdx = -9999; for (idx = 0; idx < data.Count; idx++) { if (data[idx].Depth > maxDepth) { maxDepth = data[idx].Depth; maxDepthIdx = idx; } } DateTime refTime = new DateTime(1999, 1, 1); DateTime startTime = new DateTime(1999, 1, 1); bool startTimeSet = false; InstrumentDataList downCast = new InstrumentDataList(); InstrumentDataList upCast = new InstrumentDataList(); for (idx = 0; idx < data.Count; idx++) { PicesInstrumentData pid = data[idx]; if (pid.CtdDate.CompareTo(refTime) < 0) { continue; } if (!startTimeSet) { startTime = pid.CtdDate; startTimeSet = true; } if (idx <= maxDepthIdx) { downCast.Add(new InstrumentData(pid)); } else { upCast.Add(new InstrumentData(pid)); } } DateTime endTime = data[data.Count - 1].CtdDate; data = null; String title = cruiseName + "-" + stationName + "-" + deploymentNum + " From [" + startTime.ToString("u") + "] to [" + endTime.ToString("u") + "]"; reportFileName = OSservices.AddSlash(reportFileDir) + cruiseName + "-" + stationName + "-" + deploymentNum; if (mlClass != null) { reportFileName += "-" + mlClass.Name; } reportFileName += "_InsrumentSumary.txt"; System.IO.StreamWriter o = null; try { o = new System.IO.StreamWriter(reportFileName); } catch (Exception e) { RunLogAddMsg("Error opening file[" + reportFileName + "] for output." + "\n\n" + e.ToString()); return; } if (threadConn != null) { o.WriteLine("DataBase" + "\t" + threadConn.Server.DataBaseName); } o.WriteLine("Cruise" + "\t" + cruiseName); o.WriteLine("Station" + "\t" + stationName); o.WriteLine("Deployment" + "\t" + deploymentNum); o.WriteLine("StartTime" + "\t" + startTime.ToString("u")); o.WriteLine("EndTime" + "\t" + endTime.ToString("u")); o.WriteLine(); float scanRateMin = 0.0f; float scanRateMax = 0.0f; float scanRate = 0.0f; RunLogAddMsg("Getting Particle Counts"); List <ImagesDepthStats> downCastImageStats = null; List <ImagesDepthStats> upCastImageStats = null; LoadImageDepthStats(threadConn, cruiseName, stationName, deploymentNum, ref downCastImageStats, ref upCastImageStats); RunLogAddMsg("Determining Scan Rate"); FindScanRates(threadConn, cruiseName, stationName, deploymentNum, ref scanRateMin, ref scanRateMax); if (scanRateMin == scanRateMax) { scanRate = scanRateMin; RunLogAddMsg("ScanRate [" + scanRateMin.ToString("###,##0.00") + "]"); } else { RunLogAddMsg("Scan Rates Were not consistent, you should update Sipper Files."); RunLogAddMsg(" scanRateMin [" + scanRateMin.ToString("###,##0.00") + "]" + " scanRateMax [" + scanRateMax.ToString("###,##0.00") + "]" ); o.WriteLine("Scan Rates Were not consistent, you should update Sipper Files."); o.WriteLine(" scanRateMin [" + scanRateMin.ToString("###,##0.00") + "]" + " scanRateMax [" + scanRateMax.ToString("###,##0.00") + "]" ); o.WriteLine(); } o.WriteLine("ScanRate" + "\t" + scanRateMin.ToString("###,##0.00")); o.WriteLine(); o.WriteLine(); o.WriteLine("Depth" + "\t" + "ScanLines" + "\t" + "Duration" + "\t" + "ImageCount" + "\t" + "TotalPixelCount" + "\t" + "FlowRate" + "\t" + "\t" + "Temperature" + "\t" + "\t" + "Oxygen" + "\t" + "\t" + "OxygenSensor" + "\t" + "\t" + "Salinity" + "\t" + "\t" + "Density" + "\t" + "\t" + "Fluoresce" + "\t" + "\t" + "FluorensceSensor" + "\t" + "\t" + "Transitivity" + "\t" + "\t" + "TransmissivitySensor" + "\t" + "\t" + "Turbidity" + "\t" + "\t" + "TurbiditySensor" + "\t" + "\t" + "RecordRate" ); WriteDepthSummary(o, downCast, downCastImageStats, scanRate); o.WriteLine(); if (!cancelBackGround) { WriteDepthSummary(o, upCast, upCastImageStats, scanRate); } if (cancelBackGround) { o.WriteLine(); o.WriteLine(); o.WriteLine(); o.WriteLine("Report Canceled by user request"); } o.Close(); } /* SummarizeInstrumentDataForADeployment */