/// <summary>
        /// Reads through multiple directories to read multiple files of spectral indices.
        /// The spectral indices are combined day-wise into pivot-tables which are written to file.
        /// </summary>
        /// <param name="indexPropertiesConfig"></param>
        /// <param name="inputDirInfo"></param>
        /// <param name="opDir"></param>
        public static void ReadAllSpectralIndicesAndWriteToDataTable(FileInfo indexPropertiesConfig, DirectoryInfo inputDirInfo, DirectoryInfo opDir)
        {
            Dictionary <string, IndexProperties> dictIP = IndexProperties.GetIndexProperties(indexPropertiesConfig);

            dictIP = InitialiseIndexProperties.FilterIndexPropertiesForSpectralOnly(dictIP);
            string[] spectrogramKeys = dictIP.Keys.ToArray();

            int count = 0;

            DirectoryInfo[] dirList = inputDirInfo.GetDirectories();
            foreach (DirectoryInfo dir in dirList)
            {
                // ASSUME THAT FILE PATHS IN DIRECTORY HAVE THIS STRUCTURE
                // SERF_20130915_201727_000.wav\Towsey.Acoustic\SERF_20130915_201727_000.ACI.csv; SERF_20130915_201727_000.BGN.csv etc

                string   targetFileName = dir.Name;
                string[] nameArray      = targetFileName.Split('_');
                string   stem           = nameArray[0];
                string   date           = nameArray[1];
                string   time           = nameArray[2];
                int      year           = int.Parse(date.Substring(0, 4));
                int      month          = int.Parse(date.Substring(4, 2));
                int      day            = int.Parse(date.Substring(6, 2));
                int      hour           = int.Parse(time.Substring(0, 2));
                int      minute         = int.Parse(time.Substring(2, 2));
                int      second         = int.Parse(time.Substring(4, 2));
                DateTime thisDate       = new DateTime(year, month, day, hour, minute, second);

                // get target file name without extention
                nameArray      = targetFileName.Split('.');
                targetFileName = nameArray[0];
                string targetDirectory = dir.FullName + @"\Towsey.Acoustic";
                var    targetDirInfo   = targetDirectory.ToDirectoryInfo();

                // construct the output file name
                string opFileName = stem + "_" + date + ".SpectralIndices.DataTable.csv";
                string opFilePath = Path.Combine(opDir.FullName, opFileName);

                //Logger.Info("Reading spectral-indices for file: " + targetFileName);

                ReadSpectralIndicesAndWriteToDataTable(spectrogramKeys, thisDate, targetDirInfo, targetFileName, opFilePath);

                // for DEBUG
                //count++;
                //if (count >= 20) break;
            } // foreach (DirectoryInfo dir in dirList)
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uses a dictionary of index properties to draw an image of summary index tracks.
        /// </summary>
        /// <param name="csvFile"> file containing the summary indices.</param>
        /// <param name="indexPropertiesConfig"> indexPropertiesConfig.</param>
        /// <param name="title">image title.</param>
        /// <param name="indexCalculationDuration"> The index Calculation Duration. </param>
        /// <param name="recordingStartDate"> The recording Start Date. </param>
        public static Image <Rgb24> DrawImageOfSummaryIndexTracks(
            FileInfo csvFile,
            FileInfo indexPropertiesConfig,
            string title,
            TimeSpan indexCalculationDuration,
            DateTimeOffset?recordingStartDate)
        {
            Dictionary <string, IndexProperties> dictionaryOfIndexProperties = IndexProperties.GetIndexProperties(indexPropertiesConfig);

            dictionaryOfIndexProperties = InitialiseIndexProperties.GetDictionaryOfSummaryIndexProperties(dictionaryOfIndexProperties);
            return(DrawImageOfSummaryIndices(
                       dictionaryOfIndexProperties,
                       csvFile,
                       title,
                       indexCalculationDuration,
                       recordingStartDate));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts summary indices to a tracks image
        /// </summary>
        /// <param name="listOfIndexProperties"></param>
        /// <param name="dictionaryOfSummaryIndices"></param>
        /// <param name="titleText"></param>
        /// <param name="indexCalculationDuration"></param>
        /// <param name="recordingStartDate"></param>
        /// <param name="sunriseDataFile"></param>
        /// <param name="errors"></param>
        public static Bitmap DrawImageOfSummaryIndices(
            Dictionary <string, IndexProperties> listOfIndexProperties,
            Dictionary <string, double[]> dictionaryOfSummaryIndices,
            string titleText,
            TimeSpan indexCalculationDuration,
            DateTimeOffset?recordingStartDate,
            FileInfo sunriseDataFile   = null,
            List <GapsAndJoins> errors = null,
            bool verbose = false)
        {
            // to translate past keys into current keys
            Dictionary <string, string> translationDictionary = InitialiseIndexProperties.GetKeyTranslationDictionary();

            const int trackHeight = DefaultTrackHeight;
            int       scaleLength = 0;
            var       bitmapList  = new List <Tuple <IndexProperties, Image> >(dictionaryOfSummaryIndices.Keys.Count);

            // accumulate the individual tracks in a List
            foreach (string key in dictionaryOfSummaryIndices.Keys)
            {
                string correctKey = key;
                if (!listOfIndexProperties.ContainsKey(key))
                {
                    if (translationDictionary.ContainsKey(key))
                    {
                        correctKey = translationDictionary[key];
                        LoggedConsole.WriteWarnLine(
                            "The csv header is an unknown index <{0}>. Translated to <{1}>",
                            key,
                            correctKey);
                    }
                    else
                    {
                        if (verbose)
                        {
                            Logger.Warn(
                                "A index properties configuration could not be found for {0} (not even in the translation directory). Property is ignored and not rendered"
                                .Format2(key));
                        }

                        continue;
                    }
                }

                IndexProperties ip = listOfIndexProperties[correctKey];
                if (!ip.DoDisplay)
                {
                    continue;
                }

                string   name  = ip.Name;
                double[] array = dictionaryOfSummaryIndices[key];
                scaleLength = array.Length;
                Image bitmap = ip.GetPlotImage(array, errors);

                bitmapList.Add(Tuple.Create(ip, bitmap));
            }

            var listOfBitmaps = bitmapList
                                .OrderBy(tuple => tuple.Item1.Order)
                                .Select(tuple => tuple.Item2)
                                .Where(b => b != null).ToList();

            //set up the composite image parameters
            int      X_offset      = 2;
            int      graphWidth    = X_offset + scaleLength;
            int      imageWidth    = X_offset + scaleLength + TrackEndPanelWidth;
            TimeSpan scaleDuration = TimeSpan.FromMinutes(scaleLength);
            int      imageHt       = trackHeight * (listOfBitmaps.Count + 4); //+3 for title and top and bottom time tracks
            Bitmap   titleBmp      = ImageTrack.DrawTitleTrack(imageWidth, trackHeight, titleText);

            //Bitmap time1Bmp = ImageTrack.DrawTimeTrack(scaleDuration, TimeSpan.Zero, DrawSummaryIndices.TimeScale, graphWidth, TrackHeight, "Time (hours)");
            TimeSpan       xAxisPixelDuration = indexCalculationDuration;
            TimeSpan       fullDuration       = TimeSpan.FromTicks(xAxisPixelDuration.Ticks * graphWidth);
            Bitmap         timeBmp1           = ImageTrack.DrawTimeRelativeTrack(fullDuration, graphWidth, trackHeight);
            Bitmap         timeBmp2           = timeBmp1;
            Bitmap         suntrack           = null;
            DateTimeOffset?dateTimeOffset     = recordingStartDate;

            if (dateTimeOffset.HasValue)
            {
                // draw extra time scale with absolute start time. AND THEN Do SOMETHING WITH IT.
                timeBmp2 = ImageTrack.DrawTimeTrack(fullDuration, dateTimeOffset, graphWidth, trackHeight);
                suntrack = SunAndMoon.AddSunTrackToImage(scaleLength, dateTimeOffset, sunriseDataFile);
            }

            //draw the composite bitmap
            var imageList = new List <Image>();

            imageList.Add(titleBmp);
            imageList.Add(timeBmp1);
            for (int i = 0; i < listOfBitmaps.Count; i++)
            {
                imageList.Add(listOfBitmaps[i]);
            }

            imageList.Add(timeBmp2);
            imageList.Add(suntrack);
            Bitmap compositeBmp = (Bitmap)ImageTools.CombineImagesVertically(imageList);

            return(compositeBmp);
        }