test_Apex ========= .. py:module:: test_Apex .. autoapi-nested-parse:: Test the apexpy.Apex class .. rubric:: 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 ------- .. autoapisummary:: test_Apex.TestApexInit test_Apex.TestApexMethod test_Apex.TestApexMLTMethods test_Apex.TestApexMapMethods test_Apex.TestApexBasevectorMethods test_Apex.TestApexGetMethods test_Apex.TestApexMethodExtrapolateIGRF Module Contents --------------- .. py:class:: TestApexInit Bases: :py:obj:`object` Test class for the Apex class object. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: eval_date() Evaluate the times in self.test_date and self.apex_out. .. py:method:: eval_refh() Evaluate the reference height in self.refh and self.apex_out. .. py:method:: test_init_defaults() Test Apex class default initialization. .. py:method:: test_init_today() Test Apex class initialization with today's date. .. py:method:: test_init_date(in_date) Test Apex class with date initialization. :Parameters: **in_date** (*int, float, dt.date, or dt.datetime*) -- Input date in a variety of formats .. py:method:: test_set_epoch(new_date) Test successful setting of Apex epoch after initialization. :Parameters: **new_date** (*int or float*) -- New date for the Apex class .. py:method:: test_init_refh(in_refh) Test Apex class with reference height initialization. :Parameters: **in_refh** (*float*) -- Input reference height in km .. py:method:: test_set_refh(new_refh) Test the method used to set the reference height after the init. :Parameters: **new_refh** (*float*) -- Reference height in km .. py:method:: copy_file(original, max_attempts=100) Make a temporary copy of input file. .. py:method:: test_default_datafile() Test that the class initializes with the default datafile. .. py:method:: test_custom_datafile() Test that the class initializes with a good datafile input. .. py:method:: test_init_with_bad_datafile() Test raises IOError with non-existent datafile input. .. py:method:: test_default_fortranlib() Test that the class initializes with the default fortranlib. .. py:method:: test_custom_fortranlib() Test that the class initializes with a good fortranlib input. .. py:method:: test_init_with_bad_fortranlib() Test raises IOError with non-existent fortranlib input. .. py:method:: test_igrf_fn() Test the default igrf_fn. .. py:method:: test_repr_eval() Test the Apex.__repr__ results. .. py:method:: test_ne_other_class() Test Apex class inequality to a different class. .. py:method:: test_ne_missing_attr() Test Apex class inequality when attributes are missing from one. .. py:method:: test_eq_missing_attr() Test Apex class equality when attributes are missing from both. .. py:method:: test_str_eval() Test the Apex.__str__ results. .. py:class:: TestApexMethod Bases: :py:obj:`object` Test the Apex methods. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: get_input_args(method_name, precision=0.0) 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 .. py:method:: test_apex_conversion_today() Test Apex class conversion with today's date. .. py:method:: test_fortran_scalar_input(apex_method, fortran_method, fslice, lat, lon) 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 .. py:method:: test_fortran_longitude_rollover(apex_method, fortran_method, fslice, lat, lon1, lon2) 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 .. py:method:: test_fortran_array_input(arr_shape, apex_method, fortran_method, fslice) 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 .. py:method:: test_geo2apexall_scalar(lat, lon) 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 .. py:method:: test_geo2apexall_array(arr_shape) Test Apex/fortran geo2apexall interface consistency for arrays. :Parameters: **arr_shape** (*tuple*) -- Expected output shape .. py:method:: test_convert_consistency(in_coord, out_coord) Test the self-consistency of the Apex convert method. :Parameters: * **in_coord** (*str*) -- Input coordinate system * **out_coord** (*str*) -- Output coordinate system .. py:method:: test_convert_at_lat_boundary(bound_lat, in_coord, out_coord) 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 .. py:method:: test_convert_qd2apex_at_equator() Test the quasi-dipole to apex conversion at the magnetic equator. .. py:method:: test_convert_withnan(src, dest) Test Apex.convert success with NaN input. :Parameters: * **src** (*str*) -- Input coordinate system * **dest** (*str*) -- Output coordinate system .. py:method:: test_convert_invalid_lat(bad_lat) Test convert raises ValueError for invalid latitudes. :Parameters: **bad_lat** (*int or float*) -- Latitude ouside the supported range in degrees N .. py:method:: test_convert_invalid_transformation(coords) Test raises NotImplementedError for bad coordinates. :Parameters: **coords** (*tuple*) -- Tuple specifying the input and output coordinate systems .. py:method:: test_method_scalar_input(method_name, out_comp) 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 .. py:method:: test_method_broadcast_input(in_coord, out_coord, method_args, out_shape) 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 .. py:method:: test_method_invalid_lat(in_coord, out_coord, bad_lat) 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 .. py:method:: test_method_at_lat_boundary(in_coord, out_coord, bound_lat) 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 .. py:method:: test_geo2apex_undefined_warning() Test geo2apex warning and fill values for an undefined location. .. py:method:: test_quasidipole_apexheight_close(method_name, delta_h) 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 .. py:method:: test_quasidipole_raises_apexheight(method_name, hinc, msg) 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 .. py:class:: TestApexMLTMethods Bases: :py:obj:`object` Test the Apex Magnetic Local Time (MLT) methods. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: test_convert_to_mlt(in_coord) Test the conversions to MLT using Apex convert. :Parameters: **in_coord** (*str*) -- Input coordinate system .. py:method:: test_convert_mlt_to_lon(out_coord) Test the conversions from MLT using Apex convert. :Parameters: **out_coord** (*str*) -- Output coordinate system .. py:method:: test_convert_geo2mlt_nodate() Test convert from geo to MLT raises ValueError with no datetime. .. py:method:: test_mlon2mlt_scalar_inputs(mlon_kwargs, test_mlt) Test mlon2mlt with scalar inputs. :Parameters: * **mlon_kwargs** (*dict*) -- Input kwargs * **test_mlt** (*float*) -- Output MLT in hours .. py:method:: test_mlt2mlon_scalar_inputs(mlt_kwargs, test_mlon) Test mlt2mlon with scalar inputs. :Parameters: * **mlt_kwargs** (*dict*) -- Input kwargs * **test_mlon** (*float*) -- Output longitude in degrees E .. py:method:: test_mlon2mlt_array(mlon, test_mlt) Test mlon2mlt with array inputs. :Parameters: * **mlon** (*array-like*) -- Input longitudes in degrees E * **test_mlt** (*float*) -- Output MLT in hours .. py:method:: test_mlt2mlon_array(mlt, test_mlon) Test mlt2mlon with array inputs. :Parameters: * **mlt** (*array-like*) -- Input MLT in hours * **test_mlon** (*float*) -- Output longitude in degrees E .. py:method:: test_mlon2mlt_diffdates(method_name) Test that MLT varies with universal time. :Parameters: **method_name** (*str*) -- Name of Apex class method to be tested .. py:method:: test_mlon2mlt_offset(mlt_offset) Test the time wrapping logic for the MLT. :Parameters: **mlt_offset** (*float*) -- MLT offset in hours .. py:method:: test_mlt2mlon_offset(mlon_offset) Test the time wrapping logic for the magnetic longitude. :Parameters: **mlt_offset** (*float*) -- MLT offset in hours .. py:method:: test_convert_and_return(order, start_val) 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 .. py:class:: TestApexMapMethods Bases: :py:obj:`object` Test the Apex height mapping methods. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: test_map_to_height(in_args, test_mapped) Test the map_to_height function. :Parameters: * **in_args** (*list*) -- List of input arguments * **test_mapped** (*list*) -- List of expected outputs .. py:method:: test_map_to_height_same_height() Test the map_to_height function when mapping to same height. .. py:method:: test_map_to_height_array_location(arr_shape, ivec) Test map_to_height with array input. :Parameters: * **arr_shape** (*tuple*) -- Expected array shape * **ivec** (*int*) -- Input argument index for vectorized input .. py:method:: test_mapping_height_raises_ApexHeightError(method_name, in_args) 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 .. py:method:: test_mapping_EV_bad_shape(method_name, ev_input) 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 .. py:method:: test_mapping_EV_bad_flag() Test _map_EV_to_height raises error for bad data type flag. .. py:method:: test_map_E_to_height_scalar_location(in_args, test_mapped) Test mapping of E-field to a specified height. :Parameters: * **in_args** (*list*) -- List of input arguments * **test_mapped** (*list*) -- List of expected outputs .. py:method:: test_map_EV_to_height_array_location(ev_flag, test_mapped, arr_shape, ivec) 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 .. py:method:: test_map_V_to_height_scalar_location(in_args, test_mapped) Test mapping of velocity to a specified height. :Parameters: * **in_args** (*list*) -- List of input arguments * **test_mapped** (*list*) -- List of expected outputs .. py:class:: TestApexBasevectorMethods Bases: :py:obj:`object` Test the Apex height base vector methods. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: get_comparison_results(bv_coord, coords, precision) 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 .. py:method:: test_basevectors_scalar(bv_coord, coords, precision) 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 .. py:method:: test_basevectors_scalar_shape(bv_coord) Test the shape of the scalar output. :Parameters: **bv_coord** (*str*) -- Name of the input coordinate system .. py:method:: test_basevectors_array(arr_shape, bv_coord, ivec) 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 .. py:method:: test_bvectors_apex(coords) Test the bvectors_apex method. :Parameters: **coords** (*str*) -- Name of the coordiante system .. py:method:: test_basevectors_apex_extra_values() Test specific values in the apex base vector output. .. py:method:: test_basevectors_apex_delta(lat, lon) Test that vectors are calculated correctly. :Parameters: * **lat** (*int or float*) -- Latitude in degrees N * **lon** (*int or float*) -- Longitude in degrees E .. py:method:: test_basevectors_apex_invalid_scalar() Test warning and fill values for base vectors with bad inputs. .. py:class:: TestApexGetMethods Bases: :py:obj:`object` Test the Apex `get` methods. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: test_get_apex(alat, aheight) Test the apex height retrieval results. :Parameters: * **alat** (*int or float*) -- Apex latitude in degrees N * **aheight** (*int or float*) -- Apex height in km .. py:method:: test_get_babs(glat, glon, height, test_bmag) 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 .. py:method:: test_get_apex_with_invalid_lat(bad_lat) Test get methods raise ValueError for invalid latitudes. :Parameters: **bad_lat** (*int or float*) -- Bad input latitude in degrees N .. py:method:: test_get_babs_with_invalid_lat(bad_lat) Test get methods raise ValueError for invalid latitudes. :Parameters: **bad_lat** (*int or float*) -- Bad input latitude in degrees N .. py:method:: test_get_at_lat_boundary(bound_lat) Test get methods at the latitude boundary, with allowed excess. :Parameters: **bound_lat** (*int or float*) -- Boundary input latitude in degrees N .. py:method:: test_get_height_at_equator(apex_height) Test that `get_height` returns apex height at equator. :Parameters: **apex_height** (*float*) -- Apex height .. py:method:: test_get_height_along_fieldline(lat, height) 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 .. py:class:: TestApexMethodExtrapolateIGRF Bases: :py:obj:`object` Test the Apex methods on a year when IGRF must be extrapolated. .. rubric:: Notes Extrapolation should be done using a year within 5 years of the latest IGRF model epoch. .. py:method:: setup_method() Initialize all tests. .. py:method:: teardown_method() Clean up after each test. .. py:method:: test_method_scalar_input(method_name, out_comp) 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 .. py:method:: test_convert_to_mlt() Test conversion from mlon to mlt with scalars.