Assignment 8

Problems

  1. Insect data

    We have researchers studying birds and their behaviour at Yukon University. The insects inside a bird’s nesting area have a huge impact on the reproductive success of the birds. As such our researchers have set up traps to catch insects in the habitats of birds they are interested in monitoring. Dr. Tara Stehelin shared her data, which is available in a tab separated file called insect_biomas.txt. The file is available on the Moodle. We would like to load this file into python and find out the total number and mass of insects captured per year, and the difference between those numbers in different years.

    a. Write a function called load_insect_data that has one argument: a string representing the name of the datafile. The function should return the data from the file as a list of lists. Keep the first row that has the column names.

    b. Write a function called calculate_biomass that has one argument: the data as a list of lists. The function should calculate the biomass of insects associated with each row. The function should add a new column to the data called biomass, the biomass is equal to the weight * numberday. The function should not return anything, but instead edit the list it was sent.

    c. Write a function called yearly_biomass that has one argument: the data from the file as a list of lists. The function should return a dictionary where the key is the year, and the value is the total biomass for that year.

  2. Small mammal data

    At Yukon University we also have researchers tracking wildlife around Yukon since 2005. They have collected data about mice from a site near Whitehorse. They used live trapping techniques to record details of various small mammal they caught during each trapping session. Dr. Scott Gilbert shared some of his research data in a comma separated text file small_mammal_data.csv. The file is available on the Moodle. We are particularly interested in the reproductive health of the female Clethrionomys sp. There are many columns in the data that represent different characteristics of the mice that were tracked at different time points over the summer.

    a. Write a function called load_mouse_data that has two arguments: a string representing the name of the datafile and a string representing the mouse Species that we are interested in. The function should return the data from the file as a list of lists with only the rows for that mouse species. Keep the first row that has the column names. Try to solve this without loading the whole file.

    b. Write a function called save_mouse_data that has two arguments: the data as a list of lists and a string called filename that indicates where to save the modified data. The function should create a new data file of the mouse data with filename specified. The function should return None.

    c. Write function called sexed_weight that has two arguments: the data from the file as a list of lists and an integer indicating the Sex you are interested in (1 for male and 2 for female). The function returns a float that represents the mean weight of the mice of that sex in that dataset.

    d. Write a function called lactation_status that takes the data from the file as a list of lists and returns a dictionary where the keys are the Lactation status and the values are the counts of the females with that lactation status. A lactation status of 1 means not lactating, 2 means just starting or finishing lactating, and 3 indicates that they are lactating for sure.

  3. Testing biggest()

    The last few assignments have provided you with examples of testing harnesses to ensure programs are working correctly. Now it is time for you to design some tests of your own. The file a8p3kate.py contains six versions of a function named biggest that all claim to return the largest of three values they are passed. Add test cases to the program to determine which ones (if any) work correctly. Based on your test cases identify the situations (if any) in which each version fails, and the reason for the failure, i.e. what the problem is with the code. Enter your answers into the docstrings for each function.

Logistics