Exemple #1
0
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
Exemple #2
0
 def test_valid_longitude(self):
     for angle in np.linspace(-180, 180, 100):
         assert valid_longitude(angle) == True
     for angle in [-181, 181]:
         assert valid_longitude(angle) == False
Exemple #3
0
 def test_valid_longitude(self):
     for angle in np.linspace(-180, 180, 100):
         assert valid_longitude(angle) == True
     for angle in [-181, 181]:
         assert valid_longitude(angle) == False