def validate_row(row): # validate MMSI, message_id and IMO if not utils.valid_mmsi(row[MMSI]) or not utils.valid_message_id(row[MESSAGE_ID]) or not check_imo(row[IMO]): raise ValueError("Row invalid") # check lat long for messages which should contain it if row[MESSAGE_ID] in CONTAINS_LAT_LON: if not (utils.valid_longitude(row[LONGITUDE]) and utils.valid_latitude(row[LATITUDE])): raise ValueError("Row invalid (lat,lon)") # otherwise set them to None else: row[LONGITUDE] = None row[LATITUDE] = None # validate other columns set_null_on_fail(row, NAV_STATUS, utils.valid_navigational_status) set_null_on_fail(row, SOG, utils.is_valid_sog) set_null_on_fail(row, COG, utils.is_valid_cog) set_null_on_fail(row, HEADING, utils.is_valid_heading) return row
def test_valid_latitude(self): for angle in np.linspace(-90, 90, 100): assert valid_latitude(angle) == True for angle in [-91, 91]: assert valid_latitude(angle) == False