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.

Thank you for your time


Edited by WaltP: Spelling errors; Do not post email addresses on forums

4 Years
Discussion Span
Last Post by Xantipius

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 = open("C:/Users/Dani/Documents/Danielle/MRes/Tide Tables/Holyhead/2011HOL.txt",'r')
hh_data = file_hh.readlines()

#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[1],'/')   
      time_split = string.split(line_split[2],':')

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

      year = int(date_split[0])
      month = int(date_split[1])
      day = int(date_split[2])
      hr = int(time_split[0])
      mn = int(time_split[1])

      if tide > -98.000:

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

#figure size changes the size of the graph

ax1 = fig1.add_axes([0.1,0.1,0.8,0.8])
ax1.set_ylabel('Tidal Ranges')
ax1.set_title('Holyhead Tides')
#dpi is dots per inch 300 is reasonable
#print shows this on the screen

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


Edited by WaltP: Don't post email addresses

Thank you, email has been sent.
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

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

I don't understand the code pyTony sent... what is i and how did he get the values?
This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.