def old_dec(star_adjusted_declination): dec_x = star_adjusted_declination if star_adjusted_declination > 0: # Positive declinations dec_x = star_adjusted_declination % 360 # map from 0 to 90 (positive declinations) if dec_x > 90 and dec_x <= 180: dec_x = 90 + (90 - dec_x) # map from 0 to -90 (negative declinations) if dec_x <= 270 and dec_x > 180: dec_x = 180 - dec_x if dec_x < 360 and dec_x > 270: dec_x = -90 + (dec_x - 270) if star_adjusted_declination < -0: # Negative declinations dec_x = star_adjusted_declination % -360 # map from 0 to -90 (negative declinations) if dec_x < -90 and dec_x >= -180: dec_x = -90 - (90 + dec_x) # map from 0 to 90 (positive declinations) if dec_x >= -270 and dec_x <= -180: dec_x = 180 + dec_x dec_x = abs(dec_x) if dec_x > -360 and dec_x < -270: dec_x = 90 + (dec_x + 270) return dec_x def new_dec(dec): dec %= 360 # dec in [0, 360) if dec >= 270: dec -= 360 # dec in [-90, 270) if dec >= 90: dec = 180 - dec # ensure dec in [-90, 90) return dec def test_both(): print('input\told\tnew') for angle in range(0, 360 * 10, 15): for sign in [-1, 1]: test_angle = sign * angle old = old_dec(test_angle) new = new_dec(test_angle) assert old == new print(f'{test_angle}\t{old}\t{new}') test_both()