How to find all peaks and troughs of tidal data?

I work with some ocean data that has been structured as follows:

$data = array('date' => array('time' => array('predicted','observed')));

Here is an example of the real data that I use: http://pastebin.com/raw.php?i=bRc2rmpG

And this is my attempt to find high / low values: http://pastebin.com/8PS1frc0

Current issues with my code:

  • When the readings change (as seen in the range from 11/14/2010=>11:30:00to 11/14/2010=>11:54:00in the data samples), it creates a “wobble” in the direction logic. This creates an erroneous peak and deflection. How can I avoid / fix this?

Note. My method is very ad-hoc. I suggested that I don’t need any awesome stuff, since I am not trying to find any average, approximate or future estimates, I really appreciate the code example of the best method, even if it means throwing away the code that I wrote so far .

+3
source share
7 answers

Are you looking for local lows and highs, I suppose? This is very easy to do:

<?php

$data = array(1, 9, 4, 5, 6, 9, 9, 1);

function minima($data, $radius = 2)
{
  $minima = array();

  for ($i = 0; $i < count($data); $i += $radius)
  {
    $minima[] = min(array_slice($data, $i, $radius));
  }

  return $minima;
}

function maxima($data, $radius = 2)
{
  $maxima = array();

  for ($i = 0; $i < count($data); $i += $radius)
  {
    $maxima[] = max(array_slice($data, $i, $radius));
  }

  return $maxima;
}

print_r(minima($data));
print_r(maxima($data));

?>

, . : $radius . .

: , . 2, / 2, , , . .

script, .

!

+2

. , . , .

  • , (HH * 3600) + (MM * 60) + (SS), "X".
  • X Y , , 10 . / .
  • Y [1] Y [0]. , (Y [1] > Y [0]), , . (Y [1] < Y [0]), , .
  • , , : Y [i] > Y [i + 1] Y [i] Y [i-1], .
  • / , X X, ( " " ). ( ) HH: MM: SS .
+2

, ad-hoc. , ,

 f(A,B,w,p;t)=Asin(wt+p)+B 

(, , ). , , . w p, , :

t = (pi(1+2n)-2p)/w

, , , . .:)

+1

, , . , , . :

  • , .

  • . . , $error = 0.10; if $previous - $error > $current ..

+1

/? , , ?

. "i", [i-1] [i + 1] " ", [i], . [i-1] [i + 1] , [i], . , ( ), /.

/, .

0

, / , /.

$direction , , ( ) , / "".

0

Given that you should never see two max or 2 minutes in less than 12 hours, a simple solution would be to use sliding windows 3-5 hours or so and find the maximum and minimum values. If it ends within the first or last 30 minutes, ignore it.

As an example, given the following data:

1 2 3 4 5 6 5 6 7 8 7 6 5 4 3 2 1 2

and a window of size 8 with the first and last 2, ignored and looking only under the eyes:

1 2 | 3 4 5 6 | 5 6,  max = 6, ignore = Y
2 3 | 4 5 6 5 | 6 7,  max = 7, ignore = Y
3 4 | 5 6 5 6 | 7 8,  max = 8, ignore = Y
4 5 | 6 5 6 7 | 8 7,  max = 8, ignore = Y
5 6 | 5 6 7 8 | 7 6,  max = 8, ignore = N
6 5 | 6 7 8 7 | 6 5,  max = 8, ignore = N
5 6 | 7 8 7 6 | 5 4,  max = 8, ignore = N
6 7 | 8 7 6 5 | 4 3,  max = 8, ignore = N
7 8 | 7 6 5 4 | 3 2,  max = 8, ignore = Y
8 7 | 6 5 4 3 | 2 1,  max = 8, ignore = Y
7 6 | 5 4 3 2 | 1 2,  max = 7, ignore = Y
0
source

Source: https://habr.com/ru/post/1774598/


All Articles