-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewer.html
More file actions
259 lines (201 loc) · 6.96 KB
/
viewer.html
File metadata and controls
259 lines (201 loc) · 6.96 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>H-alpha viewer</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 0;
padding: 20px;
background: linear-gradient(135deg, #0f0c1f 0%, #202b60 50%, #0f0c1f 100%);
min-height: 100vh;
color: #e0e0e0;
}
.container {
margin: 0 auto;
background: #1a1a2f;
border-radius: 20px;
padding: 10px;
box-shadow: 0 20px 60px rgba(0,0,0,0.5);
border: 1px solid rgba(255,255,255,0.1);
}
h1 {
text-align: center;
}
.main-content {
width: 60vw;
margin: 0 auto;
}
.image-container {
text-align: center;
}
.image {
width: 90%;
height: 90%;
object-fit: contain;
}
.center {
width: 100%;
text-align: center;
}
.search {
float: left;
}
.navigation {
float: right;
}
</style>
</head>
<body>
<div class="container">
<h1>Sacramento Peak H-alpha Dataset Viewer</h1>
<div class="main-content">
<h3>Upload a csv file with metadata</h3>
<input type="file" id="file-input" />
<div id="file-message"></div>
<div style="height: 5px;"></div>
<h3>Search image by date and time</h3>
<div class='search'>
<input type="date"
id="date-picker"
value="1966-03-13"
min="1966-01-01"
max="2002-12-31" />
<input type="time"
id="time-picker"
value="00:00:00" />
<button name="submit" onClick="handleSearch()">Search</button>
</div>
<div class='navigation'>
<button name="button-prev" onClick="handlePrev()">Prev</button>
<button name="button-next" onClick="handleNext()">Next</button>
</div>
<div style="height: 5px; clear: both"></div>
<div class='image-container'>
<div id="img-message" style="white-space: pre;"></div>
<img id='sun-image' class='image'>
</div>
<div class='center'>
<a href="" id='fits-link' target="_blank" download>
<button type="button">
Get FITS file
</button>
</a>
</div>
<div style="text-align: right;">Authors: E. Illarionov, A. Pevtsov. 2026.</div>
</div>
</div>
<script>
const linkTemplate = "https://nispdata.nso.edu/ftp/flare_patrol_h_alpha_sp/jpg/DIR/FILENAME.jpg"
const fitsTemplate = "https://nispdata.nso.edu/ftp/flare_patrol_h_alpha_sp/fts/DIR/FILENAME.fts.gz"
const fileInput = document.getElementById("file-input");
let fileNames = []
let fileDates = []
var filePos = null
function updateImg(filePos) {
const fname = fileNames[filePos]
const dir = Number(fname.split('_')[1])
const linkShow = linkTemplate.replace('FILENAME', fname).replace('DIR', dir)
const linkFits = fitsTemplate.replace('FILENAME', fname).replace('DIR', dir)
document.getElementById("sun-image").src=linkShow;
document.getElementById("fits-link").href=linkFits;
const name = fileNames[filePos]
const date = fileDates[filePos]
var text = ""
if (date !== null) {
const year = date.toLocaleString('default', { year: 'numeric' })
const month = date.toLocaleString('default', { month: 'short' })
const day = date.toLocaleString('default', { day: 'numeric' })
const time = date.toLocaleTimeString('default', { hour12: false})
text = `File: ${name} Date: ${day} ${month} ${year} Time: ${time}`
}
else {
text = `File: ${name} Date: Unknown Time: Unknown`
}
showMessage("img-message", text)
}
function handleNext() {
filePos = filePos == fileNames.length-1 ? fileNames.length-1 : filePos+1
updateImg(filePos)
}
function handlePrev() {
filePos = filePos == 0 ? 0 : filePos-1
updateImg(filePos)
}
function handleSearch() {
const findDate = new Date(document.querySelector('input[type="date"]').value);
const time = document.querySelector('input[type="time"]').value.split(":")
findDate.setHours(time[0])
findDate.setMinutes(time[1])
findDate.setSeconds(time[2])
var currDiff = 0;
var bestDiff = -(new Date(0,0,0)).valueOf();
for(i = 0; i < fileDates.length; ++i) {
if (fileDates[i] === null) { continue }
currDiff = Math.abs(fileDates[i] - findDate);
if (currDiff < bestDiff) {
filePos = i;
bestDiff = currDiff;
}
}
updateImg(filePos)
}
fileInput.addEventListener("change", handleFileSelection);
function strParser(row) {
const items = row.split(',')
if ( items.length < 2 ) { return }
const dateStart = 0
const year = items[1].slice(dateStart, dateStart+4)
const month = items[1].slice(dateStart+4,dateStart+6)
const day = items[1].slice(dateStart+6,dateStart+8)
const hour = items[1].slice(dateStart+9,dateStart+11)
const minutes = items[1].slice(dateStart+11,dateStart+13)
const seconds = items[1].slice(dateStart+13,dateStart+15)
const invalidDate = (year == '9999' || month == '99' || day == '99' ||
hour == '99' || minutes == '99' || seconds == '99')
const date = invalidDate ? null : new Date(year,
Number(month)-1, day, hour, minutes, seconds)
fileNames.push(items[0].split(".")[0])
fileDates.push(date)
}
function handleFileSelection(event) {
const file = event.target.files[0];
showMessage("file-message", "")
if (!file) {
showMessage("file-message", "No file selected. Please choose a file.", "error");
return;
}
if (file.name.split('.').pop().toLowerCase() !== 'csv') {
showMessage("file-message", "Unsupported file type. Please select a CSV file.", "error");
return;
}
showMessage("file-message", "Loading file, please wait...");
const reader = new FileReader();
reader.onload = () => {
const rows = reader.result.split('\n')
rows.shift()
fileNames = []
fileDates = []
rows.map(item => strParser(item))
const text = `File loaded. Total images: ${fileDates.length}. Complete dates: ${fileDates.filter(x => x !== null).length}`
showMessage("file-message", text);
filePos = fileDates.findIndex(x => x)
if (!filePos) { filePos = 0 }
updateImg(filePos)
};
reader.onerror = () => {
showMessage("file-message", "Error reading the file. Please try again.", "error");
};
reader.readAsText(file);
}
function showMessage(id, message, type) {
textField = document.getElementById(id)
textField.textContent = message;
if (type === "error") { textField.style.color = 'red'}
else { textField.style.color = '#e0e0e0'}
}
</script>
</body>
</html>