-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtidal.html
More file actions
1102 lines (968 loc) · 56.9 KB
/
tidal.html
File metadata and controls
1102 lines (968 loc) · 56.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tidal Ellipse Analysis Tool</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.11.0/math.min.js"></script>
<style>
.ocean-gradient {
background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 25%, #2563eb 50%, #3b82f6 75%, #60a5fa 100%);
}
.tidal-animation {
background: linear-gradient(-45deg, #3b82f6, #2563eb, #1e40af, #1e3a8a);
background-size: 400% 400%;
animation: tidal 6s ease-in-out infinite;
}
@keyframes tidal {
0%, 100% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
}
.ellipse-card {
transition: all 0.3s ease;
backdrop-filter: blur(10px);
}
.ellipse-card:hover {
transform: translateY(-2px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
}
.parameter-highlight {
background: linear-gradient(45deg, #f0f9ff, #e0f2fe);
border-left: 4px solid #3b82f6;
}
.constituent-badge {
background: linear-gradient(45deg, #dbeafe, #bfdbfe);
border: 1px solid #93c5fd;
}
</style>
</head>
<body class="bg-slate-50 text-slate-800">
<!-- Navigation -->
<nav class="fixed top-0 w-full bg-white/90 backdrop-blur-md shadow-sm z-50">
<div class="max-w-7xl mx-auto px-6 py-4">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-bold text-slate-800">🌊 Tidal Ellipse Analyzer</h1>
<div class="hidden md:flex space-x-6">
<a href="#input" class="text-slate-600 hover:text-blue-600 transition-colors">Data Input</a>
<a href="#analysis" class="text-slate-600 hover:text-blue-600 transition-colors">Analysis</a>
<a href="#theory" class="text-slate-600 hover:text-blue-600 transition-colors">Theory</a>
</div>
</div>
</div>
</nav>
<!-- Hero Section -->
<section class="pt-20 pb-12 ocean-gradient text-white">
<div class=></div>
<div class="relative z-10 max-w-6xl mx-auto px-6 text-center">
<h1 class="text-4xl md:text-6xl font-bold mb-6">Tidal Ellipse Analysis</h1>
<p class="text-lg md:text-xl mb-8 text-blue-200 max-w-3xl mx-auto">
Advanced harmonic analysis of tidal currents with ellipse parameter calculation, constituent identification, and comprehensive visualization by Claudio Iturra
</p>
<a href="#input" class="inline-block bg-white text-blue-600 px-8 py-3 rounded-full font-semibold hover:bg-blue-50 transition-colors">
Start Analysis
</a>
</div>
</section>
<!-- Data Input Section -->
<section id="input" class="py-16">
<div class="max-w-6xl mx-auto px-6">
<div class="text-center mb-12">
<h2 class="text-3xl font-bold mb-4 text-slate-800">Tidal Velocity Data Input</h2>
<p class="text-xl text-slate-600">Enter your tidal velocity time series and location parameters</p>
</div>
<div class="grid lg:grid-cols-2 gap-8">
<!-- Data Input Panel -->
<div class="bg-white rounded-2xl p-6 shadow-lg">
<h3 class="text-2xl font-bold mb-6 text-slate-800">Input Configuration</h3>
<!-- Location Parameters -->
<div class="mb-6 p-4 bg-blue-50 rounded-lg">
<h4 class="font-semibold text-slate-800 mb-3">📍 Location Parameters</h4>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-slate-700 mb-2">Latitude (°N)</label>
<input type="number" id="latitude" step="0.1" value="45.0"
class="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-2">Longitude (°E)</label>
<input type="number" id="longitude" step="0.1" value="-125.0"
class="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
</div>
</div>
<!-- Method Selection -->
<div class="mb-6">
<label class="block text-sm font-medium text-slate-700 mb-3">Choose Input Method:</label>
<div class="flex flex-wrap gap-2">
<button id="manual-btn" onclick="setInputMethod('manual')" class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors text-sm">
Manual Entry
</button>
<button id="sample-btn" onclick="setInputMethod('sample')" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition-colors text-sm">
Sample Data
</button>
<button id="synthetic-btn" onclick="setInputMethod('synthetic')" class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors text-sm">
Synthetic Tides
</button>
</div>
</div>
<!-- Manual Input -->
<div id="manual-input" class="space-y-4">
<div>
<label class="block text-sm font-medium text-slate-700 mb-2">Time (hours from start) - comma separated</label>
<textarea id="time-data" rows="2" placeholder="0, 1, 2, 3, 4, ..."
class="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm"></textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-2">U Component (m/s) - comma separated</label>
<textarea id="u-data" rows="2" placeholder="0.5, 0.3, -0.2, -0.6, ..."
class="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm"></textarea>
</div>
<div>
<label class="block text-sm font-medium text-slate-700 mb-2">V Component (m/s) - comma separated</label>
<textarea id="v-data" rows="2" placeholder="0.2, 0.6, 0.4, -0.1, ..."
class="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm"></textarea>
</div>
</div>
<!-- Synthetic Data Generator -->
<div id="synthetic-input" class="space-y-4 hidden">
<h4 class="font-semibold text-slate-800">Synthetic Tidal Parameters</h4>
<div class="space-y-4">
<div class="grid grid-cols-3 gap-4">
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">M2 Amplitude (m/s)</label>
<input type="number" id="m2-amp" step="0.01" value="1.2" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">M2 Phase (°)</label>
<input type="number" id="m2-phase" step="1" value="30" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">M2 Inclination (°)</label>
<input type="number" id="m2-incl" step="1" value="15" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
</div>
<div class="grid grid-cols-3 gap-4">
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">S2 Amplitude (m/s)</label>
<input type="number" id="s2-amp" step="0.01" value="0.4" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">S2 Phase (°)</label>
<input type="number" id="s2-phase" step="1" value="60" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">S2 Inclination (°)</label>
<input type="number" id="s2-incl" step="1" value="-10" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">Duration (days)</label>
<input type="number" id="duration" step="1" value="15" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">Sampling (hours)</label>
<input type="number" id="sampling" step="0.1" value="0.5" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
</div>
</div>
</div>
<button onclick="generateSyntheticData()" class="w-full bg-green-600 text-white py-2 rounded-lg hover:bg-green-700 transition-colors">
Generate Synthetic Tidal Data
</button>
</div>
<!-- Analysis Options -->
<div class="mt-6 p-4 bg-slate-50 rounded-lg">
<h4 class="font-semibold text-slate-800 mb-3">Analysis Options</h4>
<div class="space-y-3">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">Analysis Method</label>
<select id="analysis-method" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
<option value="harmonic">Harmonic Analysis</option>
<option value="least_squares">Least Squares</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-slate-700 mb-1">Constituents</label>
<select id="constituents" class="w-full px-2 py-1 border border-slate-300 rounded text-sm">
<option value="major">Major (M2, S2, N2, K1, O1)</option>
<option value="all">All Available</option>
<option value="custom">Custom Selection</option>
</select>
</div>
</div>
<label class="flex items-center">
<input type="checkbox" id="nodal-corrections" checked class="mr-2">
<span class="text-sm">Apply Nodal Corrections</span>
</label>
<label class="flex items-center">
<input type="checkbox" id="confidence-intervals" checked class="mr-2">
<span class="text-sm">Calculate Confidence Intervals</span>
</label>
</div>
</div>
<button onclick="performTidalAnalysis()" class="w-full mt-6 bg-blue-600 text-white py-3 rounded-lg hover:bg-blue-700 transition-colors font-semibold">
🔍 Analyze Tidal Ellipses
</button>
</div>
<!-- Information Panel -->
<div class="bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl p-6">
<h3 class="text-2xl font-bold mb-4 text-slate-800">Tidal Ellipse Parameters</h3>
<div class="space-y-4">
<div class="bg-white/70 rounded-lg p-4">
<h4 class="font-semibold text-slate-800 mb-2">🔄 Ellipse Geometry</h4>
<ul class="text-sm text-slate-600 space-y-1">
<li>• <strong>Semi-major axis (a):</strong> Maximum current speed</li>
<li>• <strong>Semi-minor axis (b):</strong> Minimum current speed</li>
<li>• <strong>Inclination (θ):</strong> Orientation of major axis</li>
<li>• <strong>Eccentricity (e):</strong> Shape parameter (0=circle, 1=line)</li>
</ul>
</div>
<div class="bg-white/70 rounded-lg p-4">
<h4 class="font-semibold text-slate-800 mb-2">🌊 Tidal Properties</h4>
<ul class="text-sm text-slate-600 space-y-1">
<li>• <strong>Phase (φ):</strong> Time of maximum current</li>
<li>• <strong>Sense:</strong> Clockwise or counterclockwise rotation</li>
<li>• <strong>Amplitude:</strong> Vector magnitude of tidal current</li>
<li>• <strong>Greenwich phase:</strong> Referenced to Greenwich</li>
</ul>
</div>
<div class="bg-white/70 rounded-lg p-4">
<h4 class="font-semibold text-slate-800 mb-2">📊 Major Constituents</h4>
<div class="grid grid-cols-2 gap-2 text-xs text-slate-600">
<div><strong>M2:</strong> 12.42h (Principal lunar)</div>
<div><strong>S2:</strong> 12.00h (Principal solar)</div>
<div><strong>N2:</strong> 12.66h (Lunar elliptic)</div>
<div><strong>K1:</strong> 23.93h (Lunar diurnal)</div>
<div><strong>O1:</strong> 25.82h (Lunar diurnal)</div>
<div><strong>K2:</strong> 11.97h (Lunisolar)</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Analysis Results Section -->
<section id="analysis" class="py-16 bg-white">
<div class="max-w-7xl mx-auto px-6">
<div class="text-center mb-12">
<h2 class="text-3xl font-bold mb-4 text-slate-800">Tidal Ellipse Analysis Results</h2>
<p class="text-xl text-slate-600">Comprehensive harmonic analysis and ellipse visualization</p>
</div>
<div id="results-container" class="hidden">
<!-- Time Series and Hodograph -->
<div class="grid lg:grid-cols-2 gap-8 mb-8">
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200">
<h3 class="text-xl font-bold mb-4 text-slate-800">Velocity Time Series</h3>
<div id="timeseries-plot" class="w-full h-80"></div>
</div>
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200">
<h3 class="text-xl font-bold mb-4 text-slate-800">Current Hodograph</h3>
<div id="hodograph-plot" class="w-full h-80"></div>
</div>
</div>
<!-- Tidal Ellipses -->
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200 mb-8">
<h3 class="text-xl font-bold mb-4 text-slate-800">Tidal Ellipses by Constituent</h3>
<div id="ellipses-plot" class="w-full h-96"></div>
</div>
<!-- Constituent Parameters -->
<div class="grid lg:grid-cols-2 gap-8 mb-8">
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200">
<h3 class="text-xl font-bold mb-4 text-slate-800">Constituent Parameters</h3>
<div id="parameters-table" class="overflow-x-auto">
<!-- Parameters table will be populated here -->
</div>
</div>
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200">
<h3 class="text-xl font-bold mb-4 text-slate-800">Ellipse Properties</h3>
<div id="ellipse-properties" class="space-y-4">
<!-- Ellipse properties will be populated here -->
</div>
</div>
</div>
<!-- Residual Analysis -->
<div class="grid lg:grid-cols-2 gap-8 mb-8">
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200">
<h3 class="text-xl font-bold mb-4 text-slate-800">Model vs Observations</h3>
<div id="model-comparison-plot" class="w-full h-80"></div>
</div>
<div class="ellipse-card bg-white rounded-2xl p-6 shadow-lg border border-slate-200">
<h3 class="text-xl font-bold mb-4 text-slate-800">Residual Analysis</h3>
<div id="residual-plot" class="w-full h-80"></div>
</div>
</div>
<!-- Summary Statistics -->
<div class="ellipse-card bg-slate-50 rounded-2xl p-6">
<h3 class="text-2xl font-bold mb-6 text-slate-800">Analysis Summary</h3>
<div class="grid md:grid-cols-3 gap-6">
<div class="parameter-highlight p-4 rounded-lg">
<h4 class="font-semibold text-slate-800 mb-2">Model Performance</h4>
<div id="model-stats" class="space-y-1 text-sm text-slate-600">
<!-- Model statistics will be populated here -->
</div>
</div>
<div class="parameter-highlight p-4 rounded-lg">
<h4 class="font-semibold text-slate-800 mb-2">Dominant Constituents</h4>
<div id="dominant-constituents" class="space-y-1 text-sm text-slate-600">
<!-- Dominant constituents will be populated here -->
</div>
</div>
<div class="parameter-highlight p-4 rounded-lg">
<h4 class="font-semibold text-slate-800 mb-2">Location Info</h4>
<div id="location-info" class="space-y-1 text-sm text-slate-600">
<!-- Location information will be populated here -->
</div>
</div>
</div>
</div>
</div>
<!-- No Results Message -->
<div id="no-results" class="text-center py-12">
<svg class="w-24 h-24 mx-auto text-slate-300 mb-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"></path>
</svg>
<h3 class="text-2xl font-bold text-slate-600 mb-4">No Analysis Results Yet</h3>
<p class="text-slate-500 mb-6">Enter your tidal velocity data and perform analysis to see ellipse results</p>
<a href="#input" class="inline-block bg-blue-600 text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition-colors">
Go to Data Input
</a>
</div>
</div>
</section>
<!-- Theory Section -->
<section id="theory" class="py-16 bg-slate-50">
<div class="max-w-6xl mx-auto px-6">
<div class="text-center mb-12">
<h2 class="text-3xl font-bold mb-4 text-slate-800">Tidal Ellipse Theory</h2>
<p class="text-xl text-slate-600">Mathematical foundations and harmonic analysis principles</p>
</div>
<div class="grid lg:grid-cols-2 gap-8">
<div class="bg-white rounded-2xl p-6 shadow-lg">
<h3 class="text-2xl font-bold mb-4 text-slate-800">Harmonic Analysis</h3>
<div class="space-y-4 text-slate-600">
<p>Tidal currents are decomposed into harmonic constituents:</p>
<div class="bg-slate-50 p-4 rounded-lg font-mono text-sm">
u(t) = Σ [Aᵢ cos(ωᵢt + φᵢ)]<br>
v(t) = Σ [Bᵢ cos(ωᵢt + ψᵢ)]
</div>
<p>Where:</p>
<ul class="list-disc list-inside space-y-1 text-sm">
<li>ωᵢ = angular frequency of constituent i</li>
<li>Aᵢ, Bᵢ = amplitudes in u, v directions</li>
<li>φᵢ, ψᵢ = phase lags</li>
</ul>
</div>
</div>
<div class="bg-white rounded-2xl p-6 shadow-lg">
<h3 class="text-2xl font-bold mb-4 text-slate-800">Ellipse Parameters</h3>
<div class="space-y-4 text-slate-600">
<p>From complex representation w = u + iv:</p>
<div class="bg-slate-50 p-4 rounded-lg font-mono text-sm">
w = W⁺e^(iωt) + W⁻e^(-iωt)
</div>
<p>Ellipse parameters:</p>
<div class="bg-slate-50 p-4 rounded-lg font-mono text-sm">
a = |W⁺| + |W⁻| (semi-major)<br>
b = ||W⁺| - |W⁻|| (semi-minor)<br>
θ = ½arg(W⁺W⁻*) (inclination)<br>
φ = arg(W⁺) (phase)
</div>
</div>
</div>
<div class="bg-white rounded-2xl p-6 shadow-lg">
<h3 class="text-2xl font-bold mb-4 text-slate-800">Nodal Corrections</h3>
<div class="space-y-4 text-slate-600">
<p>Account for 18.6-year lunar nodal cycle:</p>
<div class="bg-slate-50 p-4 rounded-lg font-mono text-sm">
A'ᵢ = fᵢ × Aᵢ<br>
φ'ᵢ = φᵢ + uᵢ
</div>
<p>Where fᵢ and uᵢ are nodal amplitude and phase corrections.</p>
<p>Critical for long-term predictions and accurate constituent separation.</p>
</div>
</div>
<div class="bg-white rounded-2xl p-6 shadow-lg">
<h3 class="text-2xl font-bold mb-4 text-slate-800">Applications</h3>
<div class="space-y-3 text-slate-600">
<div class="border-l-4 border-blue-500 pl-4">
<h4 class="font-semibold">Navigation</h4>
<p class="text-sm">Current predictions for safe passage planning</p>
</div>
<div class="border-l-4 border-green-500 pl-4">
<h4 class="font-semibold">Engineering</h4>
<p class="text-sm">Design loads for offshore structures</p>
</div>
<div class="border-l-4 border-purple-500 pl-4">
<h4 class="font-semibold">Oceanography</h4>
<p class="text-sm">Understanding tidal mixing and transport</p>
</div>
<div class="border-l-4 border-red-500 pl-4">
<h4 class="font-semibold">Climate</h4>
<p class="text-sm">Long-term tidal energy dissipation studies</p>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Footer -->
<footer class="bg-slate-900 text-white py-8">
<div class="max-w-6xl mx-auto px-6 text-center">
<p class="text-slate-400">
© 2024 Tidal Ellipse Analysis Tool. Advanced tidal harmonic analysis for oceanographic research.
</p>
</div>
</footer>
<script>
let currentInputMethod = 'manual';
let analysisResults = null;
// Tidal constituent definitions (frequency in cycles per hour)
const TIDAL_CONSTITUENTS = {
'M2': { freq: 1/12.4206012, name: 'Principal lunar semi-diurnal' },
'S2': { freq: 1/12.0000000, name: 'Principal solar semi-diurnal' },
'N2': { freq: 1/12.6583482, name: 'Lunar elliptic semi-diurnal' },
'K2': { freq: 1/11.9672348, name: 'Lunisolar semi-diurnal' },
'K1': { freq: 1/23.9344696, name: 'Lunar diurnal' },
'O1': { freq: 1/25.8193417, name: 'Lunar diurnal' },
'P1': { freq: 1/24.0658902, name: 'Solar diurnal' },
'Q1': { freq: 1/26.8683566, name: 'Larger lunar elliptic diurnal' }
};
// Smooth scrolling
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
function setInputMethod(method) {
currentInputMethod = method;
// Update button styles
document.querySelectorAll('#manual-btn, #sample-btn, #synthetic-btn').forEach(btn => {
btn.classList.remove('bg-blue-600', 'bg-gray-600', 'bg-green-600');
btn.classList.add('bg-gray-400');
});
// Hide all input sections
document.getElementById('manual-input').classList.add('hidden');
document.getElementById('synthetic-input').classList.add('hidden');
if (method === 'manual') {
document.getElementById('manual-btn').classList.remove('bg-gray-400');
document.getElementById('manual-btn').classList.add('bg-blue-600');
document.getElementById('manual-input').classList.remove('hidden');
} else if (method === 'sample') {
document.getElementById('sample-btn').classList.remove('bg-gray-400');
document.getElementById('sample-btn').classList.add('bg-gray-600');
loadSampleData();
} else if (method === 'synthetic') {
document.getElementById('synthetic-btn').classList.remove('bg-gray-400');
document.getElementById('synthetic-btn').classList.add('bg-green-600');
document.getElementById('synthetic-input').classList.remove('hidden');
}
}
function loadSampleData() {
// Generate realistic tidal data for a coastal location
const dt = 0.5; // 30 minutes
const duration = 15 * 24; // 15 days in hours
const time = [];
const u = [];
const v = [];
for (let t = 0; t < duration; t += dt) {
time.push(t);
// M2 constituent (dominant)
const omega_m2 = 2 * Math.PI * TIDAL_CONSTITUENTS.M2.freq;
const u_m2 = 1.2 * Math.cos(omega_m2 * t + Math.PI/6);
const v_m2 = 0.8 * Math.cos(omega_m2 * t + Math.PI/3);
// S2 constituent
const omega_s2 = 2 * Math.PI * TIDAL_CONSTITUENTS.S2.freq;
const u_s2 = 0.4 * Math.cos(omega_s2 * t + Math.PI/4);
const v_s2 = 0.3 * Math.cos(omega_s2 * t + Math.PI/2);
// N2 constituent
const omega_n2 = 2 * Math.PI * TIDAL_CONSTITUENTS.N2.freq;
const u_n2 = 0.2 * Math.cos(omega_n2 * t);
const v_n2 = 0.15 * Math.cos(omega_n2 * t + Math.PI/6);
// K1 constituent
const omega_k1 = 2 * Math.PI * TIDAL_CONSTITUENTS.K1.freq;
const u_k1 = 0.3 * Math.cos(omega_k1 * t + Math.PI/3);
const v_k1 = 0.25 * Math.cos(omega_k1 * t + Math.PI/4);
// Add noise
const noise_u = (Math.random() - 0.5) * 0.05;
const noise_v = (Math.random() - 0.5) * 0.05;
u.push(u_m2 + u_s2 + u_n2 + u_k1 + noise_u);
v.push(v_m2 + v_s2 + v_n2 + v_k1 + noise_v);
}
document.getElementById('time-data').value = time.slice(0, 50).map(t => t.toFixed(1)).join(', ') + ', ...';
document.getElementById('u-data').value = u.slice(0, 50).map(val => val.toFixed(3)).join(', ') + ', ...';
document.getElementById('v-data').value = v.slice(0, 50).map(val => val.toFixed(3)).join(', ') + ', ...';
// Store full data for analysis
window.sampleData = { time, u, v };
}
function generateSyntheticData() {
const m2_amp = parseFloat(document.getElementById('m2-amp').value);
const m2_phase = parseFloat(document.getElementById('m2-phase').value) * Math.PI / 180;
const m2_incl = parseFloat(document.getElementById('m2-incl').value) * Math.PI / 180;
const s2_amp = parseFloat(document.getElementById('s2-amp').value);
const s2_phase = parseFloat(document.getElementById('s2-phase').value) * Math.PI / 180;
const s2_incl = parseFloat(document.getElementById('s2-incl').value) * Math.PI / 180;
const duration_days = parseFloat(document.getElementById('duration').value);
const dt = parseFloat(document.getElementById('sampling').value);
const duration = duration_days * 24; // hours
const time = [];
const u = [];
const v = [];
for (let t = 0; t < duration; t += dt) {
time.push(t);
// M2 component with elliptical motion
const omega_m2 = 2 * Math.PI * TIDAL_CONSTITUENTS.M2.freq;
const u_m2 = m2_amp * Math.cos(omega_m2 * t + m2_phase) * Math.cos(m2_incl) -
m2_amp * 0.6 * Math.sin(omega_m2 * t + m2_phase) * Math.sin(m2_incl);
const v_m2 = m2_amp * Math.cos(omega_m2 * t + m2_phase) * Math.sin(m2_incl) +
m2_amp * 0.6 * Math.sin(omega_m2 * t + m2_phase) * Math.cos(m2_incl);
// S2 component with elliptical motion
const omega_s2 = 2 * Math.PI * TIDAL_CONSTITUENTS.S2.freq;
const u_s2 = s2_amp * Math.cos(omega_s2 * t + s2_phase) * Math.cos(s2_incl) -
s2_amp * 0.7 * Math.sin(omega_s2 * t + s2_phase) * Math.sin(s2_incl);
const v_s2 = s2_amp * Math.cos(omega_s2 * t + s2_phase) * Math.sin(s2_incl) +
s2_amp * 0.7 * Math.sin(omega_s2 * t + s2_phase) * Math.cos(s2_incl);
u.push(u_m2 + u_s2);
v.push(v_m2 + v_s2);
}
document.getElementById('time-data').value = time.map(t => t.toFixed(2)).join(', ');
document.getElementById('u-data').value = u.map(val => val.toFixed(4)).join(', ');
document.getElementById('v-data').value = v.map(val => val.toFixed(4)).join(', ');
}
function parseData() {
// Check if we have sample data stored
if (window.sampleData && currentInputMethod === 'sample') {
return window.sampleData;
}
const timeStr = document.getElementById('time-data').value;
const uStr = document.getElementById('u-data').value;
const vStr = document.getElementById('v-data').value;
if (!timeStr || !uStr || !vStr) {
alert('Please enter data for all three fields (time, u, v)');
return null;
}
try {
// Handle truncated display data
const timeData = timeStr.includes('...') ?
timeStr.replace(', ...', '').split(',').map(s => parseFloat(s.trim())) :
timeStr.split(',').map(s => parseFloat(s.trim()));
const uData = uStr.includes('...') ?
uStr.replace(', ...', '').split(',').map(s => parseFloat(s.trim())) :
uStr.split(',').map(s => parseFloat(s.trim()));
const vData = vStr.includes('...') ?
vStr.replace(', ...', '').split(',').map(s => parseFloat(s.trim())) :
vStr.split(',').map(s => parseFloat(s.trim()));
if (timeData.some(isNaN) || uData.some(isNaN) || vData.some(isNaN)) {
alert('All values must be valid numbers');
return null;
}
if (timeData.length !== uData.length || timeData.length !== vData.length) {
alert('Time, U, and V arrays must have the same length');
return null;
}
return { time: timeData, u: uData, v: vData };
} catch (error) {
alert('Error parsing data. Please check your input format.');
return null;
}
}
function performHarmonicAnalysis(time, u, v, constituents) {
const n = time.length;
const dt = time[1] - time[0]; // hours
const results = {};
// For each constituent, perform least squares fit
for (const [name, info] of Object.entries(constituents)) {
const omega = 2 * Math.PI * info.freq; // rad/hour
// Design matrix for u = A*cos(wt) + B*sin(wt)
const A_u = [];
const A_v = [];
for (let i = 0; i < n; i++) {
const t = time[i];
A_u.push([Math.cos(omega * t), Math.sin(omega * t)]);
A_v.push([Math.cos(omega * t), Math.sin(omega * t)]);
}
// Solve normal equations: (A^T A) x = A^T b
const AtA = [[0, 0], [0, 0]];
const Atb_u = [0, 0];
const Atb_v = [0, 0];
for (let i = 0; i < n; i++) {
const cos_wt = A_u[i][0];
const sin_wt = A_u[i][1];
AtA[0][0] += cos_wt * cos_wt;
AtA[0][1] += cos_wt * sin_wt;
AtA[1][0] += sin_wt * cos_wt;
AtA[1][1] += sin_wt * sin_wt;
Atb_u[0] += cos_wt * u[i];
Atb_u[1] += sin_wt * u[i];
Atb_v[0] += cos_wt * v[i];
Atb_v[1] += sin_wt * v[i];
}
// Solve 2x2 system
const det = AtA[0][0] * AtA[1][1] - AtA[0][1] * AtA[1][0];
if (Math.abs(det) < 1e-10) continue;
const inv_det = 1.0 / det;
const A_cos_u = inv_det * (AtA[1][1] * Atb_u[0] - AtA[0][1] * Atb_u[1]);
const A_sin_u = inv_det * (-AtA[1][0] * Atb_u[0] + AtA[0][0] * Atb_u[1]);
const A_cos_v = inv_det * (AtA[1][1] * Atb_v[0] - AtA[0][1] * Atb_v[1]);
const A_sin_v = inv_det * (-AtA[1][0] * Atb_v[0] + AtA[0][0] * Atb_v[1]);
// Convert to amplitude and phase
const amp_u = Math.sqrt(A_cos_u * A_cos_u + A_sin_u * A_sin_u);
const phase_u = Math.atan2(-A_sin_u, A_cos_u) * 180 / Math.PI;
const amp_v = Math.sqrt(A_cos_v * A_cos_v + A_sin_v * A_sin_v);
const phase_v = Math.atan2(-A_sin_v, A_cos_v) * 180 / Math.PI;
// Calculate ellipse parameters
const W_plus = math.complex((A_cos_u + A_sin_v) / 2, (A_sin_u - A_cos_v) / 2);
const W_minus = math.complex((A_cos_u - A_sin_v) / 2, (A_sin_u + A_cos_v) / 2);
const W_plus_mag = math.abs(W_plus);
const W_minus_mag = math.abs(W_minus);
const semi_major = W_plus_mag + W_minus_mag;
const semi_minor = Math.abs(W_plus_mag - W_minus_mag);
const eccentricity = semi_minor / semi_major;
// Inclination and phase
const inclination = 0.5 * math.arg(math.multiply(W_plus, math.conj(W_minus))) * 180 / Math.PI;
const phase = math.arg(W_plus) * 180 / Math.PI;
// Sense of rotation
const sense = W_plus_mag > W_minus_mag ? 'Counterclockwise' : 'Clockwise';
results[name] = {
amp_u: amp_u,
phase_u: phase_u,
amp_v: amp_v,
phase_v: phase_v,
semi_major: semi_major,
semi_minor: semi_minor,
eccentricity: eccentricity,
inclination: inclination,
phase: phase,
sense: sense,
W_plus: W_plus,
W_minus: W_minus,
frequency: info.freq,
period: 1 / info.freq,
description: info.name
};
}
return results;
}
function calculateModelFit(time, u, v, results) {
const n = time.length;
const u_model = new Array(n).fill(0);
const v_model = new Array(n).fill(0);
for (const [name, params] of Object.entries(results)) {
const omega = 2 * Math.PI * params.frequency;
for (let i = 0; i < n; i++) {
const t = time[i];
u_model[i] += params.amp_u * Math.cos(omega * t + params.phase_u * Math.PI / 180);
v_model[i] += params.amp_v * Math.cos(omega * t + params.phase_v * Math.PI / 180);
}
}
// Calculate residuals and statistics
const u_residual = u.map((val, i) => val - u_model[i]);
const v_residual = v.map((val, i) => val - v_model[i]);
const u_var = u.reduce((sum, val) => sum + val * val, 0) / n;
const v_var = v.reduce((sum, val) => sum + val * val, 0) / n;
const u_res_var = u_residual.reduce((sum, val) => sum + val * val, 0) / n;
const v_res_var = v_residual.reduce((sum, val) => sum + val * val, 0) / n;
const r2_u = 1 - u_res_var / u_var;
const r2_v = 1 - v_res_var / v_var;
const rmse_u = Math.sqrt(u_res_var);
const rmse_v = Math.sqrt(v_res_var);
return {
u_model: u_model,
v_model: v_model,
u_residual: u_residual,
v_residual: v_residual,
r2_u: r2_u,
r2_v: r2_v,
rmse_u: rmse_u,
rmse_v: rmse_v
};
}
function performTidalAnalysis() {
const data = parseData();
if (!data) return;
const latitude = parseFloat(document.getElementById('latitude').value);
const longitude = parseFloat(document.getElementById('longitude').value);
const constituentsChoice = document.getElementById('constituents').value;
// Select constituents based on choice
let selectedConstituents = {};
if (constituentsChoice === 'major') {
selectedConstituents = {
'M2': TIDAL_CONSTITUENTS.M2,
'S2': TIDAL_CONSTITUENTS.S2,
'N2': TIDAL_CONSTITUENTS.N2,
'K1': TIDAL_CONSTITUENTS.K1,
'O1': TIDAL_CONSTITUENTS.O1
};
} else {
selectedConstituents = TIDAL_CONSTITUENTS;
}
// Perform harmonic analysis
const harmonicResults = performHarmonicAnalysis(data.time, data.u, data.v, selectedConstituents);
const modelFit = calculateModelFit(data.time, data.u, data.v, harmonicResults);
analysisResults = {
data: data,
harmonic: harmonicResults,
model: modelFit,
location: { latitude: latitude, longitude: longitude }
};
// Show results container
document.getElementById('results-container').classList.remove('hidden');
document.getElementById('no-results').classList.add('hidden');
// Generate all plots and tables
plotTimeSeries(data);
plotHodograph(data);
plotTidalEllipses(harmonicResults);
plotModelComparison(data, modelFit);
plotResidualAnalysis(modelFit);
generateParametersTable(harmonicResults);
generateEllipseProperties(harmonicResults);
generateSummaryStatistics(harmonicResults, modelFit, { latitude, longitude });
// Scroll to results
document.getElementById('analysis').scrollIntoView({ behavior: 'smooth' });
}
function plotTimeSeries(data) {
const uTrace = {
x: data.time,
y: data.u,
mode: 'lines',
name: 'U Component (East)',
line: { color: '#3b82f6', width: 2 }
};
const vTrace = {
x: data.time,
y: data.v,
mode: 'lines',
name: 'V Component (North)',
line: { color: '#10b981', width: 2 }
};
Plotly.newPlot('timeseries-plot', [uTrace, vTrace], {
title: 'Tidal Velocity Components',
xaxis: { title: 'Time (hours)' },
yaxis: { title: 'Velocity (m/s)' },
showlegend: true,
margin: { t: 40, r: 20, b: 40, l: 50 }
});
}
function plotHodograph(data) {
const hodographTrace = {
x: data.u,
y: data.v,
mode: 'lines+markers',
name: 'Current Vector',
line: { color: '#8b5cf6', width: 2 },
marker: {
color: data.time,
colorscale: 'Viridis',
size: 3,
showscale: true,
colorbar: { title: 'Time (h)', len: 0.7 }
}
};
Plotly.newPlot('hodograph-plot', [hodographTrace], {
title: 'Current Hodograph',
xaxis: { title: 'U Velocity (m/s)' },
yaxis: { title: 'V Velocity (m/s)' },
showlegend: false,
margin: { t: 40, r: 20, b: 40, l: 50 }
});
}
function plotTidalEllipses(results) {
const traces = [];
const colors = ['#3b82f6', '#ef4444', '#10b981', '#f59e0b', '#8b5cf6', '#06b6d4', '#84cc16', '#f97316'];
let colorIndex = 0;
// Sort constituents by amplitude for better visualization
const sortedConstituents = Object.entries(results).sort((a, b) => b[1].semi_major - a[1].semi_major);
for (const [name, params] of sortedConstituents) {
if (params.semi_major < 0.01) continue; // Skip very small constituents
// Generate ellipse points
const nPoints = 100;
const theta = [];
const x = [];
const y = [];
for (let i = 0; i <= nPoints; i++) {
const t = 2 * Math.PI * i / nPoints;
theta.push(t);
// Ellipse in standard position
const x_std = params.semi_major * Math.cos(t);
const y_std = params.semi_minor * Math.sin(t);
// Rotate by inclination angle
const incl_rad = params.inclination * Math.PI / 180;
const x_rot = x_std * Math.cos(incl_rad) - y_std * Math.sin(incl_rad);
const y_rot = x_std * Math.sin(incl_rad) + y_std * Math.cos(incl_rad);
x.push(x_rot);
y.push(y_rot);
}
const ellipseTrace = {
x: x,
y: y,
mode: 'lines',
name: `${name} (T=${params.period.toFixed(1)}h)`,
line: { color: colors[colorIndex % colors.length], width: 3 }
};
traces.push(ellipseTrace);
colorIndex++;
}
Plotly.newPlot('ellipses-plot', traces, {
title: 'Tidal Current Ellipses',
xaxis: { title: 'East Velocity (m/s)' },
yaxis: { title: 'North Velocity (m/s)' },
showlegend: true,
margin: { t: 40, r: 20, b: 40, l: 50 }
});
}
function plotModelComparison(data, modelFit) {
const uObsTrace = {
x: data.time,
y: data.u,
mode: 'lines',
name: 'U Observed',
line: { color: '#3b82f6', width: 2 }
};
const uModelTrace = {
x: data.time,
y: modelFit.u_model,
mode: 'lines',
name: 'U Model',
line: { color: '#ef4444', width: 2, dash: 'dash' }
};
const vObsTrace = {
x: data.time,
y: data.v,
mode: 'lines',
name: 'V Observed',
line: { color: '#10b981', width: 2 }
};
const vModelTrace = {
x: data.time,
y: modelFit.v_model,
mode: 'lines',
name: 'V Model',
line: { color: '#f59e0b', width: 2, dash: 'dash' }
};
Plotly.newPlot('model-comparison-plot', [uObsTrace, uModelTrace, vObsTrace, vModelTrace], {
title: 'Model vs Observations',
xaxis: { title: 'Time (hours)' },
yaxis: { title: 'Velocity (m/s)' },
showlegend: true,
margin: { t: 40, r: 20, b: 40, l: 50 }
});
}
function plotResidualAnalysis(modelFit) {
const uResTrace = {
x: Array.from({length: modelFit.u_residual.length}, (_, i) => i),
y: modelFit.u_residual,
mode: 'lines+markers',
name: 'U Residual',
line: { color: '#3b82f6', width: 1 },
marker: { size: 3 }
};
const vResTrace = {
x: Array.from({length: modelFit.v_residual.length}, (_, i) => i),
y: modelFit.v_residual,
mode: 'lines+markers',
name: 'V Residual',
line: { color: '#10b981', width: 1 },
marker: { size: 3 }
};
Plotly.newPlot('residual-plot', [uResTrace, vResTrace], {
title: 'Model Residuals',
xaxis: { title: 'Data Point' },
yaxis: { title: 'Residual (m/s)' },