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¶
Test class for the Apex class object. |
|
Test the Apex methods. |
|
Test the Apex Magnetic Local Time (MLT) methods. |
|
Test the Apex height mapping methods. |
|
Test the Apex height base vector methods. |
|
Test the Apex get methods. |
|
Test the Apex methods on a year when IGRF must be extrapolated. |
Functions¶
|
A fixture for handling the coefficient 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.
- 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
- class test_Apex.TestApexMethod[source]¶
Bases:
object
Test the Apex methods.
- 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_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.
- class test_Apex.TestApexMLTMethods[source]¶
Bases:
object
Test the Apex Magnetic Local Time (MLT) methods.
- 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
- class test_Apex.TestApexMapMethods[source]¶
Bases:
object
Test the Apex height mapping methods.
- 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_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
- class test_Apex.TestApexBasevectorMethods[source]¶
Bases:
object
Test the Apex height base vector methods.
- 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
- class test_Apex.TestApexGetMethods[source]¶
Bases:
object
Test the Apex get methods.
- 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
- 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.