def setUpTestData(cls):
        batch_num = 0
        section_num = 0
        voter_num = 0
        party_num = 0
        position_num = 0
        candidate_num = 0
        num_elections = 2
        voters = list()
        positions = dict()
        for i in range(num_elections):
            election = Election.objects.create(name='Election {}'.format(i))
            positions[str(election.name)] = list()

            num_batches = 2
            for j in range(num_batches):
                batch = Batch.objects.create(year=batch_num, election=election)
                batch_num += 1

                num_sections = 2 if j == 0 else 1
                for k in range(num_sections):
                    section = Section.objects.create(
                        section_name=str(section_num)
                    )
                    section_num += 1

                    num_students = 2
                    for l in range(num_students):
                        voter = User.objects.create(
                            username='user{}'.format(voter_num),
                            first_name=str(voter_num),
                            last_name=str(voter_num),
                            type=UserType.VOTER
                        )
                        voter.set_password('voter')
                        voter.save()
                        voter_num += 1

                        VoterProfile.objects.create(
                            user=voter,
                            batch=batch,
                            section=section
                        )

                        voters.append(voter)

            num_positions = 3
            for i in range(num_positions):
                position = CandidatePosition.objects.create(
                    position_name='Position {}'.format(position_num),
                    election=election
                )

                positions[str(election.name)].append(position)

                position_num += 1

            num_parties = 3
            for j in range(num_parties):
                party = CandidateParty.objects.create(
                    party_name='Party {}'.format(party_num),
                    election=election
                )
                party_num += 1

                if j != 2:  # Let every third party have no candidates.
                    num_positions = 3
                    for k in range(num_positions):
                        position = positions[str(election.name)][k]

                        candidate = Candidate.objects.create(
                            user=voters[candidate_num],
                            party=party,
                            position=position,
                            election=election
                        )

                        Vote.objects.create(
                            user=voters[candidate_num],
                            candidate=candidate,
                            election=election
                        )

                        candidate_num += 1

        # Let's give one candidate an additional vote to really make sure that
        # we all got the correct number of votes.
        Vote.objects.create(
            user=voters[0],
            # NOTE: The voter in voter[1] is a Position 1 candidate of
            #       Party 1, where the voter in voter[0] is a member.
            candidate=Candidate.objects.get(user=voters[1]),
            election=Election.objects.get(name='Election 0')
        )

        _admin = User.objects.create(username='admin', type=UserType.ADMIN)
        _admin.set_password('root')
        _admin.save()
def read_specific_examples(
        netcdf_file_name, read_all_target_vars, full_storm_id_strings,
        storm_times_unix_sec, target_name=None, include_soundings=True,
        radar_field_names_to_keep=None, radar_heights_to_keep_m_agl=None,
        sounding_field_names_to_keep=None, sounding_heights_to_keep_m_agl=None,
        num_rows_to_keep=None, num_columns_to_keep=None):
    """Reads specific examples (with specific ID-time pairs) from NetCDF file.

    :param netcdf_file_name: Path to input file.
    :param read_all_target_vars: See doc for `read_example_file`.
    :param full_storm_id_strings: length-E list of storm IDs.
    :param storm_times_unix_sec: length-E numpy array of valid times.
    :param target_name: See doc for `read_example_file`.
    :param metadata_only: Same.
    :param include_soundings: Same.
    :param radar_field_names_to_keep: Same.
    :param radar_heights_to_keep_m_agl: Same.
    :param sounding_field_names_to_keep: Same.
    :param sounding_heights_to_keep_m_agl: Same.
    :param num_rows_to_keep: Same.
    :param num_columns_to_keep: Same.
    :return: example_dict: See doc for `write_example_file`.
    """

    if (
            target_name ==
            'tornado_lead-time=0000-3600sec_distance=00000-10000m'
    ):
        target_name = (
            'tornado_lead-time=0000-3600sec_distance=00000-30000m_min-fujita=0'
        )

    error_checking.assert_is_boolean(read_all_target_vars)
    error_checking.assert_is_boolean(include_soundings)

    example_dict, dataset_object = _read_metadata_from_example_file(
        netcdf_file_name=netcdf_file_name, include_soundings=include_soundings)

    example_indices_to_keep = tracking_utils.find_storm_objects(
        all_id_strings=example_dict[FULL_IDS_KEY],
        all_times_unix_sec=example_dict[STORM_TIMES_KEY],
        id_strings_to_keep=full_storm_id_strings,
        times_to_keep_unix_sec=storm_times_unix_sec, allow_missing=False
    )

    example_dict[FULL_IDS_KEY] = [
        example_dict[FULL_IDS_KEY][k] for k in example_indices_to_keep
    ]
    example_dict[STORM_TIMES_KEY] = example_dict[STORM_TIMES_KEY][
        example_indices_to_keep]

    if read_all_target_vars:
        example_dict[TARGET_MATRIX_KEY] = numpy.array(
            dataset_object.variables[TARGET_MATRIX_KEY][
                example_indices_to_keep, :],
            dtype=int
        )
    else:
        target_index = example_dict[TARGET_NAMES_KEY].index(target_name)
        example_dict[TARGET_NAME_KEY] = target_name
        example_dict.pop(TARGET_NAMES_KEY)

        example_dict[TARGET_VALUES_KEY] = numpy.array(
            dataset_object.variables[TARGET_MATRIX_KEY][
                example_indices_to_keep, target_index],
            dtype=int
        )

    example_dict = _subset_radar_data(
        example_dict=example_dict, netcdf_dataset_object=dataset_object,
        example_indices_to_keep=example_indices_to_keep,
        field_names_to_keep=radar_field_names_to_keep,
        heights_to_keep_m_agl=radar_heights_to_keep_m_agl,
        num_rows_to_keep=num_rows_to_keep,
        num_columns_to_keep=num_columns_to_keep)

    if not include_soundings:
        dataset_object.close()
        return example_dict

    example_dict = _subset_sounding_data(
        example_dict=example_dict, netcdf_dataset_object=dataset_object,
        example_indices_to_keep=example_indices_to_keep,
        field_names_to_keep=sounding_field_names_to_keep,
        heights_to_keep_m_agl=sounding_heights_to_keep_m_agl)

    dataset_object.close()
    return example_dict