test_helpers

Test the apexpy.helper submodule

Notes

Whenever function outputs are tested against hard-coded numbers, the test results (numbers) were obtained by running the code that is tested. Therefore, these tests below only check that nothing changes when refactoring, etc., and not if the results are actually correct.

These results are expected to change when IGRF is updated.

Classes

TestHelpers

Test class for the helper sub-module.

Functions

datetime64_to_datetime(dt64)

Convert numpy datetime64 object to a datetime datetime object.

Module Contents

test_helpers.datetime64_to_datetime(dt64)[source]

Convert numpy datetime64 object to a datetime datetime object.

Parameters:

dt64 (np.datetime64) – Numpy datetime64 object

Returns:

dt.datetime – Equivalent datetime object with a resolution of days

Notes

Works outside 32 bit int second range of 1970

class test_helpers.TestHelpers[source]

Bases: object

Test class for the helper sub-module.

setup_method()[source]

Set up a clean test environment.

teardown_method()[source]

Clean up the test environment.

eval_output(rtol=1e-07, atol=0.0)[source]

Evaluate the values and shape of the calculated and expected output.

test_checklat_scalar(lat)[source]

Test good latitude check with scalars.

Parameters:

lat (int or float) – Latitude in degrees N

test_checklat_scalar_clip(lat)[source]

Test good latitude check with scalars just beyond the lat limits.

Parameters:

lat (int or float) – Latitude in degrees N

test_checklat_error(in_args, msg)[source]

Test bad latitude raises ValueError with appropriate message.

Parameters:
  • in_args (list) – List of input arguments

  • msg (str) – Expected error message

test_checklat_array(lat, test_lat)[source]

Test good latitude with finite values.

Parameters:
  • lat (array-like) – Latitudes in degrees N

  • test_lat (list-like) – Output latitudes in degrees N

test_getsinIm(lat, test_sin)[source]

Test sin(Im) calculation for scalar and array inputs.

Parameters:
  • lat (float) – Latitude in degrees N

  • test_sin (float) – Output value

test_getcosIm(lat, test_cos)[source]

Test cos(Im) calculation for scalar and array inputs.

Parameters:
  • lat (float) – Latitude in degrees N

  • test_cos (float) – Expected output

test_toYearFraction(in_time, year)[source]

Test the datetime to fractional year calculation.

Parameters:
  • in_time (dt.datetime or dt.date) – Input time in a datetime format

  • year (int or float) – Output year with fractional values

test_gc2gdlat(gc_lat, gd_lat)[source]

Test geocentric to geodetic calculation.

Parameters:
  • gc_lat (int or float) – Geocentric latitude in degrees N

  • gd_lat (int or float) – Geodetic latitude in degrees N

test_subsol(in_time, test_loc)[source]

Test the subsolar location calculation.

Parameters:
  • in_time (dt.datetime) – Input time

  • test_loc (tuple) – Expected output

test_bad_subsol_date(in_time)[source]

Test raises ValueError for bad time in subsolar calculation.

Parameters:

in_time (dt.datetime) – Input time

test_bad_subsol_input(in_time)[source]

Test raises ValueError for bad input type in subsolar calculation.

Parameters:

in_time (NoneType or float) – Badly formatted input time

test_subsol_datetime64_array(in_dates)[source]

Verify subsolar point calculation using an array of np.datetime64.

Parameters:

in_time (array-like) – Array of input times

Notes

Tested by ensuring the array of np.datetime64 is equivalent to converting using single dt.datetime values