test_Apex

Test the apexpy.Apex class

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.

Module Contents

Classes

TestApexInit

Test class for the Apex class object.

TestApexMethod

Test the Apex methods.

TestApexMLTMethods

Test the Apex Magnetic Local Time (MLT) methods.

TestApexMapMethods

Test the Apex height mapping methods.

TestApexBasevectorMethods

Test the Apex height base vector methods.

TestApexGetMethods

Test the Apex get methods.

TestApexMethodExtrapolateIGRF

Test the Apex methods on a year when IGRF must be extrapolated.

Functions

igrf_file([max_attempts])

A fixture for handling the coefficient file.

test_set_epoch_file_error(igrf_file)

Test raises OSError when IGRF coefficient file is missing.

test_Apex.igrf_file(max_attempts=100)[source]

A fixture for handling the coefficient file.

Parameters

max_attempts (int) – Maximum rename attemps, needed for Windows (default=100)

test_Apex.test_set_epoch_file_error(igrf_file)[source]

Test raises OSError when IGRF coefficient file is missing.

class test_Apex.TestApexInit[source]

Bases: object

Test class for the Apex class object.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

eval_date()[source]

Evaluate the times in self.test_date and self.apex_out.

eval_refh()[source]

Evaluate the reference height in self.refh and self.apex_out.

test_init_defaults()[source]

Test Apex class default initialization.

test_init_today()[source]

Test Apex class initialization with today’s date.

test_init_date(in_date)[source]

Test Apex class with date initialization.

Parameters

in_date (int, float, dt.date, or dt.datetime) – Input date in a variety of formats

test_set_epoch(new_date)[source]

Test successful setting of Apex epoch after initialization.

Parameters

new_date (int or float) – New date for the Apex class

test_init_refh(in_refh)[source]

Test Apex class with reference height initialization.

Parameters

in_refh (float) – Input reference height in km

test_set_refh(new_refh)[source]

Test the method used to set the reference height after the init.

Parameters

new_refh (float) – Reference height in km

test_init_with_bad_datafile()[source]

Test raises IOError with non-existent datafile input.

test_init_with_bad_fortranlib()[source]

Test raises IOError with non-existent datafile input.

test_repr_eval()[source]

Test the Apex.__repr__ results.

test_ne_other_class()[source]

Test Apex class inequality to a different class.

test_ne_missing_attr()[source]

Test Apex class inequality when attributes are missing from one.

test_eq_missing_attr()[source]

Test Apex class equality when attributes are missing from both.

test_str_eval()[source]

Test the Apex.__str__ results.

class test_Apex.TestApexMethod[source]

Bases: object

Test the Apex methods.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

get_input_args(method_name, precision=0.0)[source]

Set the input arguments for the different Apex methods.

Parameters
  • method_name (str) – Name of the Apex class method

  • precision (float) – Value for the precision (default=0.0)

Returns

in_args (list) – List of the appropriate input arguments

test_apex_conversion_today()[source]

Test Apex class conversion with today’s date.

test_fortran_scalar_input(apex_method, fortran_method, fslice, lat, lon)[source]

Tests Apex/fortran interface consistency for scalars.

Parameters
  • apex_method (str) – Name of the Apex class method to test

  • fortran_method (str) – Name of the Fortran function to test

  • fslice (slice) – Slice used select the appropriate Fortran outputs

  • lat (int or float) – Latitude in degrees N

  • lon (int or float) – Longitude in degrees E

test_fortran_longitude_rollover(apex_method, fortran_method, fslice, lat, lon1, lon2)[source]

Tests Apex/fortran interface consistency for longitude rollover.

Parameters
  • apex_method (str) – Name of the Apex class method to test

  • fortran_method (str) – Name of the Fortran function to test

  • fslice (slice) – Slice used select the appropriate Fortran outputs

  • lat (int or float) – Latitude in degrees N

  • lon1 (int or float) – Longitude in degrees E

  • lon2 (int or float) – Equivalent longitude in degrees E

test_fortran_array_input(arr_shape, apex_method, fortran_method, fslice)[source]

Tests Apex/fortran interface consistency for array input.

Parameters
  • arr_shape (tuple) – Expected output shape

  • apex_method (str) – Name of the Apex class method to test

  • fortran_method (str) – Name of the Fortran function to test

  • fslice (slice) – Slice used select the appropriate Fortran outputs

test_geo2apexall_scalar(lat, lon)[source]

Test Apex/fortran geo2apexall interface consistency for scalars.

Parameters
  • lat (int or float) – Latitude in degrees N

  • long (int or float) – Longitude in degrees E

test_geo2apexall_array(arr_shape)[source]

Test Apex/fortran geo2apexall interface consistency for arrays.

Parameters

arr_shape (tuple) – Expected output shape

test_convert_consistency(in_coord, out_coord)[source]

Test the self-consistency of the Apex convert method.

Parameters
  • in_coord (str) – Input coordinate system

  • out_coord (str) – Output coordinate system

test_convert_at_lat_boundary(bound_lat, in_coord, out_coord)[source]

Test the conversion at the latitude boundary, with allowed excess.

Parameters
  • bound_lat (int or float) – Boundary latitude in degrees N

  • in_coord (str) – Input coordinate system

  • out_coord (str) – Output coordinate system

test_convert_qd2apex_at_equator()[source]

Test the quasi-dipole to apex conversion at the magnetic equator.

test_convert_withnan(src, dest)[source]

Test Apex.convert success with NaN input.

Parameters
  • src (str) – Input coordinate system

  • dest (str) – Output coordinate system

test_convert_invalid_lat(bad_lat)[source]

Test convert raises ValueError for invalid latitudes.

Parameters

bad_lat (int or float) – Latitude ouside the supported range in degrees N

test_convert_invalid_transformation(coords)[source]

Test raises NotImplementedError for bad coordinates.

Parameters

coords (tuple) – Tuple specifying the input and output coordinate systems

test_method_scalar_input(method_name, out_comp)[source]

Test the user method against set values with scalars.

Parameters
  • method_name (str) – Apex class method to be tested

  • out_comp (tuple of floats) – Expected output values

test_method_broadcast_input(in_coord, out_coord, method_args, out_shape)[source]

Test the user method with inputs that require some broadcasting.

Parameters
  • in_coord (str) – Input coordiante system

  • out_coord (str) – Output coordiante system

  • method_args (list) – List of input arguments

  • out_shape (tuple) – Expected shape of output values

test_method_invalid_lat(in_coord, out_coord, bad_lat)[source]

Test convert raises ValueError for invalid latitudes.

Parameters
  • in_coord (str) – Input coordiante system

  • out_coord (str) – Output coordiante system

  • bad_lat (int) – Latitude in degrees N that is out of bounds

test_method_at_lat_boundary(in_coord, out_coord, bound_lat)[source]

Test user methods at the latitude boundary, with allowed excess.

Parameters
  • in_coord (str) – Input coordiante system

  • out_coord (str) – Output coordiante system

  • bad_lat (int) – Latitude in degrees N that is at the limits of the boundary

test_geo2apex_undefined_warning()[source]

Test geo2apex warning and fill values for an undefined location.

test_quasidipole_apexheight_close(method_name, delta_h)[source]

Test quasi-dipole success with a height close to the reference.

Parameters
  • method_name (str) – Apex class method name to be tested

  • delta_h (float) – tolerance for height in km

test_quasidipole_raises_apexheight(method_name, hinc, msg)[source]

Quasi-dipole raises ApexHeightError when height above reference.

Parameters
  • method_name (str) – Apex class method name to be tested

  • hinc (float) – Height increment in km

  • msg (str) – Expected output message

class test_Apex.TestApexMLTMethods[source]

Bases: object

Test the Apex Magnetic Local Time (MLT) methods.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

test_convert_to_mlt(in_coord)[source]

Test the conversions to MLT using Apex convert.

Parameters

in_coord (str) – Input coordinate system

test_convert_mlt_to_lon(out_coord)[source]

Test the conversions from MLT using Apex convert.

Parameters

out_coord (str) – Output coordinate system

test_convert_geo2mlt_nodate()[source]

Test convert from geo to MLT raises ValueError with no datetime.

test_mlon2mlt_scalar_inputs(mlon_kwargs, test_mlt)[source]

Test mlon2mlt with scalar inputs.

Parameters
  • mlon_kwargs (dict) – Input kwargs

  • test_mlt (float) – Output MLT in hours

test_mlt2mlon_scalar_inputs(mlt_kwargs, test_mlon)[source]

Test mlt2mlon with scalar inputs.

Parameters
  • mlt_kwargs (dict) – Input kwargs

  • test_mlon (float) – Output longitude in degrees E

test_mlon2mlt_array(mlon, test_mlt)[source]

Test mlon2mlt with array inputs.

Parameters
  • mlon (array-like) – Input longitudes in degrees E

  • test_mlt (float) – Output MLT in hours

test_mlt2mlon_array(mlt, test_mlon)[source]

Test mlt2mlon with array inputs.

Parameters
  • mlt (array-like) – Input MLT in hours

  • test_mlon (float) – Output longitude in degrees E

test_mlon2mlt_diffdates(method_name)[source]

Test that MLT varies with universal time.

Parameters

method_name (str) – Name of Apex class method to be tested

test_mlon2mlt_offset(mlt_offset)[source]

Test the time wrapping logic for the MLT.

Parameters

mlt_offset (float) – MLT offset in hours

test_mlt2mlon_offset(mlon_offset)[source]

Test the time wrapping logic for the magnetic longitude.

Parameters

mlt_offset (float) – MLT offset in hours

test_convert_and_return(order, start_val)[source]

Test the conversion to magnetic longitude or MLT and back again.

Parameters
  • order (list) – List of strings specifying the order to run functions

  • start_val (int or float) – Input value

class test_Apex.TestApexMapMethods[source]

Bases: object

Test the Apex height mapping methods.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

test_map_to_height(in_args, test_mapped)[source]

Test the map_to_height function.

Parameters
  • in_args (list) – List of input arguments

  • test_mapped (list) – List of expected outputs

test_map_to_height_same_height()[source]

Test the map_to_height function when mapping to same height.

test_map_to_height_array_location(arr_shape, ivec)[source]

Test map_to_height with array input.

Parameters
  • arr_shape (tuple) – Expected array shape

  • ivec (int) – Input argument index for vectorized input

test_mapping_height_raises_ApexHeightError(method_name, in_args)[source]

Test map_to_height raises ApexHeightError.

Parameters
  • method_name (str) – Name of the Apex class method to test

  • in_args (list) – List of input arguments

test_mapping_EV_bad_shape(method_name, ev_input)[source]

Test height mapping of E/V with baddly shaped input raises Error.

Parameters
  • method_name (str) – Name of the Apex class method to test

  • ev_input (list) – E/V input arguments

test_mapping_EV_bad_flag()[source]

Test _map_EV_to_height raises error for bad data type flag.

test_map_E_to_height_scalar_location(in_args, test_mapped)[source]

Test mapping of E-field to a specified height.

Parameters
  • in_args (list) – List of input arguments

  • test_mapped (list) – List of expected outputs

test_map_EV_to_height_array_location(ev_flag, test_mapped, arr_shape, ivec)[source]

Test mapping of E-field/drift to a specified height with arrays.

Parameters
  • ev_flag (str) – Character flag specifying whether to run ‘E’ or ‘V’ methods

  • test_mapped (list) – List of expected outputs

  • arr_shape (tuple) – Shape of the expected output

  • ivec (int) – Index of the expected output

test_map_V_to_height_scalar_location(in_args, test_mapped)[source]

Test mapping of velocity to a specified height.

Parameters
  • in_args (list) – List of input arguments

  • test_mapped (list) – List of expected outputs

class test_Apex.TestApexBasevectorMethods[source]

Bases: object

Test the Apex height base vector methods.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

get_comparison_results(bv_coord, coords, precision)[source]

Get the base vector results using the hidden function for comparison.

Parameters
  • bv_coord (str) – Basevector coordinate scheme, expects on of ‘apex’, ‘qd’, or ‘bvectors_apex’

  • coords (str) – Expects one of ‘geo’, ‘apex’, or ‘qd’

  • precision (float) – Float specifiying precision

test_basevectors_scalar(bv_coord, coords, precision)[source]

Test the base vector calculations with scalars.

Parameters
  • bv_coord (str) – Name of the input coordinate system

  • coords (str) – Name of the output coordinate system

  • precision (float) – Level of run precision requested

test_basevectors_scalar_shape(bv_coord)[source]

Test the shape of the scalar output.

Parameters

bv_coord (str) – Name of the input coordinate system

test_basevectors_array(arr_shape, bv_coord, ivec)[source]

Test the output shape for array inputs.

Parameters
  • arr_shape (tuple) – Expected output shape

  • bv_coord (str) – Name of the input coordinate system

  • ivec (int) – Index of the evaluated output value

test_bvectors_apex(coords)[source]

Test the bvectors_apex method.

Parameters

coords (str) – Name of the coordiante system

test_basevectors_apex_extra_values()[source]

Test specific values in the apex base vector output.

test_basevectors_apex_delta(lat, lon)[source]

Test that vectors are calculated correctly.

Parameters
  • lat (int or float) – Latitude in degrees N

  • lon (int or float) – Longitude in degrees E

test_basevectors_apex_invalid_scalar()[source]

Test warning and fill values for base vectors with bad inputs.

class test_Apex.TestApexGetMethods[source]

Bases: object

Test the Apex get methods.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

test_get_apex(alat, aheight)[source]

Test the apex height retrieval results.

Parameters
  • alat (int or float) – Apex latitude in degrees N

  • aheight (int or float) – Apex height in km

test_get_babs(glat, glon, height, test_bmag)[source]

Test the method to get the magnitude of the magnetic field.

Parameters
  • glat (list) – List of latitudes in degrees N

  • glon (list) – List of longitudes in degrees E

  • height (list) – List of heights in km

  • test_bmag (float) – Expected B field magnitude

test_get_apex_with_invalid_lat(bad_lat)[source]

Test get methods raise ValueError for invalid latitudes.

Parameters

bad_lat (int or float) – Bad input latitude in degrees N

test_get_babs_with_invalid_lat(bad_lat)[source]

Test get methods raise ValueError for invalid latitudes.

Parameters

bad_lat (int or float) – Bad input latitude in degrees N

test_get_at_lat_boundary(bound_lat)[source]

Test get methods at the latitude boundary, with allowed excess.

Parameters

bound_lat (int or float) – Boundary input latitude in degrees N

test_get_height_at_equator(apex_height)[source]

Test that get_height returns apex height at equator.

Parameters

apex_height (float) – Apex height

test_get_height_along_fieldline(lat, height)[source]

Test that get_height returns expected height of field line.

Parameters
  • lat (float) – Input latitude

  • height (float) – Output field-line height for line with apex of 3000 km

class test_Apex.TestApexMethodExtrapolateIGRF[source]

Bases: object

Test the Apex methods on a year when IGRF must be extrapolated.

Notes

Extrapolation should be done using a year within 5 years of the latest IGRF model epoch.

setup_method()[source]

Initialize all tests.

teardown_method()[source]

Clean up after each test.

test_method_scalar_input(method_name, out_comp)[source]

Test the user method against set values with scalars.

Parameters
  • method_name (str) – Apex class method to be tested

  • out_comp (tuple of floats) – Expected output values

test_convert_to_mlt()[source]

Test conversion from mlon to mlt with scalars.