Exemplo n.º 1
0
def unzip_1day_tar_file(
        tar_file_name, field_names, spc_date_string, top_target_directory_name,
        refl_heights_m_agl=None):
    """Unzips 1-day tar file (containing raw MYRORSS data for one SPC date).

    :param tar_file_name: Path to input file.
    :param field_names: 1-D list with names of radar fields.
    :param spc_date_string: SPC date (format "yyyymmdd").
    :param top_target_directory_name: Name of top-level directory for unzipped
        MYRORSS files.  This method will create a subdirectory therein for the
        SPC date.
    :param refl_heights_m_agl: 1-D integer numpy array of reflectivity heights
        (metres above ground level).
    :return: target_directory_name: Path to output directory.
    """

    error_checking.assert_is_string_list(field_names)
    error_checking.assert_is_numpy_array(
        numpy.asarray(field_names), num_dimensions=1)
    error_checking.assert_is_string(top_target_directory_name)

    # Put ignorable radar fields (ones that are allowed to be missing) at the
    # end.  This way, if the tar command errors out due to missing data, it will
    # do so after unzipping all the non-missing data.
    field_names_removed = []
    for this_field_name in IGNORABLE_RADAR_FIELD_NAMES:
        if this_field_name in field_names:
            field_names.remove(this_field_name)
            field_names_removed.append(this_field_name)

    for this_field_name in field_names_removed:
        field_names.append(this_field_name)

    field_to_heights_dict_m_agl = radar_io.field_and_height_arrays_to_dict(
        field_names, refl_heights_m_agl=refl_heights_m_agl,
        data_source=radar_io.MYRORSS_SOURCE_ID)

    target_directory_name = '{0:s}/{1:s}'.format(
        top_target_directory_name, spc_date_string)
    field_names = field_to_heights_dict_m_agl.keys()
    directory_names_to_unzip = []

    for this_field_name in field_names:
        these_heights_m_agl = field_to_heights_dict_m_agl[this_field_name]

        for this_height_m_agl in these_heights_m_agl:
            directory_names_to_unzip.append(
                radar_io.get_relative_dir_for_raw_files(
                    field_name=this_field_name, height_m_agl=this_height_m_agl,
                    data_source=radar_io.MYRORSS_SOURCE_ID))

    unzipping.unzip_tar(
        tar_file_name,
        target_directory_name=target_directory_name,
        file_and_dir_names_to_unzip=directory_names_to_unzip)

    return target_directory_name
Exemplo n.º 2
0
def unzip_1day_tar_file(tar_file_name, spc_date_string, top_target_dir_name,
                        scales_to_extract_metres2):
    """Unzips tar file with segmotion output for one SPC date.

    :param tar_file_name: Path to input file.
    :param spc_date_string: SPC date (format "yyyymmdd").
    :param top_target_dir_name: Name of top-level output directory.
    :param scales_to_extract_metres2: 1-D numpy array of tracking scales to
        extract.
    :return: target_directory_name: Path to output directory.  This will be
        "<top_target_directory_name>/<yyyymmdd>", where <yyyymmdd> is the SPC
        date.
    """

    # Verification.
    _ = time_conversion.spc_date_string_to_unix_sec(spc_date_string)
    error_checking.assert_file_exists(tar_file_name)
    error_checking.assert_is_greater_numpy_array(scales_to_extract_metres2, 0)
    error_checking.assert_is_numpy_array(scales_to_extract_metres2,
                                         num_dimensions=1)

    scales_to_extract_metres2 = numpy.round(scales_to_extract_metres2).astype(
        int)

    num_scales_to_extract = len(scales_to_extract_metres2)
    directory_names_to_unzip = []

    for j in range(num_scales_to_extract):
        this_relative_stats_dir_name = '{0:s}/{1:s}'.format(
            spc_date_string,
            _get_relative_stats_dir_physical_scale(
                scales_to_extract_metres2[j]))

        this_relative_polygon_dir_name = '{0:s}/{1:s}'.format(
            spc_date_string,
            _get_relative_polygon_dir_physical_scale(
                scales_to_extract_metres2[j]))

        directory_names_to_unzip.append(
            this_relative_stats_dir_name.replace(spc_date_string + '/', ''))
        directory_names_to_unzip.append(
            this_relative_polygon_dir_name.replace(spc_date_string + '/', ''))

    target_directory_name = '{0:s}/{1:s}/{2:s}'.format(top_target_dir_name,
                                                       spc_date_string[:4],
                                                       spc_date_string)

    unzipping.unzip_tar(tar_file_name,
                        target_directory_name=target_directory_name,
                        file_and_dir_names_to_unzip=directory_names_to_unzip)

    return target_directory_name
Exemplo n.º 3
0
def unzip_1day_tar_file(
        tar_file_name, field_names, spc_date_string, top_target_directory_name,
        refl_heights_m_asl=None):
    """Unzips 1-day tar file (containing raw MYRORSS data for one SPC date).

    :param tar_file_name: Path to input file.
    :param field_names: 1-D list with names of radar fields.
    :param spc_date_string: SPC date (format "yyyymmdd").
    :param top_target_directory_name: Name of top-level directory for unzipped
        MYRORSS files.  This method will create a subdirectory therein for the
        SPC date.
    :param refl_heights_m_asl: 1-D numpy array of reflectivity heights (metres
        above sea level).
    :return: target_directory_name: Path to output directory.
    """

    # Verification.
    _ = time_conversion.spc_date_string_to_unix_sec(spc_date_string)
    error_checking.assert_is_string_list(field_names)
    error_checking.assert_is_numpy_array(
        numpy.asarray(field_names), num_dimensions=1)
    error_checking.assert_is_string(top_target_directory_name)

    # Put azimuthal-shear fields (which are allowed to be missing) at the end.
    # This way, if the tar command errors out due to missing data, it will do so
    # after unzipping all the non-missing data.
    field_names_removed = []
    for this_field_name in AZIMUTHAL_RADAR_FIELD_NAMES:
        if this_field_name in field_names:
            field_names.remove(this_field_name)
            field_names_removed.append(this_field_name)

    for this_field_name in field_names_removed:
        field_names.append(this_field_name)

    field_to_heights_dict_m_asl = (
        myrorss_and_mrms_utils.fields_and_refl_heights_to_dict(
            field_names=field_names, data_source=radar_utils.MYRORSS_SOURCE_ID,
            refl_heights_m_asl=refl_heights_m_asl))

    target_directory_name = '{0:s}/{1:s}/{2:s}'.format(
        top_target_directory_name, spc_date_string[:4], spc_date_string
    )

    field_names = list(field_to_heights_dict_m_asl.keys())
    directory_names_to_unzip = []

    for this_field_name in field_names:
        these_heights_m_asl = field_to_heights_dict_m_asl[this_field_name]

        for this_height_m_asl in these_heights_m_asl:
            directory_names_to_unzip.append(
                myrorss_and_mrms_io.get_relative_dir_for_raw_files(
                    field_name=this_field_name,
                    data_source=radar_utils.MYRORSS_SOURCE_ID,
                    height_m_asl=this_height_m_asl))

    unzipping.unzip_tar(
        tar_file_name,
        target_directory_name=target_directory_name,
        file_and_dir_names_to_unzip=directory_names_to_unzip)

    return target_directory_name