public DepthPlotParameters(Panel _chartPanel, Ruler[] _rulers, VScrollBar _domainScrollBar, int[,] _fieldIdxs, InstrumentDataList _history ) { int x; chartPanel = _chartPanel; rulers = _rulers; domainScrollBar = _domainScrollBar; fieldIdxs = _fieldIdxs; history = _history; seriesToPlot = new bool[maxNumDataSets]; for (x = 0; x < maxNumDataSets; x++) { seriesToPlot[x] = true; } AssignColors(); CalcChartVariables(); }
public Demo(IDriverEx driver, IDDK ddk, Config.Demo config, string id, InstrumentDataList instrumentDataList, string driverFolder) : base(driver, ddk, config, typeof(Demo).Name, id) { Log.TaskBegin(Id); try { if (string.IsNullOrEmpty(driverFolder)) { throw new ArgumentNullException("driverFolder"); } if (instrumentDataList == null) { throw new ArgumentNullException("instrumentDataList"); } m_Properties = new DemoProperties(driver, m_DDK, config, m_Device); //------------------------------------------------------------------------------------------------------------------- if (m_DDK.InstrumentMap == null) { throw new InvalidOperationException("DDK.InstrumentMap is Null"); } long instrumentsMap = m_DDK.InstrumentMap.Value; if (instrumentsMap == (long)InstrumentID.None) { throw new InvalidOperationException("DDK.InstrumentMap = " + instrumentsMap.ToString() + " must be != " + ((long)InstrumentID.None).ToString()); } string instrumentsMapBinary = InstrumentData.GetBitMapBinary(instrumentsMap); string instrumentsNames = instrumentDataList.GetNames(); bool logInFile = LogInFile; string fileNamePrefix = instrumentDataList[0].Name; Log.Init(Id, logInFile, fileNamePrefix); // Logging in a file starts here, if logInFile is True const string indent = "\t"; string text = Environment.NewLine + Environment.NewLine + indent + "Driver Folder \"" + driverFolder + "\"" + Environment.NewLine + indent + "Name \"" + Name + "\", IsSimulated = " + IsSimulated.ToString() + Environment.NewLine + indent + "USB Address \"" + UsbAddress + "\"" + Environment.NewLine + indent + "DDK.InstrumentMap = " + instrumentsMap.ToString() + " = " + instrumentsMapBinary + " = " + instrumentsNames + Environment.NewLine; Log.WriteLine(Id, text); //------------------------------------------------------------------------------------------------------------------- m_Properties.LogInFile.OnSetProperty += OnPropertyLogInFileSet; //------------------------------------------------------------------------------------------------------------------- CommandTestInit(); CommandStartStopInit(); Log.TaskEnd(Id); } catch (Exception ex) { Log.TaskEnd(Id, ex); throw; } }
void IDriver.Init(IDDK ddk) { m_DDK = ddk; string driverFolder = AppDomain.CurrentDomain.BaseDirectory; Log.TaskBegin(Id, "Driver Folder \"" + driverFolder + "\""); try { #region Instrument Data List long instrumentsMap = ddk.InstrumentMap.Value; if (instrumentsMap == (long)InstrumentID.None) { throw new InvalidOperationException("DDK.InstrumentMap = " + instrumentsMap.ToString() + " must be != " + ((long)InstrumentID.None).ToString()); } string instrumentsMapBinary = InstrumentData.GetBitMapBinary(instrumentsMap); Log.WriteLine(Id, "DDK.InstrumentMap = " + instrumentsMap.ToString() + " = " + instrumentsMapBinary); InstrumentDataList instrumentDataList = new InstrumentDataList(); instrumentDataList.Init(ddk, instrumentsMap); if (instrumentDataList.Count < 1) { throw new InvalidOperationException("Failed to get the instruments from the DDK.InstrumentMap = " + instrumentsMap.ToString() + " = " + instrumentsMapBinary); } #endregion m_Demo = new Demo((IDriverEx)this, ddk, m_Config.Demo, Config.Driver.DeviceId.Demo, instrumentDataList, driverFolder); AddDevice(m_Demo); //m_Heater = new Heater((IDriverEx)this, ddk, m_Config.Heater, Config.Driver.DeviceId.Heater); //AddDevice(m_Heater); //m_Pump = new Pump((IDriverEx)this, ddk, m_Config.Pump, Config.Driver.DeviceId.Pump); //AddDevice(m_Pump); //m_AutoSampler = new AutoSampler((IDriverEx)this, ddk, m_Config.AutoSampler, Config.Driver.DeviceId.AutoSampler); //AddDevice(m_AutoSampler); //m_Detector = new Detector((IDriverEx)this, ddk, m_Config.Detector, Config.Driver.DeviceId.Detector); //AddDevice(m_Detector); Log.TaskEnd(Id); } catch (Exception ex) { Log.TaskEnd(Id, ex); throw; } }
public void ValidateData() { InstrumentDataList instruments = new InstrumentDataList(m_InstrumentInfo, m_InstrumentsMap); if (m_RequiredMinInstruments > 0 && instruments.Count == 0) // At least {0} instruments must be selected. { throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.MinInstrumentsRequiredAreNotSelected, m_RequiredMinInstruments)); } if (m_RequiredMaxInstruments > 0 && instruments.Count > m_RequiredMaxInstruments) // More than the maximum of {0} instruments are selected. { throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.MoreThanMaxInstrumentsAreSelected, m_RequiredMaxInstruments)); } }
public string GetReportText(IInstrumentInfo instrumentInfo, long instrumentsMap) { if (instrumentInfo == null) { throw new ArgumentNullException("instrumentInfo"); } const string sprt = "\t"; StringBuilder sb = new StringBuilder(); sb.AppendLine("Driver " + sprt + Id); sb.AppendLine("Description" + sprt + Description); sb.AppendLine("IsSimulated" + sprt + Demo.IsSimulated.ToString()); sb.AppendLine("Firmware Version" + sprt + Demo.FirmwareVersion); sb.AppendLine("Serial Number" + sprt + Demo.SerialNo); sb.AppendLine("USB Address" + sprt + Demo.FirmwareUsbAddress); sb.AppendLine(); AddReportDevice(sb, sprt, Demo); sb.AppendLine("Name" + sprt + Demo.Name); sb.AppendLine(); AddReportDevice(sb, sprt, Heater); sb.AppendLine("Product Description" + sprt + Heater.ProductDescription); sb.AppendLine(); AddReportDevice(sb, sprt, Detector); sb.AppendLine("Property B" + sprt + Detector.ChannelsNumber.ToString(CultureInfo.InvariantCulture)); InstrumentDataList instruments = new InstrumentDataList(instrumentInfo, instrumentsMap); if (instruments.Count > 1) { string instrumentsText = instruments.GetNames(); AddReportParam(sb, sprt, "Shared in instruments", instrumentsText); } sb.AppendLine(); string result = sb.ToString(); return(result); }
} /* 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 */
} /* LocateImageDepthStats */ private void WriteDepthSummary(System.IO.StreamWriter o, InstrumentDataList cast, List <ImagesDepthStats> imageStats, float scanRate ) { int zed = 0; cast.SortByDepth(); InstrumentData id = (InstrumentData)(cast[0]); while ((id != null) && (!cancelBackGround)) { id = (InstrumentData)cast[zed]; int lastDepth = (int)Math.Round(id.Depth()); uint scanLinesThisDepth = 0; List <float> flowRate = new List <float> (); List <float> temperature = new List <float> (); List <float> oxygen = new List <float> (); List <float> oxygenSensor = new List <float> (); List <float> salinity = new List <float> (); List <float> density = new List <float> (); List <float> fluorensce = new List <float> (); List <float> fluorensceSensor = new List <float> (); List <float> transmissivity = new List <float> (); List <float> transmissivitySensor = new List <float> (); List <float> turbidity = new List <float> (); List <float> turbiditySensor = new List <float> (); List <float> recordRate = new List <float> (); while ((lastDepth == (int)Math.Round(id.Depth())) && (id != null)) { 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() > -2.0f) ) { flowRate.Add(id.FlowRate1); temperature.Add(id.Temperature()); salinity.Add(id.Salinity()); density.Add(id.Density()); fluorensce.Add(id.Fluorescence()); fluorensceSensor.Add(id.FluorescenceSensor()); transmissivity.Add(id.Transmissivity()); transmissivitySensor.Add(id.TransmissivitySensor()); turbidity.Add(id.Turbidity()); turbiditySensor.Add(id.TurbiditySensor()); recordRate.Add(id.RecordingRate); oxygen.Add(id.Oxygen()); oxygenSensor.Add(id.OxygenSensor()); scanLinesThisDepth += 4096; } zed++; if (zed < cast.Count) { id = (InstrumentData)cast[zed]; } else { id = null; break; } } float timeAtThisDepth = 0.0f; if (scanRate > 0.0f) { timeAtThisDepth = scanLinesThisDepth / scanRate; } int imageCount = 0; int totalPixelCount = 0; ImagesDepthStats ids = LocateImageDepthStats(imageStats, lastDepth); if (ids != null) { if (ids.counted) { RunLogAddMsg("WriteDepthSummary Duplicate Use of Cast[" + (ids.upCast ? "Up":"Down") + "] Depth[" + ids.bucketDepth + "] Count[" + ids.imageCount + "]"); } else { imageCount = ids.imageCount; totalPixelCount = ids.totalPixelCount; ids.counted = true; } } o.WriteLine(lastDepth.ToString() + "\t" + scanLinesThisDepth.ToString() + "\t" + timeAtThisDepth.ToString() + "\t" + imageCount.ToString() + "\t" + totalPixelCount.ToString() + "\t" + Mean(flowRate).ToString() + "\t" + StdDev(flowRate).ToString() + "\t" + Mean(temperature).ToString() + "\t" + StdDev(temperature).ToString() + "\t" + Mean(oxygen).ToString() + "\t" + StdDev(oxygen).ToString() + "\t" + Mean(oxygenSensor).ToString() + "\t" + StdDev(oxygenSensor).ToString() + "\t" + Mean(salinity).ToString() + "\t" + StdDev(salinity).ToString() + "\t" + Mean(density).ToString() + "\t" + StdDev(density).ToString() + "\t" + Mean(fluorensce).ToString() + "\t" + StdDev(fluorensce).ToString() + "\t" + Mean(fluorensceSensor).ToString() + "\t" + StdDev(fluorensceSensor).ToString() + "\t" + Mean(transmissivity).ToString() + "\t" + StdDev(transmissivity).ToString() + "\t" + Mean(transmissivitySensor).ToString() + "\t" + StdDev(transmissivitySensor).ToString() + "\t" + Mean(turbidity).ToString() + "\t" + StdDev(turbidity).ToString() + "\t" + Mean(turbiditySensor).ToString() + "\t" + StdDev(turbiditySensor).ToString() + "\t" + Mean(recordRate).ToString() + "\t" + StdDev(recordRate).ToString() ); } foreach (ImagesDepthStats ids in imageStats) { if (!ids.counted) { RunLogAddMsg("WriteDepthSummary UnCounted [" + (ids.upCast ? "Up":"Down") + "] Depth[" + ids.bucketDepth + "] Count[" + ids.imageCount + "]"); o.WriteLine(ids.bucketDepth.ToString() + "\t" + "---" + "\t" + "---" + "\t" + ids.imageCount.ToString() + "\t" + ids.totalPixelCount.ToString() + "\t" ); } } } /* WriteDepthSummary */
} /* 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 */