## danifj

My name is Danielle Jacob and I am a Masters (through) Research student at Bangor University, North Wales.

[email removed]

I have been using Python now for about 3 months (but only once a fortnight for a few hours at a time...so I am still very new)

My supervisor extracted some tidal range data for a location in Wales (Holyhead) for 2011. For those of you who know tidal ranges it is supposed to look like a series of double helix oscillations. When I got the data there were some anomalies, such as a result of +40 (normally results should not exceed 5). These look like peaks in Python graphs.

There are a series of anomalies which I am able to identify. I asked my supervisor and he simply said to look up the code for creating an average of the before and after points to 'fake' the data.

What I want to know please is how to do this.

1. Identify the anomalies.
2. Take the before and after points and average them.

I have a graph set up.... I just need to change the appearance of the data on the graph. I can send you some of the code and a screen grab of the current graph.

Dani

## danifj

This is my script - to be honest I hardly understand any of it.

``````import numpy as np
import pylab
import string
import datetime as dt
import matplotlib.ticker as ticker
import matplotlib.dates as mdates

file_hh.close()
n_data_hh=len(hh_data)

#ASLVBG02 = sealevel

hh_date = []
hh_sealevel = []

# Loop over every line in the dataset
for yind in range(11,n_data_hh):
#   | Indent starts here

line_split = string.split(hh_data[yind])

# Check we aren't looking at a blank line at the end
if len(line_split) > 1:
# | Indent starts here
#print line_split

date_split = string.split(line_split,'/')
time_split = string.split(line_split,':')

if line_split[-1] == "M" or line_split[-1] == "N" or line_split[-1] == "T":
tide = float(line_split[:-1])
else:
tide = float(line_split)
#print date_split,time_split,tide

year = int(date_split)
month = int(date_split)
day = int(date_split)
hr = int(time_split)
mn = int(time_split)

if tide > -98.000:
hh_date.append(dt.datetime(year,month,day,hr,mn,0))
hh_sealevel.append(tide)

fig1 = pylab.figure(figsize=(8,6))

#figure size changes the size of the graph

ax1.plot(hh_date,hh_sealevel)
ax1.set_xlabel('Time')
ax1.set_ylabel('Tidal Ranges')
#fig1.savefig('C:\Users\Dani\Desktop\Windconditions.png',dpi=300)
#dpi is dots per inch 300 is reasonable
#print shows this on the screen
pylab.show()
``````

## Xantipius 15

Dani,
email to me ( [email removed] ) the data file.
And I will try to understand what exactly have to be done.

Vitali

commented: Thank you, email has been sent. +0

## TrustyTony 888

``````low, high  = 10, 100

values = [12, 14, -34, 25, 200, 23, -23, 45, 23]

for i in range(1,len(values)-1):
if values[i] < low or values[i] > high:
# assuming that first value and last value are not off
# and neighbouring values are not off
values[i] = (values[i-1] + values[i+1]) / 2.0
print values
``````

## Xantipius 15

I think pyTony's code is quite enough a solution.

commented: I don't understand the code pyTony sent... what is i and how did he get the values? +0