Пример #1
0
        private void btnFilterSnapshotsBySunElevation_Click(object sender, EventArgs e)
        {
            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                 "=========== Processing started on " + DateTime.Now.ToString("s") + " ===========");

            if (bgwSnapshotsFilteringWithSunElevation == null)
            {
                bgwSnapshotsFilteringWithSunElevation = new BackgroundWorker();
                bgwSnapshotsFilteringWithSunElevation.WorkerSupportsCancellation = true;
                bgwSnapshotsFilteringWithSunElevation.WorkerReportsProgress      = true;
                bgwSnapshotsFilteringWithSunElevation.DoWork          += BgwSnapshotsFilteringWithSunElevation_DoWork;
                bgwSnapshotsFilteringWithSunElevation.ProgressChanged += BgwSnapshotsFilteringWithSunElevation_ProgressChanged;

                object[] args = new object[] { CopyImagesFrom_Path, ConcurrentDataXMLfilesPath, CopyImagesAndDataTo_Path };
                bgwSnapshotsFilteringWithSunElevation.RunWorkerAsync(args);
                ThreadSafeOperations.ToggleButtonState(btnFilterSnapshotsBySunElevation, true, "CANCEL", true);
            }
            else
            {
                if (bgwSnapshotsFilteringWithSunElevation.IsBusy)
                {
                    bgwSnapshotsFilteringWithSunElevation.CancelAsync();
                }
                else
                {
                    object[] args = new object[] { CopyImagesFrom_Path, ConcurrentDataXMLfilesPath, CopyImagesAndDataTo_Path };

                    bgwSnapshotsFilteringWithSunElevation.RunWorkerAsync(args);
                    ThreadSafeOperations.ToggleButtonState(btnFilterSnapshotsBySunElevation, true, "CANCEL", true);
                }
            }
        }
Пример #2
0
        private void bgwCopier_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "ERROR has been caught: " + Environment.NewLine + e.Error.Message + Environment.NewLine);
                //ThreadSafeOperations.SetTextTB(tbLog, "ERROR has been caught: " + Environment.NewLine, true);
                //ThreadSafeOperations.SetTextTB(tbLog, e.Error.Message + Environment.NewLine, true);
            }


            //ThreadSafeOperations.SetTextTB(tbLog, "#007" + Environment.NewLine, true);
            ThreadSafeOperations.UpdateProgressBar(prbUniversalProgress, 0);
            theLogWindow = ServiceTools.LogAText(theLogWindow, "Finished work" + Environment.NewLine);
            //ThreadSafeOperations.SetTextTB(tbLog, "Finished work" + Environment.NewLine, true);
            ThreadSafeOperations.ToggleButtonState(btnDoWork, true, "SELECT", false);
        }
Пример #3
0
        private void btnDoWork_Click(object sender, EventArgs e)
        {
            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                 "=========== Processing started on " + DateTime.Now.ToString("s") + " ===========");

            if (bgwCopier.IsBusy)
            {
                bgwCopier.CancelAsync();
            }
            else
            {
                object[] args = new object[] { CopyImagesFrom_Path, rtbConcurrentDataDir.Text, rtbToPath.Text, rtbGrIxYRGBstatsDir.Text };

                bgwCopier.RunWorkerAsync(args);
                ThreadSafeOperations.ToggleButtonState(btnDoWork, true, "CANCEL", true);
            }
        }
Пример #4
0
        private void OpenFile(string filelistmember)
        {
            dataFileName = filelistmember;

            try
            {
                dmDataToShow = NetCDFoperations.ReadDenseMatrixFromFile(dataFileName);
            }
            catch (Exception ex)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "coundn`t load data from file:" + Environment.NewLine + dataFileName);
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "exception description:" + Environment.NewLine + ex.Message);
                return;
            }

            if (dmDataToShow != null)
            {
                RepresentData();
            }
        }
Пример #5
0
        private void MainForm_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                Array  filesArray = (Array)e.Data.GetData(DataFormats.FileDrop);
                string filename   = (string)filesArray.GetValue(0);
                if (Path.GetExtension(filename) != ".nc")
                {
                    return;
                }

                if (filesArray != null)
                {
                    this.BeginInvoke(m_DelegateOpenFile, new Object[] { filename });
                    this.Activate();
                }
            }
            catch (Exception exc1)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "Ошибка при обработке Drag&Drop: " + Environment.NewLine + exc1.Message, true);
            }
        }
Пример #6
0
        private Image <Bgr, byte> FillGraphImage(Size imgSize)
        {
            string curDirPath = Directory.GetCurrentDirectory() + "\\logs\\";

            DirectoryInfo dirInfo = new DirectoryInfo(curDirPath);

            List <Dictionary <string, object> > lReadData = new List <Dictionary <string, object> >();

            if (defaultGraphsTimeSpan)
            {
                graphsTimeSpan = new Tuple <DateTime, DateTime>(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow);
            }

            GraphVariablesTypes currVarType = GraphVariablesTypes.none;

            if (rbtnPressureGraph.Checked)
            {
                currVarType = GraphVariablesTypes.Pressure;
            }
            if (rbtnAirTempGraph.Checked)
            {
                currVarType = GraphVariablesTypes.AirTemp;
            }
            if (rbtnWaterTempGraph.Checked)
            {
                currVarType = GraphVariablesTypes.WaterTemp;
            }
            if (rbtnWindSpeedGraph.Checked)
            {
                currVarType = GraphVariablesTypes.WindSpeed;
            }


            if ((fRenderer == null) || (!prevGraphsTimeSpan.Equals(graphsTimeSpan) || currVarType != prevGraphVariable))
            {
                fRenderer = new MultipleScatterAndFunctionsRepresentation(imgSize);
                switch (currVarType)
                {
                case GraphVariablesTypes.Pressure:
                {
                    currValueColor = new Bgr(Color.Blue);
                    break;
                }

                case GraphVariablesTypes.AirTemp:
                {
                    currValueColor = new Bgr(Color.Red);
                    break;
                }

                case GraphVariablesTypes.WaterTemp:
                {
                    currValueColor = new Bgr(Color.RoyalBlue);
                    break;
                }

                case GraphVariablesTypes.WindSpeed:
                {
                    currValueColor = new Bgr(Color.Gray);
                    break;
                }

                default:
                {
                    currValueColor = new Bgr(Color.Blue);
                    break;
                }
                }
            }
            else if (fRenderer != null)
            {
                if (fRenderer.TheImage.Size != imgSize)
                {
                    fRenderer.ResizeCanvas(imgSize);
                }
            }



            if (!prevGraphsTimeSpan.Equals(graphsTimeSpan))
            {
                IEnumerable <string> ncFileNames = Directory.EnumerateFiles(curDirPath,
                                                                            "IoffeVesselInfoStream-MeteoDataLog-*.nc",
                                                                            SearchOption.TopDirectoryOnly);
                foreach (string ncFileName in ncFileNames)
                {
                    Tuple <DateTime, DateTime> currFileDateTimeRange = null;
                    try
                    {
                        currFileDateTimeRange = ServiceTools.GetNetCDFfileTimeStampsRange(ncFileName);
                    }
                    catch (Exception ex)
                    {
                        #region report

#if DEBUG
                        ServiceTools.ExecMethodInSeparateThread(this, () =>
                        {
                            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                 "an exception has been thrown during file reading: " + Environment.NewLine + ncFileName +
                                                                 Environment.NewLine + "message: " + ex.Message + Environment.NewLine +
                                                                 ServiceTools.CurrentCodeLineDescription());
                        });
#else
                        ServiceTools.ExecMethodInSeparateThread(this, () =>
                        {
                            ServiceTools.logToTextFile(errorLogFilename,
                                                       "an exception has been thrown during file reading: " + Environment.NewLine + ncFileName +
                                                       Environment.NewLine + "message: " + ex.Message + Environment.NewLine +
                                                       ServiceTools.CurrentCodeLineDescription(), true, true);
                        });
#endif

                        #endregion report
                    }

                    if (currFileDateTimeRange == null)
                    {
                        continue;
                    }

                    if ((currFileDateTimeRange.Item1 >= graphsTimeSpan.Item1) &&
                        (currFileDateTimeRange.Item1 <= graphsTimeSpan.Item2) ||
                        (currFileDateTimeRange.Item2 >= graphsTimeSpan.Item1) &&
                        (currFileDateTimeRange.Item2 <= graphsTimeSpan.Item2))
                    {
                        Dictionary <string, object> dictFileData = null;
                        try
                        {
                            dictFileData = NetCDFoperations.ReadDataFromFile(ncFileName);
                        }
                        catch (Exception ex)
                        {
                            #region report

#if DEBUG
                            ServiceTools.ExecMethodInSeparateThread(this, () =>
                            {
                                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                     "an exception has been thrown during file reading: " + Environment.NewLine +
                                                                     ncFileName +
                                                                     Environment.NewLine + "message: " + ex.Message + Environment.NewLine +
                                                                     ServiceTools.CurrentCodeLineDescription());
                            });
#else
                            ServiceTools.ExecMethodInSeparateThread(this, () =>
                            {
                                ServiceTools.logToTextFile(errorLogFilename,
                                                           "an exception has been thrown during file reading: " + Environment.NewLine + ncFileName +
                                                           Environment.NewLine + "message: " + ex.Message + Environment.NewLine +
                                                           ServiceTools.CurrentCodeLineDescription(), true, true);
                            });
#endif

                            #endregion report
                        }

                        if (dictFileData != null)
                        {
                            lReadData.Add(dictFileData);
                        }
                    }
                }


                foreach (Dictionary <string, object> currFileDataDict in lReadData)
                {
                    if (currFileDataDict == null)
                    {
                        continue;
                    }

                    string varNameDateTime = "DateTime";

                    List <long> currFileDateTimeLongTicksList =
                        new List <long>((currFileDataDict[varNameDateTime] as long[]));
                    List <DateTime> currFileDateTimeList =
                        currFileDateTimeLongTicksList.ConvertAll(longVal => new DateTime(longVal));

                    string           varNameMeteoData      = "MeteoData";
                    List <MeteoData> currFileMeteoDataList =
                        MeteoData.OfDenseMatrix(currFileDataDict[varNameMeteoData] as DenseMatrix);

                    if (tsMeteoDataForGraphs == null)
                    {
                        try
                        {
                            tsMeteoDataForGraphs = new TimeSeries <MeteoData>(currFileMeteoDataList, currFileDateTimeList,
                                                                              true);
                        }
                        catch (Exception ex)
                        {
                            #region report

#if DEBUG
                            ServiceTools.ExecMethodInSeparateThread(this, () =>
                            {
                                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                     "couldn`t create timeseries: exception has been thrown" + Environment.NewLine +
                                                                     ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "message: " +
                                                                     ex.Message);
                            });
#else
                            ServiceTools.ExecMethodInSeparateThread(this, () =>
                            {
                                ServiceTools.logToTextFile(errorLogFilename,
                                                           "couldn`t create timeseries: exception has been thrown" + Environment.NewLine +
                                                           ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "message: " +
                                                           ex.Message, true, true);
                            });
#endif

                            #endregion report
                        }
                    }
                    else
                    {
                        try
                        {
                            tsMeteoDataForGraphs.AddSubseriaData(currFileMeteoDataList, currFileDateTimeList, true);
                        }
                        catch (Exception ex)
                        {
                            #region report

#if DEBUG
                            ServiceTools.ExecMethodInSeparateThread(this, () =>
                            {
                                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                     "couldn`t create timeseries: exception has been thrown" + Environment.NewLine +
                                                                     ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "message: " +
                                                                     ex.Message);
                            });
#else
                            ServiceTools.ExecMethodInSeparateThread(this, () =>
                            {
                                ServiceTools.logToTextFile(errorLogFilename,
                                                           "couldn`t create timeseries: exception has been thrown" + Environment.NewLine +
                                                           ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "message: " +
                                                           ex.Message, true, true);
                            });
#endif

                            #endregion report
                        }
                    }
                }



                if (tsMeteoDataForGraphs == null)
                {
                    return(null);
                }

                tsMeteoDataForGraphs.SortByTimeStamps();
                tsMeteoDataForGraphs.RemoveDuplicatedTimeStamps();

                DateTime utcNow = DateTime.UtcNow;
                if (defaultGraphsTimeSpan)
                {
                    tsMeteoDataForGraphs.RemoveValues(dt => (utcNow - dt).TotalSeconds > 86400);
                }
                else
                {
                    tsMeteoDataForGraphs.RemoveValues(
                        dt => !((dt >= graphsTimeSpan.Item1) && (dt <= graphsTimeSpan.Item2)));
                }


                List <TimeSeries <MeteoData> > subSeriesBy1Minute =
                    tsMeteoDataForGraphs.SplitByTimeSpan(new TimeSpan(0, 1, 0));
                List <double>         lSubSeriesEntriesCount = subSeriesBy1Minute.ConvertAll(subs => (double)subs.Count);
                DescriptiveStatistics statsCounts            = new DescriptiveStatistics(lSubSeriesEntriesCount);
                aveMinuteEntriesCount = Convert.ToInt32(statsCounts.Mean);


                // = tsMeteoData.TimeStamps.ConvertAll(dt => (dt - maxDateTime).TotalSeconds);
            }



            List <MeteoData> meteoDataList = tsMeteoDataForGraphs.DataValues;
            DateTime         maxDateTime   = tsMeteoDataForGraphs.TimeStamps.Max();



            if ((currVarType != prevGraphVariable) || !prevGraphsTimeSpan.Equals(graphsTimeSpan))
            {
                double        minVarValue         = 0.0d;
                double        maxVarValue         = 1.0d;
                List <double> currVarToShowValues = new List <double>();
                switch (currVarType)
                {
                case GraphVariablesTypes.Pressure:
                {
                    currVarToShowValues = meteoDataList.ConvertAll(mdt => mdt.pressure);

                    TimeSeries <double> currVarTS = new TimeSeries <double>(currVarToShowValues,
                                                                            tsMeteoDataForGraphs.TimeStamps);
                    currVarTS.RemoveValues(dVal => dVal <= 900.0d);

                    currVarToShowValues = new List <double>(currVarTS.DataValues);
                    currFileSecondsList = currVarTS.TimeStamps.ConvertAll(dt => (dt - maxDateTime).TotalSeconds);

                    fRenderer.yAxisValuesConversionToRepresentTicksValues =
                        new Func <double, string>(dVal => dVal.ToString("F1"));
                    break;
                }

                case GraphVariablesTypes.AirTemp:
                {
                    currVarToShowValues = meteoDataList.ConvertAll(mdt => mdt.airTemperature);

                    TimeSeries <double> currVarTS = new TimeSeries <double>(currVarToShowValues,
                                                                            tsMeteoDataForGraphs.TimeStamps);
                    currVarTS.RemoveValues(dVal => ((dVal < -20.0d) || (dVal > 50.0d)));

                    currVarToShowValues = new List <double>(currVarTS.DataValues);
                    currFileSecondsList = currVarTS.TimeStamps.ConvertAll(dt => (dt - maxDateTime).TotalSeconds);

                    fRenderer.yAxisValuesConversionToRepresentTicksValues =
                        new Func <double, string>(dVal => dVal.ToString("F2"));
                    break;
                }

                case GraphVariablesTypes.WaterTemp:
                {
                    currVarToShowValues = meteoDataList.ConvertAll(mdt => mdt.waterTemperature);

                    TimeSeries <double> currVarTS = new TimeSeries <double>(currVarToShowValues,
                                                                            tsMeteoDataForGraphs.TimeStamps);
                    currVarTS.RemoveValues(dVal => ((dVal < -20.0d) || (dVal > 50.0d)));

                    currVarToShowValues = new List <double>(currVarTS.DataValues);
                    currFileSecondsList = currVarTS.TimeStamps.ConvertAll(dt => (dt - maxDateTime).TotalSeconds);



                    fRenderer.yAxisValuesConversionToRepresentTicksValues =
                        new Func <double, string>(dVal => dVal.ToString("F2"));
                    break;
                }

                case GraphVariablesTypes.WindSpeed:
                {
                    currVarToShowValues = meteoDataList.ConvertAll(mdt => mdt.windSpeed);

                    TimeSeries <double> currVarTS = new TimeSeries <double>(currVarToShowValues,
                                                                            tsMeteoDataForGraphs.TimeStamps);
                    currVarTS.RemoveValues(dVal => ((dVal < 0.0d) || (dVal > 50.0d)));

                    currVarToShowValues = new List <double>(currVarTS.DataValues);
                    currFileSecondsList = currVarTS.TimeStamps.ConvertAll(dt => (dt - maxDateTime).TotalSeconds);

                    fRenderer.yAxisValuesConversionToRepresentTicksValues =
                        new Func <double, string>(dVal => dVal.ToString("F1"));
                    break;
                }

                default:
                    return(null);
                }

                dvVarValues = DenseVector.OfEnumerable(currVarToShowValues);
                dvVarValues = dvVarValues.Conv(Extensions.StandardConvolutionKernels.gauss, aveMinuteEntriesCount * 10);
            }



            fRenderer.dvScatterFuncValues.Add(dvVarValues);
            fRenderer.dvScatterXSpace.Add(DenseVector.OfEnumerable(currFileSecondsList));

            fRenderer.xAxisValuesConversionToRepresentTicksValues = (dValSec) =>
            {
                DateTime currDT = tsMeteoDataForGraphs.TimeStamps.Max().AddSeconds(dValSec);
                return(currDT.ToString("yyyy-MM-dd" + Environment.NewLine + "HH:mm"));
            };

            fRenderer.scatterLineColors.Add(currValueColor);
            fRenderer.scatterDrawingVariants.Add(SequencesDrawingVariants.polyline);
            fRenderer.xSpaceMin           = currFileSecondsList.Min();
            fRenderer.xSpaceMax           = currFileSecondsList.Max();
            fRenderer.overallFuncMin      = dvVarValues.Min();
            fRenderer.overallFuncMax      = dvVarValues.Max();
            fRenderer.fixSpecifiedMargins = true;

            fRenderer.Represent();

            Image <Bgr, byte> retImg = fRenderer.TheImage;

            // расположим надпись
            string strSign = "current value: " + dvVarValues.Last().ToString("F2");

            List <TextBarImage> textBarsCases = new List <TextBarImage>();

            TextBarImage tbimTopLeftSign = new TextBarImage(strSign, retImg);
            tbimTopLeftSign.PtSurroundingBarStart =
                new Point(fRenderer.LeftServiceSpaceGapX + tbimTopLeftSign.textHalfHeight,
                          fRenderer.TopServiceSpaceGapY + tbimTopLeftSign.textHalfHeight);
            textBarsCases.Add(tbimTopLeftSign);

            TextBarImage tbimBtmLeftSign = new TextBarImage(strSign, retImg);
            tbimBtmLeftSign.PtSurroundingBarStart = new Point(fRenderer.LeftServiceSpaceGapX + tbimBtmLeftSign.textHalfHeight,
                                                              retImg.Height - fRenderer.BtmServiceSpaceGapY - tbimBtmLeftSign.textHalfHeight - tbimBtmLeftSign.textHeight * 2);
            textBarsCases.Add(tbimBtmLeftSign);

            TextBarImage tbimTopRightSign = new TextBarImage(strSign, retImg);
            tbimTopRightSign.PtSurroundingBarStart =
                new Point(
                    retImg.Width - fRenderer.RightServiceSpaceGapX - tbimTopRightSign.textHalfHeight -
                    tbimTopRightSign.textBarSize.Width, fRenderer.TopServiceSpaceGapY + tbimTopLeftSign.textHalfHeight);
            textBarsCases.Add(tbimTopRightSign);

            TextBarImage tbimBtmRightSign = new TextBarImage(strSign, retImg);
            tbimBtmRightSign.PtSurroundingBarStart =
                new Point(
                    retImg.Width - fRenderer.RightServiceSpaceGapX - tbimBtmRightSign.textHalfHeight -
                    tbimBtmRightSign.textBarSize.Width,
                    retImg.Height - fRenderer.BtmServiceSpaceGapY - tbimBtmRightSign.textHalfHeight -
                    tbimBtmRightSign.textHeight * 2);
            textBarsCases.Add(tbimBtmRightSign);

            textBarsCases.Sort((case1, case2) => (case1.SubImageInTextRect.CountNonzero().Sum() > case2.SubImageInTextRect.CountNonzero().Sum()) ? 1 : -1);

            MCvFont theFont = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_PLAIN, 2.0d, 2.0d)
            {
                thickness = 2,
            };
            // retImg.Draw(strSign, textBarsCases[0].ptTextBaselineStart, Emgu.CV.CvEnum.FontFace.HersheyPlain, 2.0d, new Bgr(Color.Green), 2);
            retImg.Draw(strSign, ref theFont, textBarsCases[0].ptTextBaselineStart, new Bgr(Color.Green));
            retImg.Draw(textBarsCases[0].rectSurroundingBar, new Bgr(Color.Green), 2);

            prevGraphsTimeSpan = graphsTimeSpan;
            prevGraphVariable  = currVarType;

            return(retImg);
        }
        private void btnProcess_Click(object sender, EventArgs e)
        {
            string fName = richTextBox1.Text;

            if (!File.Exists(fName))
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow, "couldn`t find a file: " + fName);
                return;
            }

            try
            {
                xlApp         = new Microsoft.Office.Interop.Excel.Application();
                xlApp.Visible = true;
                wb            = xlApp.Workbooks.Open(fName, Type.Missing, false);
                ws            = wb.Sheets[1];
            }
            catch (Exception)
            {
                CloseAll();
            }


            List <Tuple <int, SunElevationTestDataRecord> > lRecords = new List <Tuple <int, SunElevationTestDataRecord> >();
            int    rowIdx        = 2;
            double dDataTimeRead = 0.0d;

            while (true)
            {
                DateTime dtVal;
                SunElevationTestDataRecord currRec = new SunElevationTestDataRecord();

                System.Windows.Forms.Application.DoEvents();

                try
                {
                    Range rngDT = ws.Cells[rowIdx, 1];
                    var   dDataTimeReadValue = rngDT.Value2;
                    if (dDataTimeReadValue == null)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "date-time value at row " + rowIdx + " is empty. Stopping reading.");
                        CloseAll();
                        break;
                    }
                    dDataTimeRead = (double)(dDataTimeReadValue);
                    if (dDataTimeRead == 0.0d)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "date-time value at row " + rowIdx + " is empty. Stopping reading.");
                        CloseAll();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    //CloseAll();
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         ex.Message + Environment.NewLine + "for date-time value at row " + rowIdx);
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    lRecords.Add(new Tuple <int, SunElevationTestDataRecord>(rowIdx, currRec));
                    rowIdx++;
                    continue;
                }
                dtVal      = DateTime.FromOADate(dDataTimeRead);
                currRec.Dt = dtVal;



                double latVal = 0.0d;
                try
                {
                    Range rngLat    = ws.Cells[rowIdx, 2];
                    var   rngLatVal = rngLat.Value2;
                    if (rngLatVal == null)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "latitude value at row " + rowIdx + " is empty");
                        //rowIdx++;
                        //continue;
                    }
                    else
                    {
                        latVal         = (double)(rngLatVal);
                        currRec.latDec = latVal;
                    }
                }
                catch (Exception ex)
                {
                    //CloseAll();
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         ex.Message + Environment.NewLine + "for latitude value at row " + rowIdx);
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    lRecords.Add(new Tuple <int, SunElevationTestDataRecord>(rowIdx, currRec));
                    rowIdx++;
                    continue;
                }



                double lonVal = 0.0d;
                try
                {
                    Range rngLon    = ws.Cells[rowIdx, 3];
                    var   rngLonVal = rngLon.Value2;
                    if (rngLonVal == null)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "longitude value at row " + rowIdx + " is empty");
                        //rowIdx++;
                        //continue;
                    }
                    else
                    {
                        lonVal         = (double)(rngLonVal);
                        currRec.lonDec = lonVal;
                    }
                }
                catch (Exception ex)
                {
                    //CloseAll();
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         ex.Message + Environment.NewLine + "for longitude value at row " + rowIdx);
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    lRecords.Add(new Tuple <int, SunElevationTestDataRecord>(rowIdx, currRec));
                    rowIdx++;
                    continue;
                }



                double sunAltTestVal = 0.0d;
                try
                {
                    Range rngSunAltTest    = ws.Cells[rowIdx, 4];
                    var   rngSunAltTestVal = rngSunAltTest.Value2;
                    if (rngSunAltTestVal == null)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "testing sun elevation value at row " + rowIdx + " is empty");
                        //rowIdx++;
                        //continue;
                    }
                    else
                    {
                        sunAltTestVal       = (double)(rngSunAltTestVal);
                        currRec.SunElevTest = sunAltTestVal;
                    }
                }
                catch (Exception ex)
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         ex.Message + Environment.NewLine + "for read sun elevation value at row " + rowIdx);
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "=====================");
                    //CloseAll();
                    lRecords.Add(new Tuple <int, SunElevationTestDataRecord>(rowIdx, currRec));
                    rowIdx++;
                    continue;
                }



                ThreadSafeOperations.SetText(lblLoadingStatus, "loading " + rowIdx + " row", false);

                lRecords.Add(new Tuple <int, SunElevationTestDataRecord>(rowIdx, currRec));

                rowIdx++;
            }



            List <double> lDeviations = new List <double>();
            string        outFName    = Path.GetDirectoryName(fName) + "\\" + Path.GetFileNameWithoutExtension(fName) + "-output.txt";

            ServiceTools.logToTextFile(outFName, SunElevationTestDataRecord.TableFieldsHeader() + Environment.NewLine, true);

            foreach (Tuple <int, SunElevationTestDataRecord> tpl in lRecords)
            {
                rowIdx = tpl.Item1;
                SunElevationTestDataRecord currRec = tpl.Item2;

                if (currRec.WhetherAllValuesHasBeenRead)
                {
                    SPA spaCalc = new SPA(currRec.Dt.Year, currRec.Dt.Month, currRec.Dt.Day, currRec.Dt.Hour,
                                          currRec.Dt.Minute, currRec.Dt.Second, (float)currRec.lonDec, (float)currRec.latDec,
                                          (float)SPAConst.DeltaT(currRec.Dt));
                    int res = spaCalc.spa_calculate();
                    AzimuthZenithAngle sunPositionSPAext = new AzimuthZenithAngle(spaCalc.spa.azimuth,
                                                                                  spaCalc.spa.zenith);
                    currRec.SunElevCalc = sunPositionSPAext.ElevationAngle;

                    lDeviations.Add(currRec.SunElevCalc - currRec.SunElevTest);

                    ServiceTools.logToTextFile(outFName, currRec.ToString() + Environment.NewLine, true);
                }
                else
                {
                    ServiceTools.logToTextFile(outFName, currRec.ToString() + Environment.NewLine, true);
                }
            }


            HistogramDataAndProperties histData = new HistogramDataAndProperties(DenseVector.OfEnumerable(lDeviations), 20);
            HistogramCalcAndShowForm   histForm = new HistogramCalcAndShowForm("", defaultProperties);

            histForm.HistToRepresent = histData;
            histForm.Show();
            histForm.Represent();


            CloseAll();
        }
Пример #8
0
        private void btnCorrectGPSdata_Click(object sender, EventArgs e)
        {
            string infoFilesPath    = rtbPath.Text;
            string navdataFilesPath = rtbVesselNavDataDirectoryPath.Text;

            infoFilesPath += ((infoFilesPath.Substring(infoFilesPath.Length - 1) == "\\") ? ("") : ("\\"));
            string bcpFilesPath = infoFilesPath + "backup\\";

            if (infoFilesPath == "")
            {
                return;
            }
            if (!Directory.Exists(infoFilesPath))
            {
                return;
            }
            if (navdataFilesPath == "")
            {
                return;
            }
            if (!Directory.Exists(navdataFilesPath))
            {
                return;
            }

            DirectoryInfo dirConcurrentDataFiles = new DirectoryInfo(infoFilesPath);

            FileInfo[] concurrentDataFilesList = dirConcurrentDataFiles.GetFiles("*.xml", SearchOption.TopDirectoryOnly);
            //string[] sConcurrentInfoFilenames = Directory.GetFiles(rtbPath.Text, "*.xml");
            if (!concurrentDataFilesList.Any())
            {
                return;
            }
            if (!ServiceTools.CheckIfDirectoryExists(bcpFilesPath))
            {
                return;
            }

            CultureInfo provider = CultureInfo.InvariantCulture;

            foreach (FileInfo concurrentInfoFileInfo in concurrentDataFilesList)
            {
                Dictionary <string, object> dictSavedData = ServiceTools.ReadDictionaryFromXML(concurrentInfoFileInfo.FullName);
                DateTime computerDateTime = DateTime.ParseExact((string)dictSavedData["DateTime"], "o", provider).ToUniversalTime();

                DateTime gpsDateTime = DateTime.ParseExact((string)dictSavedData["GPSDateTimeUTC"], "o", provider).ToUniversalTime();

                if (Math.Abs((gpsDateTime - computerDateTime).TotalSeconds) > 300)
                {
                    //надо корректировать по данным судовой навигации
                    File.Copy(concurrentInfoFileInfo.FullName, bcpFilesPath + concurrentInfoFileInfo.Name);
                    dictSavedData["GPSdata"] = "$GPGGA," + computerDateTime.Hour.ToString("D02") +
                                               computerDateTime.Minute.ToString("D02") +
                                               computerDateTime.Second.ToString("D02") + ".00";

                    IoffeVesselDualNavDataConverted ioffeNavdata =
                        IoffeVesselNavDataReader.GetNavDataByDatetime(navdataFilesPath, computerDateTime);
                    if (ioffeNavdata == null)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "couldn`t find vessel nav data for file: " + Environment.NewLine +
                                                             concurrentInfoFileInfo.FullName);
                        continue;
                    }

                    dictSavedData["GPSLat"]         = ioffeNavdata.gps.Lat;
                    dictSavedData["GPSLon"]         = ioffeNavdata.gps.Lon;
                    dictSavedData["GPSDateTimeUTC"] = ioffeNavdata.gps.dateTimeUTC.ToString("o");

                    ServiceTools.WriteDictionaryToXml(dictSavedData, concurrentInfoFileInfo.FullName);
                }
            }
        }
Пример #9
0
        // private List<bool> bgwFinished = new List<bool>();
        public void CollectPositioningData()
        {
#if DEBUG
            int concurrentFilesProcessingCount = 1;
#else
            int concurrentFilesProcessingCount = 2;
            try
            {
                concurrentFilesProcessingCount = Convert.ToInt32(defaultProperties["MaxConcurrentFilesProcessingCount"]);
            }
            catch (Exception ex)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "ERROR! exception thrown: " + ex.Message + Environment.NewLine +
                                                     "MaxConcurrentFilesProcessingCount value can`t be read. " + Environment.NewLine +
                                                     "Using default value = " + concurrentFilesProcessingCount);
            }
#endif



            theLogWindow = ServiceTools.LogAText(theLogWindow, "started on " + DateTime.UtcNow.ToString("s"));


            string        strImagesDir = ParentForm.richTextBox1.Text;
            DirectoryInfo imagesDir    = new DirectoryInfo(strImagesDir);

            if (!imagesDir.Exists)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "Операция не выполнена. Не найдена директория:" + Environment.NewLine + strImagesDir +
                                                     Environment.NewLine, true);
                return;
            }


            // оказалось, что маска - case-insensitive
            lImagesFileInfos = new List <FileInfo>(imagesDir.GetFiles("*.jpg", SearchOption.TopDirectoryOnly));

            List <FileInfo> lImagesFileInfoWithExistingSunDiskInfo = lImagesFileInfos.ConvertAll <FileInfo>(fInfoSrc =>
            {
                string sunDiskInfoFileName = fInfoSrc.DirectoryName + "\\" +
                                             Path.GetFileNameWithoutExtension(fInfoSrc.FullName) + "-SunDiskInfo.xml";
                if (File.Exists(sunDiskInfoFileName))
                {
                    return(fInfoSrc);
                }
                else
                {
                    return(null);
                }
            });
            lImagesFileInfoWithExistingSunDiskInfo.RemoveAll(fInfo => fInfo == null);

            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                 "files already processed before: " + lImagesFileInfoWithExistingSunDiskInfo.Count);

            lImagesFileInfos.RemoveAll(fInfo => lImagesFileInfoWithExistingSunDiskInfo.Contains(fInfo));
            int filesCountToProcess        = lImagesFileInfos.Count;
            int filesCountAlreadyProcessed = lImagesFileInfoWithExistingSunDiskInfo.Count;

            lImagesFileInfos.AddRange(lImagesFileInfoWithExistingSunDiskInfo);



            //List<BackgroundWorker> bgwList = new List<BackgroundWorker>();
            //for (int i = 0; i < 2; i++)
            //{
            //    //bgwFinished.Add(true);
            //    //bgwList.Add(null);
            //}

            int currDataIdx = 1;

            foreach (FileInfo finfo in lImagesFileInfos)
            {
                //int currentBgwID = -1;
                while ((cbgBgwList.Count >= concurrentFilesProcessingCount) && (!hasToStopCollecting))
                {
                    Application.DoEvents();
                    Thread.Sleep(0);
                }

                //while ((bgwFinished.Sum(boolVal => (boolVal) ? ((int)0) : ((int)1)) == bgwFinished.Count) && (!hasToStopCollecting))
                //{
                //    Application.DoEvents();
                //    Thread.Sleep(0);
                //}
                if (hasToStopCollecting)
                {
                    break;
                }

                //for (int i = 0; i < concurrentFilesProcessingCount; i++)
                //{
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "" + currDataIdx + " / " + filesCountToProcess + " (+ " + filesCountAlreadyProcessed +
                                                     " processed before)");
                theLogWindow = ServiceTools.LogAText(theLogWindow, Environment.NewLine + "starting: " + finfo.Name);


                //object[] BGWorker2Args = new object[] { finfo, defaultProperties, currentBgwID };
                object[] BGWorker2Args = new object[] { finfo, defaultProperties };

                BackgroundWorker currBgw = new BackgroundWorker();
                // bgwList[currentBgwID] = currBgw;
                currBgw.DoWork             += currBgw_DoWork;
                currBgw.RunWorkerCompleted += currBgw_RunWorkerCompleted;
                currBgw.RunWorkerAsync(BGWorker2Args);

                cbgBgwList.Add(finfo.FullName);

                if (filesCountToProcess > 0)
                {
                    int progress = Convert.ToInt32(100.0d * (double)currDataIdx / (double)filesCountToProcess);
                    ThreadSafeOperations.UpdateProgressBar(ParentForm.pbUniversalProgressBar, progress);
                    Interlocked.Increment(ref currDataIdx);
                }
            }


            while (cbgBgwList.Count > 0)
            {
                Application.DoEvents();
                Thread.Sleep(0);
            }

            if (hasToStopCollecting)
            {
                return;
            }



            // сохраним на будущее
            string   strMedianPerc5StatsXMLFileName = (string)defaultProperties["DefaultMedianPerc5StatsXMLFile"];
            FileInfo MedianPerc5StatsXMLFileInfo    = new FileInfo(strMedianPerc5StatsXMLFileName);
            string   strMedianPerc5StatsXMLFilePath = MedianPerc5StatsXMLFileInfo.DirectoryName;
            strMedianPerc5StatsXMLFilePath += (strMedianPerc5StatsXMLFilePath.Last() == '\\') ? ("") : ("\\");
            string computedDeviationsXMLfilesPath = strMedianPerc5StatsXMLFilePath + "azimuth-dev-stats\\";
            if (!ServiceTools.CheckIfDirectoryExists(computedDeviationsXMLfilesPath))
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "couldn`t locate or create directory " + computedDeviationsXMLfilesPath);
                return;
            }

            string computedAzimuthDeviationsXMLFile = computedDeviationsXMLfilesPath + "PreComputedSunAnglesDeviationsData.xml";

            List <AngleSunDeviationCalcResult> lResList =
                new List <AngleSunDeviationCalcResult>(cbAnglesSunDeviationCalcResults);
            ServiceTools.WriteObjectToXML(lResList, computedAzimuthDeviationsXMLFile);
            ServiceTools.WriteDictionaryToXml(defaultProperties, defaultPropertiesXMLfileName, false);


            // теперь посчитаем статистику
            List <AngleSunDeviationCalcResult> azimuthResults = new List <AngleSunDeviationCalcResult>(lResList);
            List <AngleSunDeviationCalcResult> zenithResults  = new List <AngleSunDeviationCalcResult>(lResList);
            azimuthResults.RemoveAll(
                azimuthSunDeviationCalcResult =>
                ((!azimuthSunDeviationCalcResult.calculationSucceeded) ||
                 (!azimuthSunDeviationCalcResult.AzimuthDeviationCanBeComputed)));
            zenithResults.RemoveAll(
                sunDeviationCalcResult =>
                ((!sunDeviationCalcResult.calculationSucceeded) ||
                 (!sunDeviationCalcResult.ZenithDeviationCanBeComputed)));

            List <double> azimuthDevValues =
                azimuthResults.ConvertAll <double>(
                    azimuthSunDeviationCalcResult => azimuthSunDeviationCalcResult.computedAzimuthDeviationDeg);

            List <double> zenithDevValues =
                zenithResults.ConvertAll <double>(
                    azimuthSunDeviationCalcResult => azimuthSunDeviationCalcResult.computedZenithDeviationDeg);


            ServiceTools.ExecMethodInSeparateThread(ParentForm, delegate()
            {
                HistogramDataAndProperties histAzimuthData =
                    new HistogramDataAndProperties(DenseVector.OfEnumerable(azimuthDevValues), 100);
                HistogramCalcAndShowForm hAzimuthForm = new HistogramCalcAndShowForm("azimuth sun angle deviations (deg.)",
                                                                                     defaultProperties);
                hAzimuthForm.HistToRepresent = histAzimuthData;
                hAzimuthForm.Show();
                hAzimuthForm.Represent();
            });



            ServiceTools.ExecMethodInSeparateThread(ParentForm, delegate()
            {
                HistogramDataAndProperties histZenithData =
                    new HistogramDataAndProperties(DenseVector.OfEnumerable(zenithDevValues), 100);
                HistogramCalcAndShowForm hZenithForm = new HistogramCalcAndShowForm("zenith sun angle deviations (deg.)",
                                                                                    defaultProperties);
                hZenithForm.HistToRepresent = histZenithData;
                hZenithForm.Show();
                hZenithForm.Represent();
            });



            ThreadSafeOperations.UpdateProgressBar(ParentForm.pbUniversalProgressBar, 0);
        }
Пример #10
0
        private AngleSunDeviationCalcResult CalculateDevDataForImage(FileInfo finfo, Dictionary <string, object> defaultProperties, LogWindow currImageLogWindow, bool showOnlyErrors = false)
        {
            FileInfo currFileInfo = finfo;
            Dictionary <string, object> defaultProps = defaultProperties;


            AngleSunDeviationCalcResult retRes = new AngleSunDeviationCalcResult()
            {
                fileName = currFileInfo.FullName,
            };

            GPSdata gps = ServiceTools.FindProperGPSdataForImage(currFileInfo.FullName, theLogWindow, defaultProperties,
                                                                 ref NVdataFilesAlreadyReadDateTimeSpans, ref NVdataFilesAlreadyReadData);

            if (gps == null)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow, "Couldn`t find GPS data for this image.");
                retRes.calculationSucceeded = false;
                retRes.resultMessage        = "Couldn`t find GPS data for this image.";
                return(retRes);
            }

            #region // obsolete
            //// определяем дату-время файла
            //DateTime curDateTime = DateTime.UtcNow;

            //Image anImage = Image.FromFile(currFileInfo.FullName);
            //ImageInfo newIInfo = new ImageInfo(anImage);
            //int minute = 0;
            //String dateTime = (String)newIInfo.getValueByKey("ExifDTOrig");
            //if (dateTime == null)
            //{
            //    //попробуем вытащить из имени файла
            //    string strDateTime = currFileInfo.Name;
            //    strDateTime = strDateTime.Substring(4, 19);
            //    dateTime = strDateTime;
            //}

            //try
            //{
            //    curDateTime = CommonTools.DateTimeOfString(dateTime);
            //}
            //catch (Exception)
            //{
            //    retRes.calculationSucceeded = false;
            //    retRes.resultMessage = "couldn`t get date/time for file: " + Environment.NewLine + currFileInfo.Name;
            //    return retRes;
            //}
            //curDateTime = DateTime.SpecifyKind(curDateTime, DateTimeKind.Utc);

            //GPSdata neededGPSdata = new GPSdata();
            //string currPath = currFileInfo.DirectoryName;


            //string navFilesPath = defaultProps["IoffeMeteoNavFilesDirectory"] as string;
            //List<IoffeVesselDualNavDataConverted> lAllNavData = new List<IoffeVesselDualNavDataConverted>();

            //string[] sNavFilenames = Directory.GetFiles(navFilesPath, "*.nv2", SearchOption.AllDirectories);
            //if (!sNavFilenames.Any())
            //{
            //    retRes.calculationSucceeded = false;
            //    retRes.resultMessage = "Не найдено файлов данных навигации в директории " + navFilesPath;
            //    return retRes;
            //}
            //else
            //{
            //    foreach (string navFilename in sNavFilenames)
            //    {
            //        Tuple<DateTime, DateTime> timeSpan =
            //            IoffeVesselNavDataReader.GetNavFileDateTimeMargins(navFilename);
            //        if (timeSpan == null)
            //        {
            //            continue;
            //        }

            //        if ((curDateTime < timeSpan.Item1) || (curDateTime > timeSpan.Item2))
            //        {
            //            continue;
            //        }

            //        List<IoffeVesselDualNavDataConverted> dataHasBeenRead = IoffeVesselNavDataReader.ReadNavFile(navFilename);
            //        if (dataHasBeenRead == null)
            //        {
            //            continue;
            //        }
            //        Application.DoEvents();
            //        lAllNavData.AddRange(dataHasBeenRead);
            //    }
            //}

            //lAllNavData.Sort((gpsRecord1, gpsRecord2) =>
            //{
            //    double dev1 = Math.Abs((gpsRecord1.gps.dateTimeUTC - curDateTime).TotalMilliseconds);
            //    double dev2 = Math.Abs((gpsRecord2.gps.dateTimeUTC - curDateTime).TotalMilliseconds);
            //    return (dev1 >= dev2) ? (1) : (-1);
            //});
            //neededGPSdata = lAllNavData[0].gps;
            #endregion // obsolete

            retRes.gpsData = gps;


            #region obsolete
            //double lat = gps.LatDec;
            //double lon = gps.LonDec;


            //SPA spaCalc = new SPA(curDateTime.Year, curDateTime.Month, curDateTime.Day, curDateTime.Hour,
            //    curDateTime.Minute, curDateTime.Second, (float)lon, (float)lat,
            //    (float)SPAConst.DeltaT(curDateTime));
            //int res = spaCalc.spa_calculate();
            //AzimuthZenithAngle sunPositionSPAext = new AzimuthZenithAngle(spaCalc.spa.azimuth,
            //    spaCalc.spa.zenith);
            #endregion obsolete


            AzimuthZenithAngle sunPositionSPAext = gps.SunZenithAzimuth();

            if (!showOnlyErrors)
            {
                currImageLogWindow = ServiceTools.LogAText(currImageLogWindow,
                                                           "SPA ext sun position for " + gps.dateTimeUTC.ToString("s") + ": " + sunPositionSPAext);
            }

            retRes.sunSPAcomputedPosition = sunPositionSPAext;



            Image <Bgr, Byte> img2process = new Image <Bgr, byte>(currFileInfo.FullName);
            img2process = ImageProcessing.ImageResizer(img2process, Convert.ToInt32(defaultProps["DefaultMaxImageSize"]));
            Image <Bgr, Byte> LocalProcessingImage = ImageProcessing.SquareImageDimensions(img2process);

            RoundData sunRoundData = RoundData.nullRoundData();

            //посмотрим, нет ли уже имеющихся данных о положении и размере солнечного диска на изображении
            string sunDiskInfoFileName = ConventionalTransitions.SunDiskInfoFileName(currFileInfo.FullName);
            //string sunDiskInfoFileName = currFileInfo.DirectoryName + "\\" +
            //                             Path.GetFileNameWithoutExtension(currFileInfo.FullName) + "-SunDiskInfo.xml";

            RoundData existingRoundData             = RoundData.nullRoundData();
            Size      imgSizeUnderExistingRoundData = LocalProcessingImage.Bitmap.Size;
            object    existingRoundDataObj          = ServiceTools.ReadObjectFromXML(sunDiskInfoFileName, typeof(RoundDataWithUnderlyingImgSize));

            if (existingRoundDataObj != null)
            {
                existingRoundData             = ((RoundDataWithUnderlyingImgSize)existingRoundDataObj).circle;
                imgSizeUnderExistingRoundData = ((RoundDataWithUnderlyingImgSize)existingRoundDataObj).imgSize;
            }

            double currScale = (double)LocalProcessingImage.Width / (double)imgSizeUnderExistingRoundData.Width;
            if (currScale != 1.0d)
            {
                existingRoundData.DCenterX *= currScale;
                existingRoundData.DCenterY *= currScale;
                existingRoundData.DRadius  *= currScale;
            }
            if (!existingRoundData.IsNull)
            {
                sunRoundData = existingRoundData;
            }

            ImageProcessing imgP = new ImageProcessing(LocalProcessingImage, true);

            if (sunRoundData.IsNull)
            {
                SkyCloudClassification classificator = new SkyCloudClassification(img2process, defaultProperties);
                classificator.verbosityLevel             = 0;
                classificator.ParentForm                 = ParentForm;
                classificator.theLogWindow               = currImageLogWindow;
                classificator.ClassificationMethod       = ClassificationMethods.GrIx;
                classificator.isCalculatingUsingBgWorker = false;
                // classificator.SelfWorker = currBGWsender as BackgroundWorker;
                classificator.defaultOutputDataDirectory = (string)defaultProps["DefaultDataFilesLocation"];
                classificator.theStdDevMarginValueDefiningSkyCloudSeparation =
                    Convert.ToDouble(defaultProps["GrIxDefaultSkyCloudMarginWithoutSun"]);
                classificator.sourceImageFileName = currFileInfo.FullName;

                retRes.imageEdgesDetected = new RoundDataWithUnderlyingImgSize()
                {
                    circle  = imgP.imageRD,
                    imgSize = LocalProcessingImage.Size,
                };
                DenseMatrix dmProcessingData = (DenseMatrix)imgP.eval("grix").Clone();
                try
                {
                    sunRoundData = classificator.DetectSunWithSerieOfArcs(imgP, dmProcessingData);
                    if (!sunRoundData.IsNull)
                    {
                        RoundDataWithUnderlyingImgSize infoToSave = new RoundDataWithUnderlyingImgSize()
                        {
                            circle  = sunRoundData,
                            imgSize = LocalProcessingImage.Size,
                        };
                        ServiceTools.WriteObjectToXML(infoToSave, sunDiskInfoFileName);
                    }
                }
                catch (Exception ex)
                {
                    retRes.calculationSucceeded = false;
                    retRes.resultMessage        = ex.Message;
                    return(retRes);
                }
                ServiceTools.FlushMemory();
            }



            if (sunRoundData.IsNull)
            {
                throw new Exception(finfo.Name + ": couldn`t detect sun position");
            }
            else
            {
                retRes.sunDiskDetectedPosition = new RoundDataWithUnderlyingImgSize()
                {
                    circle  = sunRoundData,
                    imgSize = LocalProcessingImage.Size,
                };
            }



            RoundData imageDetectedRound = imgP.imageRD.Copy();
            retRes.imageEdgesDetected = new RoundDataWithUnderlyingImgSize()
            {
                circle  = imageDetectedRound,
                imgSize = LocalProcessingImage.Size,
            };

            try
            {
                double dev = retRes.computedAzimuthDeviation;
                retRes.calculationSucceeded = true;
            }
            catch (Exception ex)
            {
                retRes.calculationSucceeded = false;
                retRes.resultMessage        = ex.Message;
                return(retRes);
            }

            return(retRes);
        }
Пример #11
0
        void currBgw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker            selfWorker        = sender as BackgroundWorker;
            FileInfo                    finfo             = ((object[])e.Argument)[0] as FileInfo;
            Dictionary <string, object> defaultProperties = ((object[])e.Argument)[1] as Dictionary <string, object>;
            //int currentBgwID = (int) ((object[]) e.Argument)[2];
            LogWindow currImageLogWindow = null;
            bool      showOnlyErrors     = false;

            string sunDiskInfoFileName = finfo.DirectoryName + "\\" +
                                         Path.GetFileNameWithoutExtension(finfo.FullName) + "-SunDiskInfo.xml";

            if (File.Exists(sunDiskInfoFileName))
            {
                showOnlyErrors = true;
            }

            try
            {
                if (finfo == null)
                {
                    e.Result = false;
                    return;
                }

                if (!showOnlyErrors)
                {
                    currImageLogWindow = ServiceTools.LogAText(currImageLogWindow, Environment.NewLine + "starting: " + finfo.Name);
                    currImageLogWindow = ServiceTools.LogAText(currImageLogWindow, "start processing image " + finfo.Name);
                }


                AngleSunDeviationCalcResult devCalcResDatum = CalculateDevDataForImage(finfo, defaultProperties, currImageLogWindow, showOnlyErrors);


                if (devCalcResDatum.calculationSucceeded)
                {
                    cbAnglesSunDeviationCalcResults.Add(devCalcResDatum);
                }


                if (!showOnlyErrors)
                {
                    currImageLogWindow = ServiceTools.LogAText(currImageLogWindow,
                                                               Environment.NewLine + "finished: " + Path.GetFileName(devCalcResDatum.fileName) +
                                                               " with result: " + devCalcResDatum.calculationSucceeded + Environment.NewLine +
                                                               devCalcResDatum.resultMessage);
                }


                if (currImageLogWindow != null)
                {
                    currImageLogWindow.Close();
                }
            }
            catch (Exception ex)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     Environment.NewLine + "ERROR. There exceptions has been thrown: " + Environment.NewLine + ex.Message);

                string strDirForFailedImages = Path.GetDirectoryName(finfo.FullName);
                strDirForFailedImages += (strDirForFailedImages.Last() == '\\') ? ("") : ("\\") + "failed-detections\\";
                try
                {
                    if (ServiceTools.CheckIfDirectoryExists(strDirForFailedImages))
                    {
                        File.Move(finfo.FullName, strDirForFailedImages + finfo.Name);
                    }
                }
                catch (Exception ex1)
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         Environment.NewLine + "ERROR. There exceptions has been thrown: " + Environment.NewLine +
                                                         ex1.Message);
                }


                if (currImageLogWindow != null)
                {
                    currImageLogWindow.Close();
                }
            }


            e.Result = new object[] { true };
        }
Пример #12
0
        private void btnCreateList_Click(object sender, EventArgs e)
        {
            theLogWindow = ServiceTools.LogAText(theLogWindow, "Started processing...");

            BackgroundWorker bgwCreateList = new BackgroundWorker();

            bgwCreateList.DoWork += (bgwSender, bgwArgs) =>
            {
                List <ImageFileDescription> lImagesFilesList         = new List <ImageFileDescription>();
                List <ImagesProcessingData> lImagesAllConcurrentData = new List <ImagesProcessingData>();
                List <ObservedClCoverData>  lObservedData            = new List <ObservedClCoverData>();

                #region check available data

                //ImagesBaseSourcePath = "";
                //ConcurrentAndStatsXMLfilesDir = "";
                //ObservedDataCSVfile = "";
                //DestinationPath = "";
                //DateTimeFilterTolerance = new TimeSpan(0, 5, 0);

                #region ImagesBaseSourcePath

                theLogWindow = ServiceTools.LogAText(theLogWindow, "Started enumerating images...");

                if (!Directory.Exists(ImagesBaseSourcePath))
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to find sky-images base source path. Please check if it does exist and contain at least one sky-image *.jpg file.");
                    FINISHED();
                    return;
                }

                lImagesFilesList =
                    Directory.GetFiles(ImagesBaseSourcePath, "*.jpg", SearchOption.AllDirectories)
                    .ToList()
                    .ConvertAll(str => new ImageFileDescription(str));

                if (!lImagesFilesList.Any())
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to find any sky-images. Please check if at least one sky-image exists in base source path.");
                    FINISHED();
                    return;
                }

                #endregion ImagesBaseSourcePath


                #region ConcurrentAndStatsXMLfilesDir

                theLogWindow = ServiceTools.LogAText(theLogWindow, "Started reading concurrent data and stats data using existing XML files...");

                if (!Directory.Exists(ConcurrentAndStatsXMLfilesDir))
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to find sky-images pre-calculated concurrent data XML files directory: " +
                                                         Environment.NewLine + ConcurrentAndStatsXMLfilesDir + Environment.NewLine +
                                                         ". Please check if it does exist.");
                    FINISHED();
                    return;
                }



                #region read all concurrent data using all-included XML files

                List <string> lXMLfiles =
                    Directory.GetFiles(ConcurrentAndStatsXMLfilesDir, "ImagesCameraPositioning-stats-*-camID?.xml", SearchOption.AllDirectories).ToList();
                if (!lXMLfiles.Any())
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to find any XML file satisfied the following mask: \"ImagesCameraPositioning-stats-*-camID?.xml\". Please check if at least one XML of that kind does exist in directory " +
                                                         ConcurrentAndStatsXMLfilesDir);
                    FINISHED();
                    return;
                }

                foreach (string xmlFile in lXMLfiles)
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow, "trying to read and parse file " + xmlFile);

                    try
                    {
                        List <ImagesProcessingData> currFileContents =
                            ServiceTools.ReadObjectFromXML(xmlFile, typeof(List <ImagesProcessingData>)) as
                            List <ImagesProcessingData>;
                        if (currFileContents != null)
                        {
                            lImagesAllConcurrentData.AddRange(currFileContents);
                        }
                    }
                    catch (Exception ex)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "ERROR! Unable to read data from file: " + xmlFile + Environment.NewLine + ex.Message);
                        continue;
                    }
                }

                if (!lImagesAllConcurrentData.Any())
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to read any concurrent data. Please check the directory for files containing valid concurrent data XML files: " + Environment.NewLine +
                                                         "directory: " + ConcurrentAndStatsXMLfilesDir + Environment.NewLine +
                                                         "XML files mask: \"ImagesCameraPositioning-stats-*-camID?.xml\"");
                    FINISHED();
                    return;
                }

                #endregion read all concurrent data using all-included XML files


                #endregion ConcurrentAndStatsXMLfilesDir



                #region ObservedDataCSVfile

                theLogWindow = ServiceTools.LogAText(theLogWindow, "Started reading observed data CSV file...");

                if (!File.Exists(ObservedDataCSVfile))
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to read observed data CSV file: " + ObservedDataCSVfile);
                    FINISHED();
                    return;
                }

                List <List <string> > lCSVfileContents = ServiceTools.ReadDataFromCSV(ObservedDataCSVfile, 1, true);

                if (!lCSVfileContents.Any())
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to read observed data CSV file: " + ObservedDataCSVfile);
                    FINISHED();
                    return;
                }

                lObservedData = lCSVfileContents.ConvertAll(lStr => new ObservedClCoverData(lStr));

                #endregion ObservedDataCSVfile



                #region DestinationPath

                if (!Directory.Exists(DestinationPath))
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to find the output directory: " + DestinationPath);
                    FINISHED();
                    return;
                }

                #endregion DestinationPath



                #endregion check available data



                List <Tuple <ObservedClCoverData, ImageFileDescription> > lImagesFilteredByAvailableObservedData =
                    new List <Tuple <ObservedClCoverData, ImageFileDescription> >();


                #region filter images by available observed data using DateTimeFilterTolerance

                theLogWindow = ServiceTools.LogAText(theLogWindow, "Filtering by observed data available...");

                foreach (ObservedClCoverData observedData in lObservedData)
                {
                    DateTime currObservedDatumDateTime = observedData.dt;
                    List <Tuple <ObservedClCoverData, ImageFileDescription> > lImagesCloseToCurrObservedDatum = lImagesFilesList
                                                                                                                .Where(ifd =>
                    {
                        TimeSpan tspan =
                            new TimeSpan(Math.Abs((ifd.currImageDateTime - currObservedDatumDateTime).Ticks));
                        return(tspan <= DateTimeFilterTolerance);
                    })
                                                                                                                .ToList()
                                                                                                                .ConvertAll(ifd => new Tuple <ObservedClCoverData, ImageFileDescription>(observedData, ifd));

                    lImagesFilteredByAvailableObservedData.AddRange(lImagesCloseToCurrObservedDatum);
                }

                #endregion filter images by available observed data using DateTimeFilterTolerance

                List <SkyImagesDataWith_Concurrent_Stats_CloudCover> lImagesFilteredByAnyAvailableData =
                    new List <SkyImagesDataWith_Concurrent_Stats_CloudCover>();

                #region map available stats data using image filename

                theLogWindow = ServiceTools.LogAText(theLogWindow, "Mapping concurrent and stats data...");

                lImagesFilteredByAnyAvailableData = lImagesFilteredByAvailableObservedData.ConvertAll(tpl =>
                {
                    SkyImagesDataWith_Concurrent_Stats_CloudCover retVal = null;
                    try
                    {
                        ImagesProcessingData foundConcurrentData =
                            lImagesAllConcurrentData.Where(ipd => Path.GetFileName(ipd.filename) == tpl.Item2.fileName)
                            .ElementAt(0);
                        retVal = new SkyImagesDataWith_Concurrent_Stats_CloudCover()
                        {
                            skyImageFullFileName   = tpl.Item2.fullFileName,
                            skyImageFileName       = tpl.Item2.fileName,
                            currImageDateTime      = tpl.Item2.currImageDateTime,
                            observedCloudCoverData = tpl.Item1,
                            concurrentDataXMLfile  = foundConcurrentData.concurrentDataXMLfile,
                            concurrentData         = foundConcurrentData.concurrentData,
                            grixyrgbStatsXMLfile   = foundConcurrentData.grixyrgbStatsXMLfile,
                            grixyrgbStats          = foundConcurrentData.grixyrgbStats
                        };
                        //(tpl.Item1, tpl.Item2, foundConcurrentData);
                    }
                    catch (Exception ex)
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "ERROR! Couldn`t find concurrent data for file " + Path.GetFileName(tpl.Item2.fileName) +
                                                             Environment.NewLine + ex.Message);
                    }
                    return(retVal);
                });

                lImagesFilteredByAnyAvailableData.RemoveAll(tpl => tpl == null);

                if (!lImagesFilteredByAnyAvailableData.Any())
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "There is no images remain after filtering using all available data. Output will be empty.");
                }

                #endregion map available stats data using image filename

                theLogWindow = ServiceTools.LogAText(theLogWindow, "Writing output list to file...");

                string strOutputXMLfileName = DestinationPath +
                                              ((DestinationPath.Last() == Path.DirectorySeparatorChar)
                                                  ? ("")
                                                  : (Path.DirectorySeparatorChar.ToString())) + "FilesListToDetectCloudCover.xml";

                ServiceTools.WriteObjectToXML(lImagesFilteredByAnyAvailableData, strOutputXMLfileName);

                theLogWindow = ServiceTools.LogAText(theLogWindow, "images list wrote to file: " + strOutputXMLfileName);
            };


            bgwCreateList.RunWorkerAsync();
        }
Пример #13
0
 private void FINISHED()
 {
     theLogWindow = ServiceTools.LogAText(theLogWindow, "====  FINISHED  ====");
 }
Пример #14
0
        private void BgwSnapshotsFilteringWithSunElevation_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker selfWorker = sender as BackgroundWorker;

            object[] bgwArgs                 = e.Argument as object[];
            string   SnapshotsBasePath       = bgwArgs[0] as string;
            string   concurrentDataFilesPath = bgwArgs[1] as string;
            string   directoryToMoveFilesTo  = bgwArgs[2] as string;

            DirectoryInfo srcDir = new DirectoryInfo(SnapshotsBasePath);

            if (!srcDir.Exists)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "Операция не выполнена. Не найдена директория:" + Environment.NewLine + SnapshotsBasePath +
                                                     Environment.NewLine);
                //ThreadSafeOperations.SetTextTB(tbLog, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + fromPath + Environment.NewLine, true);
                return;
            }


            List <FileInfo> lFileList2Process = srcDir.GetFiles("*.jpg", SearchOption.AllDirectories).ToList();
            List <FileInfoWithSnapshotDateTime> lSnapshotsInfos =
                lFileList2Process.ConvertAll(finfo => new FileInfoWithSnapshotDateTime(finfo));


            #region read concurrent data from XML files

            theLogWindow = ServiceTools.LogAText(theLogWindow, "started concurrent data reading");

            List <Tuple <string, ConcurrentData> > lImagesConcurrentData = new List <Tuple <string, ConcurrentData> >();

            List <string> filesListConcurrentData =
                new List <string>(Directory.EnumerateFiles(concurrentDataFilesPath,
                                                           ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(), SearchOption.AllDirectories));

            int totalFilesCountToRead = filesListConcurrentData.Count;
            int filesRead             = 0;
            int currProgressPerc      = 0;
            selfWorker.ReportProgress(0);
            List <Dictionary <string, object> > lDictionariesConcurrentData = new List <Dictionary <string, object> >();
            foreach (string strConcDataXMLFile in filesListConcurrentData)
            {
                Dictionary <string, object> currDict = ServiceTools.ReadDictionaryFromXML(strConcDataXMLFile);
                currDict.Add("XMLfileName", Path.GetFileName(strConcDataXMLFile));

                lDictionariesConcurrentData.Add(currDict);

                #region calculate and report progress

                filesRead++;
                double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead;
                if (progress - (double)currProgressPerc > 1.0d)
                {
                    currProgressPerc = Convert.ToInt32(progress);
                    selfWorker.ReportProgress(currProgressPerc);
                }

                if (selfWorker.CancellationPending)
                {
                    return;
                }

                #endregion calculate and report progress
            }
            lDictionariesConcurrentData.RemoveAll(dict => dict == null);


            List <ConcurrentData> lConcurrentData =
                lDictionariesConcurrentData.ConvertAll <ConcurrentData>(dict =>
            {
                ConcurrentData retVal = null;
                try
                {
                    retVal = new ConcurrentData(dict);
                    GPSdata gpsOfGPSstring = new GPSdata((string)dict["GPSdata"], GPSdatasources.CloudCamArduinoGPS,
                                                         retVal.datetimeUTC.Date);
                    if (!gpsOfGPSstring.validGPSdata)
                    {
                        throw new Exception("invalid GPS data");
                    }
                }
                catch (Exception ex)
                {
                    string strError = "couldn`t parse XML file " + dict["XMLfileName"] + " : " +
                                      Environment.NewLine + ex.Message;
                    return(null);
                }

                if (retVal.gps.validGPSdata)
                {
                    return(retVal);
                }
                else
                {
                    return(null);
                }
            });
            lConcurrentData.RemoveAll(val => val == null);



            // map obtained concurrent data to images by its datetime
            theLogWindow = ServiceTools.LogAText(theLogWindow, "started concurrent data mapping");
            int totalrecordsToMap = lSnapshotsInfos.Count;
            int recordsMapped     = 0;
            currProgressPerc = 0;
            selfWorker.ReportProgress(0);
            foreach (FileInfoWithSnapshotDateTime info in lSnapshotsInfos)
            {
                DateTime currImgDT = info.dateTime;

                ConcurrentData nearestConcurrentData = lConcurrentData.Aggregate((cDt1, cDt2) =>
                {
                    TimeSpan tspan1 = new TimeSpan(Math.Abs((cDt1.datetimeUTC - currImgDT).Ticks));
                    TimeSpan tspan2 = new TimeSpan(Math.Abs((cDt2.datetimeUTC - currImgDT).Ticks));
                    return((tspan1 <= tspan2) ? (cDt1) : (cDt2));
                });


                if (new TimeSpan(Math.Abs((nearestConcurrentData.datetimeUTC - currImgDT).Ticks)) <=
                    TimeSpanForConcurrentDataMappingTolerance)
                {
                    info.concurrentData = nearestConcurrentData;
                }

                #region calculate and report progress

                recordsMapped++;
                double progress = 100.0d * (double)recordsMapped / (double)totalrecordsToMap;
                if (progress - (double)currProgressPerc > 1.0d)
                {
                    currProgressPerc = Convert.ToInt32(progress);
                    selfWorker.ReportProgress(currProgressPerc);
                }

                if (selfWorker.CancellationPending)
                {
                    return;
                }

                #endregion calculate and report progress
            }

            #endregion read concurrent data from XML files

            List <FileInfo> filesToMove = new List <FileInfo>();
            filesToMove.AddRange(
                lSnapshotsInfos.Where(inf => inf.concurrentData == null).ToList().ConvertAll(inf => inf.finfo));
            lSnapshotsInfos.RemoveAll(inf => inf.concurrentData == null);

            filesToMove.AddRange(lSnapshotsInfos.Where(inf =>
            {
                GPSdata currGPS = new GPSdata(inf.concurrentData.GPSdata, GPSdatasources.CloudCamArduinoGPS,
                                              inf.dateTime.Date);
                var spa = currGPS.SunZenithAzimuth();
                return(spa.ZenithAngle >= 85.0);
            }).ToList().ConvertAll(inf => inf.finfo));


            totalFilesCountToRead = filesToMove.Count;
            filesRead             = 0;
            currProgressPerc      = 0;
            selfWorker.ReportProgress(0);
            foreach (FileInfo inf in filesToMove)
            {
                #region calculate and report progress

                filesRead++;
                double progress = 100.0d * (double)filesRead / (double)totalFilesCountToRead;
                if (progress - (double)currProgressPerc > 1.0d)
                {
                    currProgressPerc = Convert.ToInt32(progress);
                    selfWorker.ReportProgress(currProgressPerc);
                }

                if (selfWorker.CancellationPending)
                {
                    return;
                }

                #endregion calculate and report progress

                string strFilenameMoveTo = directoryToMoveFilesTo +
                                           ((directoryToMoveFilesTo.Last() == Path.DirectorySeparatorChar)
                    ? ("")
                    : (Path.DirectorySeparatorChar.ToString()));

                string currImgFilenameRelPath = ConventionalTransitions.MakeRelativePath(inf.FullName, SnapshotsBasePath);
                strFilenameMoveTo += currImgFilenameRelPath;

                theLogWindow = ServiceTools.LogAText(theLogWindow, "moving " + inf.FullName);

                if (!ServiceTools.CheckIfDirectoryExists(strFilenameMoveTo))
                {
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "Unable to move file " + Environment.NewLine + inf.FullName + Environment.NewLine + "to:" +
                                                         Environment.NewLine + strFilenameMoveTo + Environment.NewLine +
                                                         "Directory couldn`t be located or created");
                    continue;
                }

                File.Move(inf.FullName, strFilenameMoveTo);
            }

            selfWorker.ReportProgress(0);
        }
Пример #15
0
        private void bgwCopier_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker SelfWorker = sender as BackgroundWorker;

            object[] bgwArgs  = e.Argument as object[];
            string   fromPath = bgwArgs[0] as string;
            string   concurrentDataFilesPath = bgwArgs[1] as string;
            string   toPath = bgwArgs[2] as string;
            string   imagesStatsXMLfilesDir = bgwArgs[3] as string;

            DirectoryInfo dir           = new DirectoryInfo(fromPath);
            String        destDirectory = toPath +
                                          ((toPath.Last() == Path.DirectorySeparatorChar)
                                       ? ("")
                                       : (Path.DirectorySeparatorChar.ToString()));

            if (!dir.Exists)
            {
                theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                     "Операция не выполнена. Не найдена директория:" + Environment.NewLine + fromPath +
                                                     Environment.NewLine);
                //ThreadSafeOperations.SetTextTB(tbLog, "Операция не выполнена. Не найдена директория:" + Environment.NewLine + fromPath + Environment.NewLine, true);
                return;
            }


            FileInfo[] FileList2Process = dir.GetFiles("*.jpg", SearchOption.AllDirectories);
            List <Tuple <string, string> > imagesStatsXMLfiles = new List <Tuple <string, string> >();

            if (Directory.Exists(imagesStatsXMLfilesDir))
            {
                imagesStatsXMLfiles =
                    (new DirectoryInfo(imagesStatsXMLfilesDir)).EnumerateFiles(
                        ConventionalTransitions.ImageGrIxYRGBstatsFileNamesPattern(), SearchOption.AllDirectories)
                    .ToList()
                    .ConvertAll(fInfo => new Tuple <string, string>(fInfo.Name, fInfo.FullName));
            }


            DirectoryInfo dirConcurrentDataFiles = new DirectoryInfo(concurrentDataFilesPath);
            List <Tuple <string, DateTime> > lConcurrentDataFiles =
                dirConcurrentDataFiles.EnumerateFiles(ConventionalTransitions.ImageConcurrentDataFilesNamesPattern(),
                                                      SearchOption.AllDirectories).ToList().ConvertAll(fInfo =>
            {
                // data-2015-12-15T06-12-56.0590302Z.xml
                string strDateTimeOfFile = Path.GetFileNameWithoutExtension(fInfo.Name).Substring(5, 28);
                strDateTimeOfFile        = strDateTimeOfFile.Substring(0, 11) +
                                           strDateTimeOfFile.Substring(11).Replace('-', ':');
                DateTime currFileDT = DateTime.Parse(strDateTimeOfFile, null, System.Globalization.DateTimeStyles.AdjustToUniversal);
                currFileDT          = DateTime.SpecifyKind(currFileDT, DateTimeKind.Utc);
                return(new Tuple <string, DateTime>(fInfo.FullName, currFileDT));
            });



            int filesCount = FileList2Process.Length;

            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                 "searching in directory: " + dir.FullName + Environment.NewLine);
            //ThreadSafeOperations.SetTextTB(tbLog, "searching in directory: " + dir.FullName + Environment.NewLine, true);
            theLogWindow = ServiceTools.LogAText(theLogWindow, "files found count: " + filesCount + Environment.NewLine);
            //ThreadSafeOperations.SetTextTB(tbLog, "files found count: " + filesCount + Environment.NewLine, true);

            String usedDateTimes = "";

            List <DateTime> listUsedHours = new List <DateTime>();

            int counter = 0;

            foreach (FileInfo fileInfo in FileList2Process)
            {
                if (SelfWorker.CancellationPending)
                {
                    break;
                }
                counter++;
                double percCounter = (double)counter * 1000.0d / (double)filesCount;
                SelfWorker.ReportProgress(Convert.ToInt32(percCounter));


                Image     anImage  = Image.FromFile(fileInfo.FullName);
                ImageInfo newIInfo = new ImageInfo(anImage);
                //ThreadSafeOperations.SetTextTB(tbLog, "processing file " + fileInfo.Name + Environment.NewLine, true);


                //String curDateTime = "";
                int minute = 0;
                //String dateTime = (String)newIInfo.getValueByKey("DateTime");
                String strDateTimeEXIF = (String)newIInfo.getValueByKey("ExifDTOrig");
                if (strDateTimeEXIF == null)
                {
                    //попробуем вытащить из имени файла
                    string strDateTime = fileInfo.Name;
                    strDateTime     = strDateTime.Substring(4, 19);
                    strDateTimeEXIF = strDateTime;
                }


                //curDateTime = dateTime;
                DateTime curImgDateTime;
                DateTime theHour = RoundToHour(DateTime.UtcNow);
                try
                {
                    //curImgDateTime = DateTimeOfString(strDateTimeEXIF);
                    curImgDateTime = ConventionalTransitions.DateTimeOfSkyImageFilename(fileInfo.Name);
                    theHour        = RoundToHour(curImgDateTime);
                }
                catch (Exception ex)
                {
                    continue;
                }


                //minute = Convert.ToInt32(strDateTimeEXIF.Substring(14, 2));

                //if ((minute == 0) && (!listUsedHours.Contains(theHour)))
                if (new TimeSpan(Math.Abs((theHour - curImgDateTime).Ticks)) <= filterTolerance)
                {
                    #region copy the image file itself
                    listUsedHours.Add(theHour);

                    string dateDirectorySuffix   = curImgDateTime.ToString("yyyy-MM-dd");
                    string currDateDestDirectory = destDirectory + dateDirectorySuffix + Path.DirectorySeparatorChar;
                    if (!ServiceTools.CheckIfDirectoryExists(currDateDestDirectory))
                    {
                        currDateDestDirectory = destDirectory;
                    }



                    String newFileName = currDateDestDirectory + fileInfo.Name;
                    File.Copy(fileInfo.FullName, newFileName);
                    theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                         "COPY: " + fileInfo.FullName + "   >>>   " + newFileName + Environment.NewLine);
                    //ThreadSafeOperations.SetTextTB(tbLog, "COPY: " + fileInfo.FullName + "   >>>   " + newFileName + Environment.NewLine, true);
                    #endregion copy the image file itself


                    #region find and copy the GrIx,YRGB stats data file
                    if (imagesStatsXMLfiles.Any())
                    {
                        string xmlStatsFileName =
                            ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(fileInfo.FullName, "", false);

                        Tuple <string, string> foundXMLfile =
                            imagesStatsXMLfiles.Find(tpl => tpl.Item1 == xmlStatsFileName);

                        if (foundXMLfile != null)
                        {
                            string sStatsXMLfilename   = foundXMLfile.Item2;
                            string newStatsXMLfilename = currDateDestDirectory + foundXMLfile.Item1;
                            File.Copy(sStatsXMLfilename, newStatsXMLfilename);
                            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                 "COPY: " + sStatsXMLfilename + "   >>>   " + newStatsXMLfilename + Environment.NewLine);
                            //ThreadSafeOperations.SetTextTB(tbLog,
                            //    "COPY: " + sStatsXMLfilename + "   >>>   " + newStatsXMLfilename + Environment.NewLine,
                            //    true);
                        }
                        else
                        {
                            theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                                 "========== ERROR: couldn`t find GrIx,YRGB stats XML file" + Environment.NewLine);
                            //ThreadSafeOperations.SetTextTB(tbLog,
                            //    "========== ERROR: couldn`t find GrIx,YRGB stats XML file" + Environment.NewLine, true);
                        }
                    }
                    #endregion find and copy the GrIx,YRGB stats data file


                    #region find and copy concurrent data XML file
                    if (lConcurrentDataFiles.Any())
                    {
                        //найдем ближайший по времени
                        List <Tuple <string, TimeSpan> > lCurrFileConcurrentDataNearest =
                            lConcurrentDataFiles.ConvertAll(
                                tpl =>
                                new Tuple <string, TimeSpan>(tpl.Item1,
                                                             new TimeSpan(Math.Abs((tpl.Item2 - curImgDateTime).Ticks))));
                        lCurrFileConcurrentDataNearest.Sort(new Comparison <Tuple <string, TimeSpan> >((tpl1, tpl2) =>
                        {
                            if (tpl1 == null)
                            {
                                if (tpl2 == null)
                                {
                                    return(0);
                                }
                                else
                                {
                                    return(-1);
                                }
                            }
                            else
                            {
                                if (tpl2 == null)
                                {
                                    return(1);
                                }
                                else
                                {
                                    return(tpl1.Item2.CompareTo(tpl2.Item2));
                                }
                            }
                        }));

                        GPSdata gps = new GPSdata();
                        Tuple <string, TimeSpan> nearestConcurrentDataFile = null;
                        int concurrentDataFileIdx = 0;

                        while (!gps.validGPSdata)
                        {
                            nearestConcurrentDataFile = lCurrFileConcurrentDataNearest[concurrentDataFileIdx];

                            Dictionary <string, object> dictSavedData = ServiceTools.ReadDictionaryFromXML(nearestConcurrentDataFile.Item1);

                            gps = new GPSdata((string)dictSavedData["GPSdata"],
                                              GPSdatasources.CloudCamArduinoGPS,
                                              DateTime.Parse((string)dictSavedData["GPSDateTimeUTC"], null,
                                                             System.Globalization.DateTimeStyles.RoundtripKind));

                            concurrentDataFileIdx++;
                        }

                        string currValidConcurrentDataFile         = nearestConcurrentDataFile.Item1;
                        string currValidConcurrentDataFileToCopyTo = currDateDestDirectory + "data-" +
                                                                     Path.GetFileNameWithoutExtension(fileInfo.FullName) + ".xml";
                        File.Copy(currValidConcurrentDataFile, currValidConcurrentDataFileToCopyTo);
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "COPY: " + currValidConcurrentDataFile + "   >>>   " + currValidConcurrentDataFileToCopyTo +
                                                             Environment.NewLine);
                        //ThreadSafeOperations.SetTextTB(tbLog,
                        //    "COPY: " + currValidConcurrentDataFile + "   >>>   " + currValidConcurrentDataFileToCopyTo +
                        //    Environment.NewLine, true);
                    }
                    else
                    {
                        theLogWindow = ServiceTools.LogAText(theLogWindow,
                                                             "========== ERROR: couldn`t find concurrent data file for " + fileInfo.FullName +
                                                             Environment.NewLine);
                        //ThreadSafeOperations.SetTextTB(tbLog, "========== ERROR: couldn`t find concurrent data file for " + fileInfo.FullName + Environment.NewLine, true);
                    }
                    #endregion find and copy concurrent data XML file


                    theLogWindow.ClearLog();
                }
            }
        }