class TestSparseSHCoefficientsTimeDependentDecimalYearDefault(
        TestCase, SHCoefficinetTestMixIn):
    times = array([2012.0, 2016.0, 2014.0])
    indices = array([(1, 0), (1, 1), (1, -1)])
    coeff = array([
        [1, 3, 2],
        [5, 15, 10],
        [10, 30, 20],
    ])
    degree = 1
    is_internal = True
    validity = tuple(decimal_year_to_mjd2000((2012.0, 2016.0)))
    options = {}

    @property
    def coefficients(self):
        return SparseSHCoefficientsTimeDependentDecimalYear(
            self.indices, self.coeff, self.times, **self.options)

    def test_callable(self):
        coeff, degree = self.coefficients(decimal_year_to_mjd2000(2013.0))
        assert_allclose(coeff, [[0., 0.], [1.5, 0], [7.5, 15.0]])
        self.assertEqual(degree, self.degree)

    def test_callable_before_first_time(self):
        coeff, degree = self.coefficients(decimal_year_to_mjd2000(2011.0))
        assert_allclose(coeff, [[0., 0.], [0.5, 0], [2.5, 5.0]])
        self.assertEqual(degree, self.degree)
Exemple #2
0
def eval_model(time=dt.datetime(2020, 1, 1),
               coords=grid(),
               shc_model=eoxmagmod.data.IGRF13):
    """Evaluate a .shc model at a fixed time

    Args:
        time (datetime)
        coords (ndarray)
        shc_model (str): path to file

    Returns:
        dict: magnetic field vector components:
            https://intermagnet.github.io/faq/10.geomagnetic-comp.html
    """
    # Convert Python datetime to MJD2000
    epoch = eoxmagmod.util.datetime_to_decimal_year(time)
    mjd2000 = eoxmagmod.decimal_year_to_mjd2000(epoch)
    # Load model
    model = eoxmagmod.load_model_shc(shc_model)
    # Evaluate in North, East, Up coordinates
    height = eoxmagmod.GEODETIC_ABOVE_WGS84
    b_neu = model.eval(mjd2000, coords, height, height)
    # Inclination (I), declination (D), intensity (F)
    inc, dec, F = eoxmagmod.vincdecnorm(b_neu)
    return {
        "X": b_neu[:, :, 0],
        "Y": b_neu[:, :, 1],
        "Z": -b_neu[:, :, 2],
        "I": inc,
        "D": dec,
        "F": F
    }
class TestSparseSHCoefficientsTimeDependentDecimalYearExtendedValidity(
        TestSparseSHCoefficientsTimeDependentDecimalYearDefault):
    validity = tuple(decimal_year_to_mjd2000((2010.0, 2018.0)))
    options = {"validity_start": 2010.0, "validity_end": 2018.0}
 def test_callable_before_first_time(self):
     coeff, degree = self.coefficients(decimal_year_to_mjd2000(2011.0))
     assert_allclose(coeff, [[0., 0.], [0.5, 0], [2.5, 5.0]])
     self.assertEqual(degree, self.degree)
 def test_callable(self):
     coeff, degree = self.coefficients(decimal_year_to_mjd2000(2013.0))
     assert_allclose(coeff, [[0., 0.], [1.5, 0], [7.5, 15.0]])
     self.assertEqual(degree, self.degree)
Exemple #6
0
class TestFieldLineTracing(TestCase):
    time = decimal_year_to_mjd2000(2015.5)
    point = START_POINT
    points = FIELD_LINE_POINTS

    @property
    def model(self):
        if not hasattr(self, "_model"):
            self._model = load_model_shc(IGRF12,
                                         interpolate_in_decimal_years=True)
        return self._model

    def test_trace_field_line_wgs84(self):
        point = self.point
        points, vectors = trace_field_line(
            self.model,
            self.time,
            point,
            input_coordinate_system=GEODETIC_ABOVE_WGS84,
            output_coordinate_system=GEODETIC_ABOVE_WGS84,
        )
        assert_allclose(points, self.points)
        assert_allclose(
            vectors,
            self.model.eval(
                self.time,
                points,
                input_coordinate_system=GEODETIC_ABOVE_WGS84,
                output_coordinate_system=GEODETIC_ABOVE_WGS84,
            ))

    def test_trace_field_line_spherical(self):
        point = convert(self.point, GEODETIC_ABOVE_WGS84, GEOCENTRIC_SPHERICAL)
        points, vectors = trace_field_line(
            self.model,
            self.time,
            point,
            input_coordinate_system=GEOCENTRIC_SPHERICAL,
            output_coordinate_system=GEOCENTRIC_SPHERICAL,
        )
        assert_allclose(
            points,
            convert(self.points, GEODETIC_ABOVE_WGS84, GEOCENTRIC_SPHERICAL))
        assert_allclose(
            vectors,
            self.model.eval(
                self.time,
                points,
                input_coordinate_system=GEOCENTRIC_SPHERICAL,
                output_coordinate_system=GEOCENTRIC_SPHERICAL,
            ))

    def test_trace_field_line_cartesian(self):
        point = convert(self.point, GEODETIC_ABOVE_WGS84, GEOCENTRIC_CARTESIAN)
        points, vectors = trace_field_line(
            self.model,
            self.time,
            point,
            input_coordinate_system=GEOCENTRIC_CARTESIAN,
            output_coordinate_system=GEOCENTRIC_CARTESIAN,
        )
        assert_allclose(
            points,
            convert(self.points, GEODETIC_ABOVE_WGS84, GEOCENTRIC_CARTESIAN))
        assert_allclose(
            vectors,
            self.model.eval(
                self.time,
                points,
                input_coordinate_system=GEOCENTRIC_CARTESIAN,
                output_coordinate_system=GEOCENTRIC_CARTESIAN,
            ))