-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
1359 lines (1142 loc) · 44.9 KB
/
index.html
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>
<head>
<meta charset="UTF-8">
<title>Rover Pics</title>
<style>
body {
background-color: #555;
color: #eeeeee;
font-family: monospace;
}
div {
//border-style: solid;
//border-color: yellow;
//margin: 1px;
}
button {
width: 18ch;
font-weight: bold;
}
.checkbox_div {
white-space: nowrap;
text-align: left
}
table, td, th {
color: #0b0b0b;
border: 1px solid #999;
}
td {
background-color: #eae6e0
}
th {
vertical-align: text-top;
background-color: #dcb
}
table {
width: 100%;
border-collapse: collapse;
}
h3 {
text-decoration: underline;
}
#loading {
float: none;
display: none;
width: 30px;
height: 30px;
margin-left: 20px;
border: 8px solid rgba(255,255,255,.2);
border-radius: 50%;
border-top-color: #ccbbaa;
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 0px 20px 0px 20px;
border: 1px solid #888;
width: 80%;
color: #321;
}
.modal_close_button {
color: #666;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
gray { color: #999 }
strong {
font-weight: bold;
text-decoration: underline;
}
.collapse {
width: fit-content;
display: inline-block;
padding-left: 2px;
padding-right: 2px;
}
.imgcontainer:hover .imgoverlay {
opacity: 0.8;
overflow: scroll;
}
.imgcontainer {
position: relative;
overflow: hidden;
}
.imgoverlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #eae6e0
}
pre {
font-size: 75%;
margin-top: 0px;
}
</style>
</head>
<body onload="pageSetup()">
<!-- INFO -->
<div id="info_modal" class="modal">
<div class="modal-content">
<div style="display: inline-block">
<h1>Rover Pics</h1>
<p> R. Kinnett, 2021. </p>
</div>
<div style="float: right">
<span id="modal_close_button" class="modal_close_button" onclick='closeModal()'>×</span>
</div>
<hr/>
<p>
Also see NASA's <a href="https://mars.nasa.gov/msl/multimedia/raw-images/">MSL</a> and <a href="https://mars.nasa.gov/mars2020/multimedia/raw-images/">Mars 2020</a> raw image sites.
<br/><br/>
This interface retrieves image information lists via <a href="https://mars.nasa.gov/rss/">JPL's RSS API</a> and builds a table showing thumbnails and basic metadata for each image, along with links to the maximum available resolution images. This page retrieves all available full-frame and subframe still and movie frames and displays all inline.
<br/>
<span style="color: orange">Note:</span> JPL's RSS API (and this page, consequentially) returns incomplete results from MSL.
<br/>
<ol>
<li> Start by selecting either Perseverance, Ingenuity, or Curiosity in the upper left. Then, <i>either</i>:
<ul>
<li>click "Latest 25 images" to retrieve the latest <i>downlinked</i> images,</li>
<li><i>or</i> click "Current Sol" to retrieve images (if available) for the current sol,</li>
<li>or enter a specific sol number and click Go, or click Prev/Next to increment/decrement sol number and retrieve images, if available.</li>
</ul>
</li>
<li> After retrieving image information and thumbnails, the user may:
<ul>
<li>
Export a JSON file containing all info retrieved from JPL,
</li>
<li>
Use checkboxes under the Camera and Type headings to narrow the table to specific images of interest, then use a browser extension to download all full-frame (or largest available) images remaining in the table via the provided links.
<ul>
<li>
Try <a href="https://www.downthemall.net/">DownThemAll!</a> for Chrome, Firefox or Opera
</li>
</ul>
</li>
<li>
Down-select further via checkboxes in the Select column and click "Export selected image URLs" to save a text file containing URLs to the full-frame (or max available) images which can be used in conjunction with command-line tools such as wget and curl.
</li>
</ul>
</li>
</ol>
Also try URL parameters! Examples:
<br/> <a href="##PAGE_ADDR##?msl">##PAGE_ADDR##?msl</a>
<br/> <a href="##PAGE_ADDR##?mars2020">##PAGE_ADDR##?mars2020</a>
<br/> <a href="##PAGE_ADDR##?mars2020&latest">##PAGE_ADDR##?mars2020&latest</a>
<br/> <a href="##PAGE_ADDR##?ingenuity&latest">##PAGE_ADDR##?ingenuity&latest</a>
<br/> <a href="##PAGE_ADDR##?msl&sol3000">##PAGE_ADDR##?msl&sol3000</a>
<br/> <a href="##PAGE_ADDR##?msl&sol3000&camera=HAZ">##PAGE_ADDR##?msl&sol3000&camera=haz</a> <gray>(fetches hazcam images)</gray>
<br/> <a href="##PAGE_ADDR##?msl&sol3052&filter=rhaz00311">##PAGE_ADDR##?msl&sol3052&filter=rhaz00311</a> <gray>(fetches images from specific sequence)</gray>
<br/> <a href="##PAGE_ADDR##?mars2020&sol0&filter=EDL">##PAGE_ADDR##?mars2020&sol0&filter=EDL</a> <gray>(fetches specific image type)</gray>
<br/> <a href="##PAGE_ADDR##?mars2020&sol50&filter=ECV">##PAGE_ADDR##?mars2020&sol50&filter=ECV</a> <gray>(fetches movie frames)</gray>
<br/> <a href="##PAGE_ADDR##?mars2020&sol18&fullframe">##PAGE_ADDR##?mars2020&sol18&fullframe</a>
<br/> <a href="##PAGE_ADDR##?mars2020&latest&sort=date">##PAGE_ADDR##?mars2020&latest&sort=date</a>
<br/> <a href="##PAGE_ADDR##?mars2020&latest&sort=imageid">##PAGE_ADDR##?mars2020&latest&sort=imageid</a>
<br/> <a href="##PAGE_ADDR##?mars2020&latest&sort=camera">##PAGE_ADDR##?mars2020&latest&sort=camera</a>
<hr/>
Image credits are provided in the JSON file which can be exported via the Export Metadata button.<br/><br/>
Get the source code on <a href="https://github.com/rkinnett/rkinnett.github.io/tree/master/roverpics">github</a>.<br/>
<b>Comments and suggestions: </b> <a href="https://twitter.com/rover_18">twitter</a> or <a href="https://discord.gg/Eky6AhRSnj">discord</a>
</p>
</div>
</div>
<!-- TOP ROW -->
<div style="display:block">
<!-- TOP LEFT AREA -->
<div style="overflow: hidden; display: inline-block">
<div style="display: inline-block">
<div style="display: block; margin: 6px 0px"">
Mission:
<select name="selectMission" id="selectMission" onchange='setMission(selectMission.value)'>
<option value="mars2020" selected>Perseverance</option>
<option value="ingenuity">Ingenuity</option>
<option value="msl">Curiosity</option>
</select>
</div>
<div style="display:block; margin: 8px 0px">
Mission time: <span id="mission_clock"></span>
</div>
<div style="display: block; margin: 6px 0px"">
<button class="collapse" onclick="getLatest()">Latest 25 images</button>
<button class="collapse" onclick="getCurrentSol()">Current Sol</button>
</div>
<div style="display: block; margin: 6px 0px"">
<div style="display: inline-block">
<label for="textSol">Sol:</label>
<input type="text" id="textSol" name="textSol" style="width: 6ex; margin-right: 0px" value="SOL">
<button class="collapse" onclick="getSol(textSol.value);" style="margin-left: -6px">Go</button>
</div>
<div style="display: inline-block; margin: 0px 10px">
<button class="collapse" onclick="prevSol()">Prev</button>
<button class="collapse" onclick="nextSol()">Next</button>
</div>
</div>
</div>
<div style="display:inline-block; float: right">
<div id="loading" style="display: none"></div>
</div>
</div>
<!-- TOP RIGHT AREA -->
<div style="float:right">
<div style="display: block; padding: 5px">
<button onclick='openModal()'>INFO</button>
</div>
<div style="display: block; padding: 5px">
<button onclick="exportJson()">Export Metadata</button>
</div>
<div style="display: block; padding: 5px">
<button onclick="exportImageURLs()">Export selected image URLs</button>
</div>
</div>
</div>
<div style="display:block; margin: 8px 0px">
<span id="summary">Empty</span>
<span id="image_count"/>
</div>
<table id="images_table">
<thead>
<tr>
<th> <h3 title="This is currently only used for exporting URLs to file">Select</h3>
<div>
<a onclick='selectImages("all")'>[all]</a>
<a onclick='selectImages("none")'>[none]</a>
</div>
<div>
<div class="checkbox_div">
<input type="checkbox" id="checkboxShowSelected" name="checkboxShowSelected" onchange="doFilter()" checked>
<label for="checkboxShowSelected">selected</label>
</div>
<div class="checkbox_div">
<input type="checkbox" id="checkboxShowUnselected" name="checkboxShowUnselected" onchange="doFilter()" checked>
<label for="checkboxShowUnselected">unselected</label>
</div>
</div>
</th>
<th> <h3>Thumbnail</h3> </th>
<th> <h3 onclick='sortTable("camera")'>Camera</h3>
<div>
<a onclick='selectCams("all")'>[all]</a>
<a onclick='selectCams("none")'>[none]</a>
</div>
<form id="cam_filter"></form>
</th>
<th> <h3 onclick='sortTable("frametype")'>Frame Type</h3> <form id="type_filter"></form> </th>
<th>
<h3 onclick='sortTable("imageid")'>Image ID</h3>
<div style="block">
<input type="text" id="imageIdFilterPattern" name="imageIdFilterPattern" value="Keyword" onclick='setImageIdFilter("")' style="color:lightgray ">
<input type="button" value="Filter" onclick="imageIdFilter()">
<input type="button" value="Clear" onclick="clearImageIdFilter()">
</div>
<span style="color:#777; font-size:90%">
(Examples: filter for a specific sequence ID, <br/>
or enter "ECV" to show only movie frames)
</span>
</th>
<th> <h3 onclick='sortTable("date")'>Date Taken</h3> </th>
</tr>
</thead>
<tbody id="table_body">
</tbody>
</table>
<canvas id="canv" style='display:"none"'></canvas>
<script>
var got_images = false;
var table = document.getElementById("images_table");
var spinner = document.getElementById("loading");
var cameras = [];
var camera_type_img_counts = [];
var image_types = [];
var image_type_img_counts = [];
var num_rows = 0;
var num_images = 0;
var image_list_json, images;
var checked_checkbox_names = [];
var imageNameFilter = "";
var mission = "mars2020";
var urlParams = {
mission: "",
sol: "",
camera: "",
filter: "",
frame: "",
latest: false,
sortfield: "",
sortdir: "ascending",
};
var missionFullName = {
msl: "MSL",
mars2020: "Mars 2020",
ingenuity: "Ingenuity",
};
const earthDaysPerMarsDay = 1.02749125;
// Get the modal
var modal = document.getElementById("info_modal");
function openModal(){
modal.style.display = "block";
}
function closeModal(){
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
// Handle enter key inside filter text box:
document.getElementById("imageIdFilterPattern").addEventListener("keyup", event => {
if(event.key == "Enter") {
imageIdFilter();
event.preventDefault();
}
});
// Handle enter key inside Sol text box:
document.getElementById("textSol").addEventListener("keyup", event => {
if(event.key == "Enter") {
sol = document.getElementById("textSol").value;
if(/^[0-9]+$/.test(sol)){
urlParams.sol = sol;
setThisPageUrlParams();
getSol(sol);
}
event.preventDefault();
}
});
////////// FUNCTION DEFINITIONS ///////////////
function pageSetup(){
// Replace page address placeholder in Info modal:
let page_address = window.location.origin + window.location.pathname;
var modal = document.getElementById("info_modal");
modal.innerHTML = modal.innerHTML.replaceAll("##PAGE_ADDR##",page_address);
lmst = currentMarsTime();
document.getElementById("textSol").value = lmst.sol;
parseUrl();
setMissionClock();
}
function parseUrl(){
let paramString = window.location.search.toLowerCase().split('?')[1];
if(!paramString) return;
console.log("parsing URL arguments...");
let queryString = new URLSearchParams(paramString);
for (let pair of queryString.entries()) {
key = pair[0];
val = pair[1];
console.log(key + (val.length>0? (": " + val) : "") );
if(key=="m" || key=="mission"){
console.log("MISSION");
if(val=="msl" || val=="curiosity"){
urlParams.mission = "msl";
setMission("msl");
} else if(val=="mars2020" || val=="m2020" || val=="perseverance"){
urlParams.mission = "mars2020"
setMission("mars2020");
} else if(val=="ingenuity"){
urlParams.mission = "ingenuity"
setMission("ingenuity");
} else {
console.log("unrecognized mission name: " + val);
return;
}
} else if(key=="msl" || key=="curiosity"){
urlParams.mission = "msl";
setMission("msl");
} else if(key=="mars2020" || key=="m2020" || key=="perseverance"){
urlParams.mission = "mars2020";
setMission("mars2020");
} else if(key=="ingenuity"){
urlParams.mission = "ingenuity";
setMission("ingenuity");
} else if(key=="latest"){
console.log("LATEST");
urlParams.sol = "latest";
} else if(key=="s" || key=="sol") {
console.log("SOL");
if((/^[0-9]+$/).test(val)){
urlParams.sol = val;
} else {
console.log("invalid sol string: " + val);
return;
}
} else if((/^sol[0-9]+$/).test(key)) {
console.log("SOL#");
urlParams.sol = key.replace("sol","");
} else if(key=="f" || key=="filt" || key=="filter") {
if( (/^[a-z0-9_]+$/).test(val) ){
val = val.toUpperCase();
console.log("Filter: " + val);
imageNameFilter = val;
setImageIdFilter(val);
urlParams.filter = val;
} else {
console.log("warning: invalid filter pattern specified in url parameters: " + val);
}
} else if(key=="c" || key=="cam" || key=="camera") {
if( val && (/^[a-z0-9_]+$/).test(val) ){
val = val.toUpperCase();
console.log("Camera: " + val);
urlParams.camera = val;
} else {
console.log('invalid camera descriptor "' + val + '"');
}
} else if(key=="full" || key=="fullframe") {
urlParams.frame = "full";
} else if(key=="sub" || key=="subframe") {
urlParams.frame = "subframe";
} else if(key=="thumb" || key=="thumbnail") {
urlParams.frame = "thumbnail";
} else if(/^sort(field)?$/.test(key) && /^(type)|(frame)|(camera)|(cam)|(name)|(id)|(imageid)|(date)|(datetaken)|(time)$/.test(val) ) {
console.log('Sort: "' + val + '"');
if(val=="type" || val=="frame") urlParams.sortfield = "frametype";
else if(val=="camera" || val=="cam") urlParams.sortfield = "camera";
else if(val=="name" || val=="id" || val=="imageid") urlParams.sortfield = "imageid";
else if(val=="date" || val=="datetaken" || val=="time") urlParams.sortfield = "date";
else console.log('unrecognized sort field: "' + val + '"');
} else if(/^(sortdir)|(sortdirection)|(dir)|(direction)?$/.test(key) && /^(ascending)|(descending)$/.test(val) ) {
console.log('Sort dir: "' + val + '"');
urlParams.sortdir = key;
} else {
console.log("unrecognized url parameter: " + key);
}
}
if(urlParams.mission=="msl" || urlParams.mission=="mars2020" || urlParams.mission=="ingenuity"){
if(urlParams.sol=="latest" /*|| urlParams.sol==""*/){
getLatest();
} else if( (/^[0-9]+$/).test(urlParams.sol)){
document.getElementById("textSol").value = urlParams.sol;
getSol(urlParams.sol);
} else {
console.log("URL params specified mission but not sol");
getLatest();
}
}
}
function setMission(missionName){
mission = missionName;
urlParams.mission = mission;
setThisPageUrlParams();
setMissionClock();
document.getElementById("selectMission").value = mission;
var textSolTextBox = document.getElementById("textSol");
//if(textSolTextBox.value=="SOL"){
var lmst = currentMarsTime();
textSolTextBox.value = lmst.sol;
//}
}
function setImageIdFilter(toString){
var keywordFilterTextbox = document.getElementById("imageIdFilterPattern");
keywordFilterTextbox.value = toString;
keywordFilterTextbox.style.color = "black";
}
function clearImageIdFilter(){
var keywordFilterTextbox = document.getElementById("imageIdFilterPattern");
keywordFilterTextbox.value="Keyword";
keywordFilterTextbox.style.color = "lightgray";
imageNameFilter = "";
urlParams.filter = "";
setThisPageUrlParams();
doFilter();
}
function imageIdFilter(){
var keywordFilterTextbox = document.getElementById("imageIdFilterPattern");
if(keywordFilterTextbox.value!=="Keyword") {
imageNameFilter = keywordFilterTextbox.value.toUpperCase();
console.log("Filter: " + imageNameFilter);
urlParams.filter = imageNameFilter;
setThisPageUrlParams();
doFilter();
}
}
function selectCams(allOrNone){
console.log("selecting " + allOrNone + " cameras");
var include = (allOrNone=="all")? true : false;
var camCheckboxes = table.tHead.rows[0].cells[2].querySelectorAll('input[type="checkbox"]');
console.log(camCheckboxes);
console.log(camCheckboxes.length);
for(var i=0; i<camCheckboxes.length; i++){
console.log(camCheckboxes[i]);
camCheckboxes[i].checked = include;
}
doFilter();
}
function selectImages(allOrNone){
console.log("selecting " + allOrNone + " images");
var include = (allOrNone=="all")? true : false;
for(var r=0; r<num_rows; r++){
table.tBodies[0].rows[r].cells[0].querySelector('input[type="checkbox"]').checked = include;
}
}
function getLatest(){
urlParams.sol = "latest";
setThisPageUrlParams(mission);
imageQuery(mission);
urlParams.mission = mission;
setThisPageUrlParams();
}
function getCurrentSol(){
lmst = currentMarsTime();
document.getElementById("textSol").value = lmst.sol;
getSol(lmst.sol);
}
function nextSol(){
sol = document.getElementById("textSol").value*1;
lmst = currentMarsTime();
if((/^[0-9]+$/).test(sol) && sol<lmst.sol){
sol+=1
document.getElementById("textSol").value = sol;
getSol(sol);
}
}
function prevSol(){
sol = document.getElementById("textSol").value*1;
if((/^[0-9]+$/).test(sol) && sol>0){
sol-=1;
document.getElementById("textSol").value = sol;
getSol(sol);
}
}
function getSol(sol){
if ( /^[0-9]+$/.test(sol)) {
document.getElementById("textSol").value = sol;
imageQuery(mission, sol);
urlParams.sol = sol;
urlParams.mission = mission;
setThisPageUrlParams();
} else {
console.log("not a number: " + sol);
}
}
function setThisPageUrlParams(){
var paramsCount = 0;
var paramString = "";
if(urlParams.mission!==""){
paramString += urlParams.mission;
paramsCount++;
}
if(urlParams.sol=="latest"){
if(paramsCount>0) paramString += "&";
paramString += "latest";
paramsCount++;
} else if(/^[0-9]+$/.test(urlParams.sol)){
if(paramsCount>0) paramString += "&";
paramString += "sol" + urlParams.sol;
paramsCount++;
}
if(urlParams.camera!==""){
if(paramsCount>0) paramString += "&";
paramString += "camera=" + urlParams.camera;
paramsCount++;
}
if(urlParams.frame!==""){
if(paramsCount>0) paramString += "&";
paramString += urlParams.frame;
paramsCount++;
}
if(urlParams.filter!==""){
if(paramsCount>0) paramString += "&";
paramString += "filter=" + urlParams.filter;
paramsCount++;
}
if(urlParams.sortfield!==""){
if(paramsCount>0) paramString += "&";
paramString += "sort=" + urlParams.sortfield;
paramsCount++;
}
console.log(urlParams);
console.log(paramsCount + " url params");
console.log("URL param string: " + paramString);
if(paramsCount>0){
this_page_url_base = location.protocol + '//' + location.host + location.pathname;
newUrl = this_page_url_base + "?" + paramString
console.log("Setting url to: " + newUrl);
window.history.pushState({}, null, newUrl);
}
}
/*
https://mars.nasa.gov/api/v1/raw_image_items/?
order=date_taken+desc
&per_page=100
&page=0
&condition_1=msl:mission
&condition_2=3294:sol:gte
&condition_3=3295:sol:lte
&extended=thumbnail::sample_type::noteq
https://mars.nasa.gov/rss/api/?
feed=raw_images
&category=mars2020,ingenuity
&feedtype=json
&ver=1.2
&num=100
&page=0
&&order=sol+desc&&&
*/
function imageQuery(mission, sol){
const images_per_page = 100; // 100 is API max
//const base_url = 'https://mars.nasa.gov/rss/api/?feed=raw_images&feedtype=json&category=' + mission;
const base_url = 'https://mars.nasa.gov/api/v1/raw_image_items/?' +
'order=date_taken+desc' +
'&per_page=' + images_per_page +
'&condition_1=' + mission + ':mission'
document.getElementById("summary").innerText = "Querying...";
clearTable();
document.getElementById("cam_filter").innerHTML = "";
document.getElementById("type_filter").innerHTML = "";
image_list_json = {};
// If sol was not specified, just do basic full-frame latest image query:
if(sol === undefined){
console.log("sol undefined.. performing standard query only");
getFullframeStillframes(base_url, function(){
tabulateImages();
});
return;
}
// Get full-frame still frames:
var rss_url = base_url + '&condition_2=' + sol + ':sol:gte' + '&condition_3=' + sol + ':sol:lte';
console.log("Getting full-frame still frames");
//getPaginatedFrames(rss_url + (mission=="mars2020" || mission=="ingenuity" ? '&extended=sample_type::full' : ''), function(){
getPaginatedFrames(rss_url + '&extended=thumbnail::sample_type::noteq', function(){
// Get thumbnail still frames:
console.log("Getting thumbnail still frames");
getPaginatedFrames(rss_url + '&extended=thumbnail::sample_type', function(){
if(mission=="mars2020"){
// Get full-frame movie frames:
console.log("Getting full-frame movie frames");
getPaginatedFrames(rss_url + '&extended=sample_type::full,product_id::ecv,', function(){
// Get thumbnail movie frames:
console.log("Getting subframe movie frames");
getPaginatedFrames(rss_url + '&extended=sample_type::thumbnail,product_id::ecv,', function(){
console.log("Completed query");
tabulateImages();
});
});
} else {
console.log("Completed query");
tabulateImages();
}
});
});
}
function getPaginatedFrames(url, callback){
const initial_image_count = (image_list_json && image_list_json.items) ? image_list_json.items.length : 0;
// Extended query to see if there are any video frames from this sol:
fetchJson(url + '&page=' + 0, function(extd_image_list_json){
console.log(extd_image_list_json);
if(!extd_image_list_json || !extd_image_list_json.total){
console.log("getPaginatedFrames: no images");
callback();
return;
}
// If first extended query indicates images are available, then get total count and calculate page count:
const num_pages = Math.ceil(extd_image_list_json.total / extd_image_list_json.per_page);
console.log("extended query indicates " + extd_image_list_json.total + " images available (" + num_pages + " pages)");
// Append images from the first page, one at a time, to master list
if(extd_image_list_json.items && extd_image_list_json.items.length>0 ){
if(!image_list_json || !image_list_json.items){
console.log("initializing image list");
image_list_json = extd_image_list_json;
got_images = true;
} else {
var this_page_img_count = 0;
extd_image_list_json.items.forEach(function(img){
image_list_json.items[initial_image_count + extd_image_list_json.page*extd_image_list_json.per_page + this_page_img_count] = img;
this_page_img_count++;
});
}
}
// If there are no frames, or just one page, then proceed to tabulation
if(num_pages<=1){
callback();
return;
}
// If there are more pages then loop through them:
var pages_loaded = 1;
for(var page=1; page<num_pages; page++){
fetchJson(url + '&page=' + page, function(extd_image_list_json){
console.log(extd_image_list_json);
// Append images, one at a time, to master list
if(extd_image_list_json.items && extd_image_list_json.items.length>0 ){
console.log("appending page-" + extd_image_list_json.page + " images (" + extd_image_list_json.items.length + ") to image list");
var this_page_img_count = 0;
extd_image_list_json.items.forEach(function(img){
image_list_json.items[initial_image_count + extd_image_list_json.page*extd_image_list_json.per_page + this_page_img_count] = img;
this_page_img_count++;
});
} else {
console.log("no images on page " + extd_image_list_json.page);
}
pages_loaded++;
if(pages_loaded>=num_pages){
console.log("finished paginated query");
console.log("extended query returned " + extd_image_list_json.total_results + ' images spanning ' + num_pages + ' pages');
callback();
}
});
}
});
}
function getFullframeStillframes(rss_url, callback){
fetchJson(rss_url, function(rxJson){
image_list_json = rxJson;
console.log(image_list_json);
if(!image_list_json || !image_list_json.items || !image_list_json.items.length) return;
got_images = true;
if(callback) callback();
});
}
function fetchJson(url, callback){
console.log("fetching rss feed: " + url);
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
console.log(this.responseText);
if(callback) {
callback(JSON.parse(this.responseText, null, '\t'));
}
} else {
console.log("unexpected response:");
console.log(JSON.stringify(this.responseText, null, '\t'));
alert("Error fetching requested feed. The server may be overloaded, or it's possible no images have been posted from the requested sol.");
}
}
};
xhr.withCredentials = false;
setBusyIndicator(true);
xhr.open("GET", url, true);
setTimeout(function(){ xhr.send(); }, 100);
}
function clearTable(){
document.getElementById("image_count").innerText = "";
// do this in reverse otherwise takes a lot of resources to rebuild bottom of table as top rows are deleted!
for (var r=table.tBodies[0].rows.length; r>0; r--) {
table.deleteRow(r);
}
num_rows = 0;
}
function tabulateImages(){
console.log(image_list_json);
cameras = [];
image_types = [];
camera_type_img_counts = [];
image_type_img_counts = [];
clearTable();
if(!image_list_json || !image_list_json.items){
console.log("tabulateImages: nothing to tabulate");
document.getElementById("summary").innerText = "Query returned 0 images.";
setBusyIndicator(false);
return;
}
images = image_list_json.items;
num_images = images.length;
start_sol = images[0].sol; // initial value; will check each image
end_sol = images[0].sol; // initial value; will check each image
console.log("tabulating " + num_images + " images");
for(n=0; n<num_images; n++){
//images[n].selected = false;
var type = images[n].extended.sample_type;
var camera = images[n].instrument;
//console.log('image ' + n + ', ' + camera + ', ' + type);
image_list_json.items[n].idx = n;
image_list_json.items[n].Azimuth = "" + ((calculateAz(images[n])*180/Math.PI +720) %360).toFixed(0) + " deg";
if(!cameras.includes(camera)) {
cameras.push(camera);
camera_type_img_counts[camera]=0;
}
if(!image_types.includes(type)) {
image_types.push(type);
image_type_img_counts[type]=0;
}
camera_type_img_counts[camera]++;
image_type_img_counts[type]++;
// Get sol range:
if(images[n].sol<start_sol) {
start_sol = images[n].sol;
}
if(images[n].sol>end_sol) {
end_sol = images[n].sol;
}
}
// Update summary:
document.getElementById("summary").innerText = 'Query returned ' + images.length + ' images from ' + missionFullName[image_list_json.mission] + ' sol ' + start_sol + ((end_sol>start_sol)?(' to sol ' + end_sol):'');
if( images.length==25 && urlParams.sol!=="latest" && start_sol*1<document.getElementById("textSol").value*1 ){
console.log("Query returned latest 25");
document.getElementById("summary").innerText += " (images may not be available for requested sol)";
}
console.log("Sol range: " + start_sol + " to " + end_sol);
console.log(camera_type_img_counts);
console.log(image_type_img_counts);
// Clear and repopulate filter checkboxes:
document.getElementById("cam_filter").innerHTML = "";
document.getElementById("type_filter").innerHTML = "";
cameras.forEach(function(cam_type){
var checked = (urlParams.camera=="" || new RegExp(urlParams.camera).test(cam_type) );
makeCheckbox("cam_filter", cam_type, checked);
});
image_types.forEach(function(img_type){
var checked = (urlParams.frame=="" || new RegExp(urlParams.frame).test(img_type.toLowerCase()) );
makeCheckbox("type_filter",img_type, checked);
});
setBusyIndicator(false);
buildTable();
}
function calculateAz(img){
var az;
//console.log(img);
if(!img || !img.instrument || !img.attitude || !/^\(/.test(img.attitude) ){
console.log("need camera info and rover attitude");
return null;
}
q = img.attitude.replace(/[\(\)]/mg,'').split(',').map(x=>+x);
roverAz = Math.atan2(2*(q[1]*q[2] + q[0]*q[3]), 2*(q[0]*q[0] + q[1]*q[1])-1);
// If camera vector is provided, then.. easy!
if(img.camera_vector && /^\(/.test(img.camera_vector)){
cameraVector = img.camera_vector.replace(/[\(\)]/mg,'').split(',').map(x=>+x);
az = Math.atan2(cameraVector[1], cameraVector[0]) + roverAz;