cratermaker.utils.general_utils.validate_and_normalize_location#
- cratermaker.utils.general_utils.validate_and_normalize_location(location)[source]#
Validate and normalize a given location into a standard structured format.
This function checks the input location data and converts it into a consistent structured array format if it is a valid location representation. Valid formats for location include a tuple, a dictionary, or a structured array with longitude (‘lon’) and latitude (‘lat’).
- Parameters:
location (tuple, dict, ArrayLike) – The input location data. It can be: - A tuple, list, or array with two elements (longitude, latitude). - A dictionary with keys ‘lon’ and ‘lat’. - A structured numpy array with ‘lon’ and ‘lat’ fields. - A 2D array of shape (N, 2) where each row is a (longitude, latitude) pair.
- Returns:
tuple or list of tuples – longitude and latitude as a tuple of floats in degrees.
- Raises:
ValueError – If the input does not conform to one of the expected formats for location data.
Examples
>>> validate_and_normalize_location((370, 95)) (10.0, 85.0))
>>> validate_and_normalize_location({"lat": 45.0, "lon": 120.0}) (-120., 45.)
>>> validate_and_normalize_location(np.array([(-120.0, 45.0)], dtype=[("lon", "f8"), ("lat", "f8")])) (-120., 45.)