private void SetEquations(MeterCalibration calibration)
        {
            var slope1     = _parsedData.MeterConst1;
            var intercept1 = _parsedData.MeterConst2;
            var slope2     = _parsedData.MeterConst3;
            var intercept2 = _parsedData.MeterConst4;

            var interceptUnit = CommonMapper.GetUnitSystem(_parsedData).VelocityUnitId;

            //Sample files show: C5=0, C3=C1, C4=C2. This should be 1 segment equation.
            if (!AreEqualDoubles(slope1, 0.0d) || !AreEqualDoubles(intercept1, 0.0d))
            {
                calibration.Equations.Add(
                    new MeterCalibrationEquation {
                    Slope = slope1, Intercept = intercept1, InterceptUnitId = interceptUnit
                });
            }

            //Assuming this is a 2 segment equation setup:
            if (!AreEqualDoubles(slope1, slope2) ||
                !AreEqualDoubles(intercept1, intercept2))
            {
                calibration.Equations.Add(
                    new MeterCalibrationEquation {
                    Slope = slope2, Intercept = intercept2, InterceptUnitId = interceptUnit
                });
            }
        }
Exemplo n.º 2
0
        private double CalculateDepthObservationVelocity(int revolutionCount, int observationInterval,
                                                         MeterCalibration meterCalibration)
        {
            var velocity = 0.0;

            var frequency = (float)revolutionCount / observationInterval;

            foreach (var equation in meterCalibration.Equations)
            {
                var rangeStart = equation.RangeStart.GetValueOrDefault();
                var rangeEnd   = equation.RangeEnd.GetValueOrDefault();

                if (frequency > rangeStart &&
                    (frequency < rangeEnd || DoubleHelper.HasMinimalDifference(frequency, rangeEnd)))
                {
                    velocity = frequency * equation.Slope + equation.Intercept;
                    break;
                }
            }

            Log.Info(
                $"VelocityDepthObservation: Revolutions={revolutionCount}, Interval={observationInterval}, Frequency={frequency} m/s, Velocity={velocity} m/s");

            return(velocity);
        }
        private MeterCalibration CreateMeterCalibration(Meter meter)
        {
            var meterCalibration = new MeterCalibration
            {
                FirmwareVersion = _ehsn.InstrumentDeployment?.GeneralInfo?.firmware,
                Manufacturer    = _ehsn.InstrumentDeployment?.GeneralInfo?.manufacturer.WithDefaultValue(Config.UnknownMeterPlaceholder),
                Model           = _ehsn.InstrumentDeployment?.GeneralInfo?.model.WithDefaultValue(Config.UnknownMeterPlaceholder),
                SerialNumber    = meter.Number.WithDefaultValue(Config.UnknownMeterPlaceholder),
                Configuration   = meter.MeterCalibDate,
                MeterType       = GetMappedEnum(_ehsn.InstrumentDeployment?.GeneralInfo?.model, KnownMeterTypes),
            };

            foreach (var equation in meter.Equation ?? new MeterEquation[0])
            {
                var slope     = equation.Slope.ToNullableDouble();
                var intercept = equation.Intercept.ToNullableDouble();

                if (!slope.HasValue || !intercept.HasValue)
                {
                    continue;
                }

                meterCalibration.Equations.Add(new MeterCalibrationEquation
                {
                    Slope           = slope.Value,
                    Intercept       = intercept.Value,
                    InterceptUnitId = Units.VelocityUnitId
                });
            }

            return(meterCalibration);
        }
Exemplo n.º 4
0
        private List <VelocityDepthObservation> GetVelocityDepthObservations(ManualGaugingRecord gauging,
                                                                             MeterCalibration meterCalibration)
        {
            return(gauging.Observations.Select(observation =>
            {
                var revolutionCount = observation.Revolutions;
                var observationInterval = observation.IntervalInSeconds;
                if (observation.Revolutions == 0 || observation.IntervalInSeconds == 0)
                {
                    revolutionCount = 0;
                    observationInterval = 0;
                }

                var velocity = CalculateDepthObservationVelocity(revolutionCount, observationInterval, meterCalibration);

                return new VelocityDepthObservation
                {
                    Depth = observation.ObservationDepth,
                    IsVelocityEstimated = false,
                    RevolutionCount = revolutionCount,
                    Velocity = velocity,
                    ObservationInterval = observationInterval
                };
            }).ToList());
        }
Exemplo n.º 5
0
 private static void AssignMeterCalibrations(MeterDetails meterDetails, MeterCalibration meterCalibrations)
 {
     foreach (var meterDetail in meterDetails.MeterDetailsItems)
     {
         meterDetail.Calibrations =
             meterCalibrations.MeterCalibrationItems.Where(item => item.MeterId == meterDetail.MeterId).ToList();
     }
 }
        private Vertical CreateEdgeVertical(Edge edge, VerticalType verticalType, MeterCalibration edgeMeter)
        {
            var taglinePosition = edge.Tagmark.ToNullableDouble() ?? 0;
            var depth           = edge.Depth.ToNullableDouble() ?? 0;
            var area            = edge.Area.ToNullableDouble() ?? 0;
            var velocity        = edge.Velocity.ToNullableDouble() ?? 0;
            var discharge       = edge.Discharge.ToNullableDouble() ?? 0;
            var width           = edge.Width.ToNullableDouble() ?? 0;
            var percentFlow     = edge.Flow.ToNullableDouble() ?? 0;

            var velocityObservation = new VelocityObservation
            {
                VelocityObservationMethod = PointVelocityObservationType.Surface,
                MeanVelocity     = velocity,
                DeploymentMethod = DeploymentMethodType.Unspecified,
                MeterCalibration = edgeMeter,
                Observations     =
                {
                    new VelocityDepthObservation
                    {
                        Depth               = depth,
                        Velocity            = velocity,
                        ObservationInterval = 0,
                        RevolutionCount     = 0
                    },
                },
            };

            return(new Vertical
            {
                VerticalType = verticalType,
                MeasurementTime = TimeHelper.CoerceDateTimeIntoUtcOffset(edge.Date, LocationInfo.UtcOffset),
                SequenceNumber = edge.panelId,
                TaglinePosition = taglinePosition,
                SoundedDepth = depth,
                EffectiveDepth = depth,
                MeasurementConditionData = new OpenWaterData(),
                FlowDirection = FlowDirectionType.Normal,
                VelocityObservation = velocityObservation,
                Segment = new Segment
                {
                    Area = area,
                    Discharge = discharge,
                    Width = width,
                    Velocity = velocity,
                    TotalDischargePortion = percentFlow,
                }
            });
        }
        private MeterCalibration GetMeterCalibration()
        {
            var meterTypeString = _parsedData.MeterType;
            var serialNumber    = _parsedData.MeterId;

            var manufacturer = AquaCalcConstants.AquaCalc5000;

            var calibration = new MeterCalibration
            {
                Manufacturer = manufacturer,
                Model        = meterTypeString,
                //SoftwareVersion: N/A
                FirmwareVersion = _parsedData.FirmwareVersion,
                SerialNumber    = serialNumber,
                MeterType       = GetMeterTypeEnumOrUnspecified(meterTypeString),
            };

            SetEquations(calibration);

            return(calibration);
        }
        private VelocityObservation GetVelocityObservation(VerticalObservation verticalObservation,
                                                           MeterCalibration meterCalibration, int sequenceNumber)
        {
            var depthObservations = GetVelocityDepthObservations(verticalObservation.ObservationPoints);

            var velocityObservationMethod = GetVelocityObservationMethodOrUnknown(verticalObservation, sequenceNumber);

            var velocityObservation = new VelocityObservation
            {
                MeterCalibration          = meterCalibration,
                DeploymentMethod          = CommonMapper.GetDeploymentMethodBySoundingWeight(_parsedData.SoundingWeight),
                VelocityObservationMethod = velocityObservationMethod,
                MeanVelocity = verticalObservation.MeanVelocity
            };

            foreach (var velocityDepthObservation in depthObservations)
            {
                velocityObservation.Observations.Add(velocityDepthObservation);
            }

            return(velocityObservation);
        }
Exemplo n.º 9
0
        private MeterCalibration CreateMeterCalibration(Station station)
        {
            var point = station.PointMeasurements.FirstOrDefault();

            var meterCalibration = new MeterCalibration
            {
                MeterType       = MeterType.Adv,
                Manufacturer    = "SonTek",
                Model           = "FlowTracker2",
                Configuration   = $"{DataFile.HandheldInfo.SerialNumber}/{DataFile.HandheldInfo.CpuSerialNumber}",
                SoftwareVersion = point?.HandheldInfo.SoftwareVersion,
                FirmwareVersion = point?.ProbeInfo.FirmwareVersion,
                SerialNumber    = point?.ProbeInfo.SerialNumber ?? DataFile.HandheldInfo.SerialNumber,
            };

            meterCalibration.Equations.Add(new MeterCalibrationEquation
            {
                InterceptUnitId = UnitSystem.VelocityUnitId
            });

            return(meterCalibration);
        }
 public VerticalMapper(DateTimeInterval measurementInterval, MeterCalibration meterCalibration)
 {
     _measurementInterval = measurementInterval;
     _meterCalibration    = meterCalibration;
 }
        private Vertical CreatePanelVertical(Panel panel, MeterCalibration meter)
        {
            var taglinePosition = panel.Tagmark.ToNullableDouble() ?? 0;
            var soundedDepth    = panel.DepthReading.ToNullableDouble() ?? 0;
            var effectiveDepth  = panel.DepthWithOffset.ToNullableDouble() ?? soundedDepth;
            var velocity        = panel.AverageVelocity.ToNullableDouble() ?? 0;
            var discharge       = panel.Discharge.ToNullableDouble() ?? 0;
            var width           = panel.Width.ToNullableDouble() ?? 0;
            var percentFlow     = panel.Flow.ToNullableDouble() ?? 0;

            var waterSurfaceToBottomOfIce   = panel.IceCovered?.WSToBottomOfIceAdjusted.ToNullableDouble() ?? 0;
            var waterSurfaceToBottomOfSlush = panel.IceCovered?.WaterSurfaceToBottomOfSlush.ToNullableDouble() ?? waterSurfaceToBottomOfIce;

            string comments        = null;
            var    distanceToMeter = panel.Open?.DistanceAboveWeight.ToNullableDouble();

            if (distanceToMeter > soundedDepth)
            {
                comments        = $"Original DistanceToMeter={distanceToMeter:F2} {Units.DistanceUnitId} updated to SoundedDepth={soundedDepth:F2} {Units.DistanceUnitId} by eHSN plugin.";
                distanceToMeter = soundedDepth;
            }

            var measurementCondition = panel.IceCovered != null
                ? (MeasurementConditionData) new IceCoveredData
            {
                IceAssemblyType             = panel.IceCovered.IceAssembly,
                IceThickness                = panel.IceCovered.IceThickness.ToNullableDouble(),
                AboveFooting                = panel.IceCovered.MeterAboveFooting.ToNullableDouble(),
                BelowFooting                = panel.IceCovered.MeterBelowFooting.ToNullableDouble(),
                WaterSurfaceToBottomOfIce   = waterSurfaceToBottomOfIce,
                WaterSurfaceToBottomOfSlush = waterSurfaceToBottomOfSlush,
            }
                : new OpenWaterData
            {
                DistanceToMeter   = distanceToMeter,
                DryLineAngle      = panel.DryAngle.ToNullableDouble() ?? 0,
                DryLineCorrection = panel.DryCorrection.ToNullableDouble(),
                WetLineCorrection = panel.WetCorrection.ToNullableDouble(),
                SuspensionWeight  = panel.Open?.AmountOfWeight
            };

            effectiveDepth = panel.IceCovered?.EffectiveDepth.ToNullableDouble() ?? effectiveDepth;

            var points = panel.PointMeasurements ?? new PointMeasurement[0];

            var fractionalDepths = string.Join("/", points.Select(p => p.SamplingDepthCoefficient));

            if (!PointVelocityTypes.TryGetValue(fractionalDepths, out var pointVelocityObservationType))
            {
                if (!points.Any())
                {
                    pointVelocityObservationType = PointVelocityObservationType.Surface;
                    soundedDepth = effectiveDepth = 0;
                }
                else
                {
                    throw new ArgumentException($"'{fractionalDepths}' is not a supported point velocity observation type");
                }
            }

            var velocityObservation = new VelocityObservation
            {
                VelocityObservationMethod = pointVelocityObservationType,
                MeanVelocity     = velocity,
                DeploymentMethod = GetPanelDeploymentMethod(panel),
                MeterCalibration = meter
            };

            if (!points.Any())
            {
                velocityObservation.Observations.Add(new VelocityDepthObservation
                {
                    Depth               = 0,
                    Velocity            = 0,
                    ObservationInterval = 0,
                    RevolutionCount     = 0
                });
            }
            else
            {
                foreach (var point in points)
                {
                    velocityObservation.Observations.Add(new VelocityDepthObservation
                    {
                        Depth               = point.MeasurementDepth.ToNullableDouble() ?? 0,
                        Velocity            = point.Velocity.ToNullableDouble() ?? 0,
                        ObservationInterval = point.ElapsedTime.ToNullableDouble(),
                        RevolutionCount     = point.Revolutions
                    });
                }
            }

            var vertical = new Vertical
            {
                VerticalType             = VerticalType.MidRiver,
                Comments                 = comments,
                MeasurementTime          = TimeHelper.CoerceDateTimeIntoUtcOffset(panel.Date, LocationInfo.UtcOffset),
                SequenceNumber           = panel.panelId,
                TaglinePosition          = taglinePosition,
                SoundedDepth             = soundedDepth,
                EffectiveDepth           = effectiveDepth,
                MeasurementConditionData = measurementCondition,
                FlowDirection            = panel.ReverseFlow.ToBoolean()
                    ? FlowDirectionType.Reversed
                    : FlowDirectionType.Normal,
                VelocityObservation = velocityObservation,
                Segment             = new Segment
                {
                    Area                  = soundedDepth * width, // We need to infer the area
                    Discharge             = discharge,
                    Width                 = width,
                    Velocity              = velocity,
                    TotalDischargePortion = percentFlow,
                }
            };

            return(vertical);
        }
        private void SetMappedVerticals(ManualGaugingDischargeSection manualGaugingDischarge, MeterCalibration meterCalibration,
                                        XmlRootSummaryStation[] stations)
        {
            var verticals = new VerticalMapper(GetMeasurementPeriod(), meterCalibration).MapAll(stations);

            foreach (var vertical in verticals)
            {
                manualGaugingDischarge.Verticals.Add(vertical);
            }
        }