コード例 #1
0
    def test_check_data_source_gridrad(self):
        """Ensures correct output from check_data_source.

        In this case, data source is GridRad.
        """

        radar_utils.check_data_source(radar_utils.GRIDRAD_SOURCE_ID)
コード例 #2
0
    def test_check_data_source_mrms(self):
        """Ensures correct output from check_data_source.

        In this case, data source is MRMS.
        """

        radar_utils.check_data_source(radar_utils.MRMS_SOURCE_ID)
コード例 #3
0
    def test_check_data_source_fake(self):
        """Ensures correct output from check_data_source.

        In this case, data source is fake.
        """

        with self.assertRaises(ValueError):
            radar_utils.check_data_source(FAKE_DATA_SOURCE)
コード例 #4
0
def write_matches(
        pickle_file_name, source_to_target_dict, max_time_diff_seconds,
        max_distance_metres, source_dataset_name, source_tracking_dir_name,
        target_dataset_name, target_tracking_dir_name):
    """Writes matches to Pickle file.

    "Matches" are between storm storm objects in one dataset (e.g., MYRORSS or
    GridRad) and those in another dataset, at one time step.

    :param pickle_file_name: Path to output file.
    :param source_to_target_dict: Dictionary, where each key is a tuple with
        (source ID, source time) and each value is a list with [target ID,
        target time].  The IDs are strings, and the times are Unix seconds
        (integers).  For source objects with no match in the target dataset, the
        corresponding value is None (rather than a list).
    :param max_time_diff_seconds: Max time difference between matched storm
        objects.
    :param max_distance_metres: Max distance between matched storm objects.
    :param source_dataset_name: Name of source dataset (must be accepted by
        `radar_utils.check_data_source`).
    :param source_tracking_dir_name: Name of top-level directory with tracks for
        source dataset.
    :param target_dataset_name: Same but for target dataset.
    :param target_tracking_dir_name: Same but for target dataset.
    """

    error_checking.assert_is_string(pickle_file_name)
    error_checking.assert_is_integer(max_time_diff_seconds)
    error_checking.assert_is_geq(max_time_diff_seconds, 0)
    error_checking.assert_is_greater(max_distance_metres, 0.)
    radar_utils.check_data_source(source_dataset_name)
    error_checking.assert_is_string(source_tracking_dir_name)
    radar_utils.check_data_source(target_dataset_name)
    error_checking.assert_is_string(target_tracking_dir_name)

    metadata_dict = {
        MAX_TIME_DIFF_KEY: max_time_diff_seconds,
        MAX_DISTANCE_KEY: max_distance_metres,
        SOURCE_DATASET_KEY: source_dataset_name,
        SOURCE_TRACKING_DIR_KEY: source_tracking_dir_name,
        TARGET_DATASET_KEY: target_dataset_name,
        TARGET_TRACKING_DIR_KEY: target_tracking_dir_name
    }

    file_system_utils.mkdir_recursive_if_necessary(file_name=pickle_file_name)

    pickle_file_handle = open(pickle_file_name, 'wb')
    pickle.dump(source_to_target_dict, pickle_file_handle)
    pickle.dump(metadata_dict, pickle_file_handle)
    pickle_file_handle.close()