def convert_lng_positive_in_west(longitudes_deg, allow_nan=True): """Converts longitudes so that all WH values are positive. In other words, all values in WH are from 180...360 deg E. :param longitudes_deg: scalar or numpy array of longitudes (deg E). :param: allow_nan: Boolean flag. If True, NaN longitudes will be allowed. :return: longitudes_positive_in_west_deg: Same as input, except that longitudes in WH are positive. """ was_input_array = isinstance(longitudes_deg, numpy.ndarray) if not was_input_array: longitudes_deg = numpy.full(1, longitudes_deg) error_checking.assert_is_valid_lng_numpy_array(longitudes_deg, allow_nan=allow_nan) longitudes_positive_in_west_deg = copy.deepcopy(longitudes_deg) longitudes_positive_in_west_deg[ longitudes_positive_in_west_deg < 0.] += 360. if was_input_array: return longitudes_positive_in_west_deg return longitudes_positive_in_west_deg[0]
def test_assert_is_valid_lng_numpy_array_negative_in_west_true(self): """Checks assert_is_valid_lng_numpy_array; negative_in_west_flag = True. In this case, longitudes in western hemisphere are negative. """ error_checking.assert_is_valid_lng_numpy_array( LNG_NUMPY_ARRAY_NEGATIVE_IN_WEST_DEG, negative_in_west_flag=True)
def test_assert_is_valid_lng_numpy_array_negative_in_west_false(self): """Checks assert_is_valid_lng_numpy_array; negative_in_west_flag = True. In this case, longitudes in western hemisphere are positive. """ with self.assertRaises(ValueError): error_checking.assert_is_valid_lng_numpy_array( LNG_NUMPY_ARRAY_POSITIVE_IN_WEST_DEG, negative_in_west_flag=True)
def test_assert_is_valid_lng_numpy_array_true(self): """Checks assert_is_valid_lng_numpy_array; all longitudes valid.""" error_checking.assert_is_valid_lng_numpy_array(LNG_NUMPY_ARRAY_DEG)
def test_assert_is_valid_lng_numpy_array_some_invalid(self): """Checks assert_is_valid_lng_numpy_array; some longitudes invalid.""" with self.assertRaises(ValueError): error_checking.assert_is_valid_lng_numpy_array( LNG_NUMPY_ARRAY_SOME_INVALID_DEG)