BistaticRangeRate.java

/* Copyright 2002-2026 CS GROUP
 * Licensed to CS GROUP (CS) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * CS licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.orekit.estimation.measurements;

import java.util.Map;

import org.hipparchus.analysis.differentiation.Gradient;
import org.hipparchus.analysis.differentiation.GradientField;
import org.orekit.estimation.measurements.model.TwoLegsRangeRateModel;
import org.orekit.estimation.measurements.signal.SignalTravelTimeModel;
import org.orekit.frames.Frame;
import org.orekit.propagation.SpacecraftState;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.FieldAbsoluteDate;
import org.orekit.utils.FieldPVCoordinatesProvider;
import org.orekit.utils.PVCoordinatesProvider;
import org.orekit.utils.TimeStampedFieldPVCoordinates;
import org.orekit.utils.TimeStampedPVCoordinates;

/** Class modeling a bistatic range rate measurement using
 *  an emitter ground station and a receiver ground station.
 * <p>
 * The measurement is considered to be a signal:
 * <ul>
 * <li>Emitted from the emitter ground station</li>
 * <li>Reflected on the spacecraft</li>
 * <li>Received on the receiver ground station</li>
 * </ul>
 * The date of the measurement corresponds to the reception on ground of the reflected signal.
 * The quantity measured at the receiver is the bistatic radial velocity as the sum of the radial
 * velocities with respect to the two stations.
 * <p>
 * The motion of the stations and the spacecraft during the signal flight time are taken into account.
 * </p><p>
 * The Doppler measurement can be obtained by multiplying the velocity by (fe/c), where
 * fe is the emission frequency.
 * </p>
 *
 * @author Pascal Parraud
 * @since 11.2
 */
public class BistaticRangeRate extends BistaticRangeRelatedMeasurement<BistaticRangeRate> {

    /** Type of the measurement. */
    public static final String MEASUREMENT_TYPE = "BistaticRangeRate";

    /** Range-rate measurement model. */
    private final TwoLegsRangeRateModel twoLegsRangeRateModel;

    /** Simple constructor.
     * @param emitter emitter ground station
     * @param receiver receiver ground station
     * @param date date of the measurement
     * @param rangeRate observed value, m/s
     * @param sigma theoretical standard deviation
     * @param baseWeight base weight
     * @param satellite satellite related to this measurement
     */
    public BistaticRangeRate(final GroundStation emitter, final GroundStation receiver, final AbsoluteDate date,
                             final double rangeRate, final double sigma, final double baseWeight,
                             final ObservableSatellite satellite) {
        this(emitter, receiver, date, rangeRate, sigma, baseWeight, new SignalTravelTimeModel(), satellite);
    }

    /** Simple constructor.
     * @param emitter emitter ground station
     * @param receiver receiver ground station
     * @param date date of the measurement
     * @param rangeRate observed value, m/s
     * @param sigma theoretical standard deviation
     * @param baseWeight base weight
     * @param signalTravelTimeModel signal travel time model
     * @param satellite satellite related to this measurement
     */
    public BistaticRangeRate(final GroundStation emitter, final GroundStation receiver, final AbsoluteDate date,
                             final double rangeRate, final double sigma, final double baseWeight,
                             final SignalTravelTimeModel signalTravelTimeModel, final ObservableSatellite satellite) {
        super(emitter, receiver, true, date, new double[] {rangeRate}, new double[] {sigma}, new double[] {baseWeight},
                signalTravelTimeModel, satellite);

        // Add class member values
        this.twoLegsRangeRateModel = new TwoLegsRangeRateModel(getTwoLegsSignalTimer());
    }

    /** {@inheritDoc} */
    @Override
    protected EstimatedMeasurementBase<BistaticRangeRate> theoreticalEvaluationWithoutDerivatives(final int iteration,
                                                                                                  final int evaluation,
                                                                                                  final SpacecraftState[] states) {
        // Compute participants (position-velocities at signal transmissions)
        final SpacecraftState state = states[0];
        final Frame frame = state.getFrame();
        final TimeStampedPVCoordinates[] participants = getParticipants(state);

        // Extract dates
        final AbsoluteDate emissionDate = participants[0].getDate();
        final AbsoluteDate transitDate = participants[1].getDate();
        final AbsoluteDate receptionDate = participants[2].getDate();

        // Prepare the evaluation
        final double shift = transitDate.durationFrom(state);
        final SpacecraftState transitState = state.shiftedBy(shift);
        final EstimatedMeasurementBase<BistaticRangeRate> estimated = new EstimatedMeasurementBase<>(this, iteration, evaluation,
                new SpacecraftState[] { transitState }, participants);

        // Compute range rate
        final PVCoordinatesProvider observablePVCoordinates = AbstractMeasurementObject.extractPVCoordinatesProvider(state,
                state.getPVCoordinates());
        final double rangeRate = twoLegsRangeRateModel.value(frame, participants[2], receptionDate,
                observablePVCoordinates, transitDate, getEmitterStation().getPVCoordinatesProvider(), emissionDate);

        estimated.setEstimatedValue(rangeRate);
        return estimated;
    }

    /** {@inheritDoc} */
    @Override
    protected EstimatedMeasurement<BistaticRangeRate> theoreticalEvaluation(final int iteration,
                                                                            final int evaluation,
                                                                            final SpacecraftState[] states) {
        // Bistatic range-rate derivatives are computed with respect to spacecraft state in inertial frame
        // and station parameters
        // ----------------------
        //
        // Parameters:
        //  - 0..2 - Position of the spacecraft in inertial frame
        //  - 3..5 - Velocity of the spacecraft in inertial frame
        //  - 6..n - measurements parameters (clock offset, station offsets, pole, prime meridian, sat clock offset...)
        // Compute time shifts w.r.t. recorded observation date
        final Gradient[] shifts = getFieldShifts(states);
        final GradientField field = shifts[0].getField();
        final FieldAbsoluteDate<Gradient> receptionDate = new FieldAbsoluteDate<>(field, getDate()).shiftedBy(shifts[0]);
        final FieldAbsoluteDate<Gradient> transitDate = receptionDate.shiftedBy(shifts[1]);
        final FieldAbsoluteDate<Gradient> emissionDate = transitDate.shiftedBy(shifts[2]);

        // Prepare the evaluation
        final SpacecraftState state = states[0];
        final Frame frame = state.getFrame();
        final double shift = transitDate.toAbsoluteDate().durationFrom(state);
        final SpacecraftState transitState = state.shiftedBy(shift);
        final int nbParams = field.getZero().getFreeParameters();
        final Map<String, Integer> paramIndices = getParameterIndices(states);
        final FieldPVCoordinatesProvider<Gradient> receiver = getReceiverStation().getFieldPVCoordinatesProvider(nbParams,
                paramIndices);
        final TimeStampedFieldPVCoordinates<Gradient> receiverPV = receiver.getPVCoordinates(receptionDate, frame);
        final EstimatedMeasurement<BistaticRangeRate> estimated = new EstimatedMeasurement<>(this, iteration, evaluation,
                new SpacecraftState[] { transitState },
                new TimeStampedPVCoordinates[] {
                        getEmitterStation().getPVCoordinatesProvider().getPVCoordinates(emissionDate.toAbsoluteDate(), frame),
                        transitState.getPVCoordinates(),
                        receiverPV.toTimeStampedPVCoordinates()});

        // Compute range rate
        final FieldPVCoordinatesProvider<Gradient> emitter = getEmitterStation().getFieldPVCoordinatesProvider(nbParams,
                paramIndices);
        final FieldPVCoordinatesProvider<Gradient> observable = AbstractMeasurementObject.extractFieldPVCoordinatesProvider(state,
                AbstractMeasurement.getCoordinates(state, 0, nbParams));
        final Gradient rangeRate = twoLegsRangeRateModel.value(frame, receiverPV, receptionDate, observable,
                transitDate, emitter, emissionDate);

        fillEstimation(rangeRate, getParameterIndices(states), estimated);
        return estimated;
    }

}