An ice core is a cylinder shaped sample that comes from an ice cap, usually from the polar regions or from a glacier. Seeing that ice caps are formed by an accumulation of yearly snow layers, they are built out of ice from different years where the under layers are older than the upper layers. Thanks to analysis of the properties of the ice and the gas composition of crystallized air bulbs that are enclosed in the ice, a climatological reconstruction can be made of the period in which the ice core was formed. Based on the concentrations and the isotopes of carbon monoxide and methane, for example, one can map out the evolution of the local temperature and the atmospheric composure.

ijskern
Segment of 19 cm from the GISP 2 ice core (dept 1,855 m) in which the structure of the yearly layers was made visible by illuminating it from the bottom with a glass fibre source. The segment contains layers that were formed during 11 consecutive years, where the layers that were formed during summer (indicated with arrows) are enclosed in the darker layers that were formed during winter. 
ijskap Vostok
Reconstructed temperature (blue), concentration of carbon monoxide (CO2, green) and number of particles (red) in the Vostok ice cap (Antarctica) over a period of the past 420,000 years.

The picture above shows the evolution of temperature (blue), the concentration of carbon monoxide (green) and the amount of particles that were fixed (red) in the Vostok ice cap (Antarctica) ofer a period of the past 420.000 years. Here, a number of climatological cycles can be seen with the naked eye. However, the course of such time-series contains too much noise to immediately analyze them with a computer. This noise can be suppressed by simple mathematical techniques to level off the curves. 

In the left-hand figure below we have copied the original values of the carbon monoxide concentration and we have indicated the climatological cycles. In the middle figure, we have applied a mean flattening to the original values and the right-hand figure is a result of a triangle flattening. In the last two cases, the periodical character of the curve is pronounced even more clearly.

concentratie koolstofdioxide (geen afvlakking) concentratie koolstofdioxide (gemiddelde afvlakking) concentratie koolstofdioxide (driehoeksafvlakking)

Assignment

We have determined the concentration of a certain property (e.g. the concentration of carbon monoxide) alongside consecutive points of an ice core. The values on these measurement points were bundled in a list or tuple. Your assignment is to level off these measuring values so that it is can be analyzed more easily by a computer. Work as follows:

Example

In the interactive session below we have rounded off the floating point numbers in order to retain a brief example. In the assignment we do not ask to round off numbers. 

>>> CO2 = [285.5, 281.4, 277.2, 280.9, 282.7]
>>> weights = [0.5, 1.0, 0.5]
>>> weightedAverage(CO2, weights )
Traceback (most recent call last):
AssertionError: sequences should have equal length
>>> weights = [0.25, 0.5, 1.0, 0.5, 0.25]
>>> weightedAverage(CO2, weights )
280.16
>>> weightedAverage((4.0, 3.0, 7.0), (1.0, 2.0, 1.0))
4.25

>>> CO2 = [285.5, 281.4, 277.2, 280.9, 282.7, 280.9, 279.5, 279.1, 278.6, 278.2]
>>> smooth(CO2, weights)
[280.16, 280.57, 281.11, 280.8, 279.93, 279.17]
>>> smoothAverage(CO2)
[281.54, 280.62, 280.24, 280.62, 280.16, 279.26]
>>> smoothAverage(CO2, window=4)
[281.25, 280.55, 280.425, 281.0, 280.55, 279.525, 278.85]
>>> smoothTriangle(CO2)
[280.489, 280.533, 280.933, 280.789, 279.978, 279.178]
>>> smoothTriangle(CO2, window=4)
Traceback (most recent call last):
AssertionError: window size must be odd value
>>> smoothTriangle(CO2, window=3)
[281.375, 279.175, 280.425, 281.8, 281.0, 279.75, 279.075, 278.625]

Resources