Newer
Older
{
"cells": [
{
"cell_type": "code",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/tthatcher/anaconda3/envs/autocnet/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
]
}
],
"source": [
"import os\n",
"import sys\n",
"from functools import singledispatch\n",
"import numpy as np\n",
"\n",
"sys.path.insert(0, \"/home/tthatcher/Desktop/Projects/Plio/plio\")\n",
"from plio.io.io_bae import read_gpf, read_ipf\n",
"import plio.io.io_controlnetwork as cn\n",
"import plio.io.isis_serial_number as sn"
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
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"HATS_File_Version_7\n",
"\n",
"PROJ_FLAG 1\n",
"\n",
"PROJECT D:\\data\\CTX_Athabasca_Middle.prj\n",
"\n",
"ATF_FILE CTX_Athabasca_Middle_step0.atf\n",
"\n",
"GP_FILE CTX_Athabasca_Middle.gpf\n",
"\n",
"STRAT_FILE apm.apm_strat\n",
"\n",
"SOLVE_STRAT_FILE default.solve\n",
"\n",
"DTM_FILE null\n",
"\n",
"GPS_INFO_FILE null\n",
"\n",
"INPUT_COV_FILE null\n",
"\n",
"TRI_CONSTRAINT_FILE null\n",
"\n",
"ADJ absolute\n",
"\n",
"NUM_IMGS 6\n",
"\n",
"STRIP_SEQ 0\n",
"\n",
"NUM_STRIPS 3\n",
"\n",
"STRIP_FLAG 1\n",
"\n",
"STRIP_FLAG 1\n",
"\n",
"STRIP_ID 1\n",
"\n",
"IMAGE_SEQ 0\n",
"\n",
"NUM_IMGS_STRIP 2\n",
"\n",
"STRIP_BEGIN 0 0 0 0.0 0.0\n",
"\n",
"STRIP_END 0 0 0 0.0 0.0\n",
"\n",
"STRIP_SCAN 1\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_ID 0\n",
"\n",
"IMAGE_SUP P19_008344_1894_XN_09N203W.sup\n",
"\n",
"IMAGE_IPF P19_008344_1894_XN_09N203W.ipf\n",
"\n",
"SENSOR GENERIC_PUSHBROOM\n",
"\n",
"INCLUDE_IN_SOLUTION 1\n",
"\n",
"IMG_DATA_1 60.0 0.0\n",
"\n",
"IMG_DATA_2 1000.0 0.0\n",
"\n",
"IMG_DATA_3 0.0 228.6\n",
"\n",
"DEFAULT_FLAG 1\n",
"\n",
"NUM_ADJ_PARMS 16\n",
"\n",
"ADJUST_&_SIGMA 0 100\n",
"\n",
"ADJUST_&_SIGMA 0 100\n",
"\n",
"ADJUST_&_SIGMA 0 10\n",
"\n",
"ADJUST_&_SIGMA 0 13\n",
"\n",
"ADJUST_&_SIGMA 0 13\n",
"\n",
"ADJUST_&_SIGMA 0 1.3\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.1\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0353\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_ID 1\n",
"\n",
"IMAGE_SUP P20_008845_1894_XN_09N203W.sup\n",
"\n",
"IMAGE_IPF P20_008845_1894_XN_09N203W.ipf\n",
"\n",
"SENSOR GENERIC_PUSHBROOM\n",
"\n",
"INCLUDE_IN_SOLUTION 1\n",
"\n",
"IMG_DATA_1 60.0 0.0\n",
"\n",
"IMG_DATA_2 1000.0 0.0\n",
"\n",
"IMG_DATA_3 0.0 228.6\n",
"\n",
"DEFAULT_FLAG 1\n",
"\n",
"NUM_ADJ_PARMS 16\n",
"\n",
"ADJUST_&_SIGMA 1 100\n",
"\n",
"ADJUST_&_SIGMA 1 100\n",
"\n",
"ADJUST_&_SIGMA 1 10\n",
"\n",
"ADJUST_&_SIGMA 1 13\n",
"\n",
"ADJUST_&_SIGMA 1 13\n",
"\n",
"ADJUST_&_SIGMA 1 1.3\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 1 0.1\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0353\n",
"\n",
"STRIP_FLAG 1\n",
"\n",
"STRIP_ID 2\n",
"\n",
"IMAGE_SEQ 0\n",
"\n",
"NUM_IMGS_STRIP 2\n",
"\n",
"STRIP_BEGIN 0 0 0 0.0 0.0\n",
"\n",
"STRIP_END 0 0 0 0.0 0.0\n",
"\n",
"STRIP_SCAN 1\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_ID 0\n",
"\n",
"IMAGE_SUP P03_002371_1888_XI_08N204W.sup\n",
"\n",
"IMAGE_IPF P03_002371_1888_XI_08N204W.ipf\n",
"\n",
"SENSOR GENERIC_PUSHBROOM\n",
"\n",
"INCLUDE_IN_SOLUTION 0\n",
"\n",
"IMG_DATA_1 60.0 0.0\n",
"\n",
"IMG_DATA_2 1000.0 0.0\n",
"\n",
"IMG_DATA_3 0.0 228.6\n",
"\n",
"DEFAULT_FLAG 1\n",
"\n",
"NUM_ADJ_PARMS 16\n",
"\n",
"ADJUST_&_SIGMA 0 100\n",
"\n",
"ADJUST_&_SIGMA 0 100\n",
"\n",
"ADJUST_&_SIGMA 0 10\n",
"\n",
"ADJUST_&_SIGMA 0 13\n",
"\n",
"ADJUST_&_SIGMA 0 13\n",
"\n",
"ADJUST_&_SIGMA 0 1.3\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.1\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0353\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_ID 1\n",
"\n",
"IMAGE_SUP P01_001540_1889_XI_08N204W.sup\n",
"\n",
"IMAGE_IPF P01_001540_1889_XI_08N204W.ipf\n",
"\n",
"SENSOR GENERIC_PUSHBROOM\n",
"\n",
"INCLUDE_IN_SOLUTION 0\n",
"\n",
"IMG_DATA_1 60.0 0.0\n",
"\n",
"IMG_DATA_2 1000.0 0.0\n",
"\n",
"IMG_DATA_3 0.0 228.6\n",
"\n",
"DEFAULT_FLAG 1\n",
"\n",
"NUM_ADJ_PARMS 16\n",
"\n",
"ADJUST_&_SIGMA 1 100\n",
"\n",
"ADJUST_&_SIGMA 1 100\n",
"\n",
"ADJUST_&_SIGMA 1 10\n",
"\n",
"ADJUST_&_SIGMA 1 13\n",
"\n",
"ADJUST_&_SIGMA 1 13\n",
"\n",
"ADJUST_&_SIGMA 1 1.3\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 1 0.1\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0353\n",
"\n",
"STRIP_FLAG 1\n",
"\n",
"STRIP_ID 3\n",
"\n",
"IMAGE_SEQ 0\n",
"\n",
"NUM_IMGS_STRIP 2\n",
"\n",
"STRIP_BEGIN 0 0 0 0.0 0.0\n",
"\n",
"STRIP_END 0 0 0 0.0 0.0\n",
"\n",
"STRIP_SCAN 1\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_ID 0\n",
"\n",
"IMAGE_SUP P01_001606_1897_XI_09N203W.sup\n",
"\n",
"IMAGE_IPF P01_001606_1897_XI_09N203W.ipf\n",
"\n",
"SENSOR GENERIC_PUSHBROOM\n",
"\n",
"INCLUDE_IN_SOLUTION 0\n",
"\n",
"IMG_DATA_1 60.0 0.0\n",
"\n",
"IMG_DATA_2 1000.0 0.0\n",
"\n",
"IMG_DATA_3 0.0 228.6\n",
"\n",
"DEFAULT_FLAG 1\n",
"\n",
"NUM_ADJ_PARMS 16\n",
"\n",
"ADJUST_&_SIGMA 0 100\n",
"\n",
"ADJUST_&_SIGMA 0 100\n",
"\n",
"ADJUST_&_SIGMA 0 10\n",
"\n",
"ADJUST_&_SIGMA 0 13\n",
"\n",
"ADJUST_&_SIGMA 0 13\n",
"\n",
"ADJUST_&_SIGMA 0 1.3\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.1\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0353\n",
"\n",
"IMAGE_FLAG 1\n",
"\n",
"IMAGE_ID 1\n",
"\n",
"IMAGE_SUP P03_002226_1895_XI_09N203W.sup\n",
"\n",
"IMAGE_IPF P03_002226_1895_XI_09N203W.ipf\n",
"\n",
"SENSOR GENERIC_PUSHBROOM\n",
"\n",
"INCLUDE_IN_SOLUTION 0\n",
"\n",
"IMG_DATA_1 60.0 0.0\n",
"\n",
"IMG_DATA_2 1000.0 0.0\n",
"\n",
"IMG_DATA_3 0.0 228.6\n",
"\n",
"DEFAULT_FLAG 1\n",
"\n",
"NUM_ADJ_PARMS 16\n",
"\n",
"ADJUST_&_SIGMA 1 100\n",
"\n",
"ADJUST_&_SIGMA 1 100\n",
"\n",
"ADJUST_&_SIGMA 1 10\n",
"\n",
"ADJUST_&_SIGMA 1 13\n",
"\n",
"ADJUST_&_SIGMA 1 13\n",
"\n",
"ADJUST_&_SIGMA 1 1.3\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 0 0.0173\n",
"\n",
"ADJUST_&_SIGMA 1 0.1\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0017\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0002\n",
"\n",
"ADJUST_&_SIGMA 0 0.0353\n",
"\n",
"TPP_FILE 3x3.tpp\n",
"\n",
"TRANS_TF_CTL_IMG 0\n",
"\n",
"UPDATE_ZERO_SIGMAS 0\n",
"\n",
"USE_DTM_FILE 0\n",
"\n",
"USE_GPS_FILE 0\n",
"\n",
"USE_INPUT_COV_FILE 0\n",
"\n",
"USE_TRI_CONSTRAINT_FILE 0\n",
"\n",
"PERCENT_REMOVED_POINTS 50\n",
"\n",
"{'IMAGE_IPF': [['IMAGE_IPF', 'P19_008344_1894_XN_09N203W.ipf'], ['IMAGE_IPF', 'P20_008845_1894_XN_09N203W.ipf'], ['IMAGE_IPF', 'P03_002371_1888_XI_08N204W.ipf'], ['IMAGE_IPF', 'P01_001540_1889_XI_08N204W.ipf'], ['IMAGE_IPF', 'P01_001606_1897_XI_09N203W.ipf'], ['IMAGE_IPF', 'P03_002226_1895_XI_09N203W.ipf']], 'IMAGE_SUP': [['IMAGE_SUP', 'P19_008344_1894_XN_09N203W.sup'], ['IMAGE_SUP', 'P20_008845_1894_XN_09N203W.sup'], ['IMAGE_SUP', 'P03_002371_1888_XI_08N204W.sup'], ['IMAGE_SUP', 'P01_001540_1889_XI_08N204W.sup'], ['IMAGE_SUP', 'P01_001606_1897_XI_09N203W.sup'], ['IMAGE_SUP', 'P03_002226_1895_XI_09N203W.sup']], 'PATH': '/home/tthatcher/Desktop/Projects/plio_imgs/quest_imgs'}\n"
]
}
],
"source": [
"from collections import defaultdict\n",
"\n",
"atf_file = ('/home/tthatcher/Desktop/Projects/plio_imgs/quest_imgs/CTX_Athabasca_Middle_step0.atf')\n",
"\n",
"with open(atf_file) as f:\n",
" \n",
" files_ext = ['.prj', '.sup', '.ipf']\n",
" files_dict = []\n",
" files = defaultdict(list)\n",
"\n",
" for line in f:\n",
" print(line)\n",
" ext = os.path.splitext(line)[-1]\n",
" \n",
" if ext in files_ext:\n",
" files[ext.strip()].append(line.strip().split(' '))\n",
" \n",
" \n",
" files['basepath'] = os.path.dirname(os.path.abspath(atf_file))\n",
" \n",
" # Creates a dict out of file lists for GPF, PRJ, IPF, and ATF\n",
" files_dict = (dict(files_dict))\n",
" \n",
" # Sets the value of IMAGE_IPF to all IPF images\n",
" files_dict['IMAGE_IPF'] = files['.ipf']\n",
" \n",
" # Sets the value of IMAGE_SUP to all SUP images\n",
" files_dict['IMAGE_SUP'] = files['.sup']\n",
" \n",
" # Sets the value of PATH to the path of the ATF file\n",
" files_dict['PATH'] = files['basepath']\n",
" \n",
"print(files_dict)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
"metadata": {},
"outputs": [],
"source": [
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
"# Reads a .atf file and outputs all of the \n",
"# .ipf, .gpf, .sup, .prj, and path to locate the \n",
"# .apf file (should be the same as all others) \n",
"def read_atf(atf_file):\n",
" with open(atf_file) as f:\n",
"\n",
" files = []\n",
" ipf = []\n",
" sup = []\n",
" files_dict = []\n",
" \n",
" # Grabs every PRJ, GPF, SUP, and IPF image from the ATF file\n",
" for line in f:\n",
" if line[-4:-1] == 'prj' or line[-4:-1] == 'gpf' or line[-4:-1] == 'sup' or line[-4:-1] == 'ipf' or line[-4:-1] == 'atf':\n",
" files.append(line)\n",
" \n",
" files = np.array(files)\n",
" \n",
" # Creates appropriate arrays for certain files in the right format\n",
" for file in files:\n",
" file = file.strip()\n",
" file = file.split(' ')\n",
"\n",
" # Grabs all the IPF files\n",
" if file[1].endswith('.ipf'):\n",
" ipf.append(file[1])\n",
"\n",
" # Grabs all the SUP files\n",
" if file[1].endswith('.sup'):\n",
" sup.append(file[1])\n",
"\n",
" files_dict.append(file)\n",
"\n",
" # Creates a dict out of file lists for GPF, PRJ, IPF, and ATF\n",
" files_dict = (dict(files_dict))\n",
" \n",
" # Sets the value of IMAGE_IPF to all IPF images\n",
" files_dict['IMAGE_IPF'] = ipf\n",
" \n",
" # Sets the value of IMAGE_SUP to all SUP images\n",
" files_dict['IMAGE_SUP'] = sup\n",
" \n",
" # Sets the value of PATH to the path of the ATF file\n",
" files_dict['PATH'] = os.path.dirname(os.path.abspath(atf_file))\n",
" \n",
"def line_sample_size(record, path):\n",
" with open(os.path.join(path, record['ipf_file'] + '.sup')) as f:\n",
" if i == 2:\n",
" img_index = line.split('\\\\')\n",
" img_index = img_index[-1].strip()\n",
" img_index = img_index.split('.')[0]\n",
" \n",
" line_size = line.split(' ')\n",
" line_size = line_size[-1].strip()\n",
" assert int(line_size) > 0, \"Line number {} from {} is a negative number: Invalid Data\".format(line_size, record['ipf_file'])\n",
" \n",
" if i == 4:\n",
" sample_size = line.split(' ')\n",
" sample_size = sample_size[-1].strip()\n",
" assert int(sample_size) > 0, \"Sample number {} from {} is a negative number: Invalid Data\".format(sample_size, record['ipf_file'])\n",
" \n",
" \n",
" line_size = int(line_size)/2.0 + record['l.'] + 1\n",
" sample_size = int(sample_size)/2.0 + record['s.'] + 1\n",
" \n",
"# converts known to ISIS keywords\n",
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
"def known(record):\n",
" if record['known'] == 0:\n",
" return 'Free'\n",
" \n",
" elif record['known'] == 1 or record['known'] == 2 or record['known'] == 3:\n",
" return 'Constrained'\n",
" \n",
"# converts +/- 180 system to 0 - 360 system\n",
"def to_360(num):\n",
" return num % 360\n",
"\n",
"# ocentric to ographic latitudes\n",
"def oc2og(dlat, dMajorRadius, dMinorRadius):\n",
" try: \n",
" dlat = math.radians(dlat)\n",
" dlat = math.atan(((dMajorRadius / dMinorRadius)**2) * (math.tan(dlat)))\n",
" dlat = math.degrees(dlat)\n",
" except:\n",
" print (\"Error in oc2og conversion\")\n",
" return dlat\n",
"\n",
"# ographic to ocentric latitudes\n",
"def og2oc(dlat, dMajorRadius, dMinorRadius):\n",
" try:\n",
" dlat = math.radians(dlat)\n",
" dlat = math.atan((math.tan(dlat) / ((dMajorRadius / dMinorRadius)**2)))\n",
" dlat = math.degrees(dlat)\n",
" except:\n",
" print (\"Error in og2oc conversion\")\n",
" return dlat\n",
"\n",
"# gets eRadius and pRadius from a .prj file\n",
"def get_axis(file):\n",
" from collections import defaultdict\n",
"\n",
" files = defaultdict(list)\n",
" \n",
" for line in f:\n",
" \n",
" ext = line.strip().split(' ')\n",
" files[ext[0]].append(ext[-1])\n",
" \n",
" eRadius = float(files['A_EARTH'][0])\n",
" pRadius = eRadius * (1 - float(files['E_EARTH'][0]))\n",
" \n",
" return eRadius, pRadius\n",
" \n",
"# function to convert lat_Y_North to ISIS_lat\n",
"def lat_ISIS_coord(record, semi_major, semi_minor):\n",
" ocentric_coord = og2oc(record['lat_Y_North'], semi_major, semi_minor)\n",
" coord_360 = to_360(ocentric_coord)\n",
" return coord_360\n",
"\n",
"# function to convert long_X_East to ISIS_lon\n",
"def lon_ISIS_coord(record, semi_major, semi_minor):\n",
" ocentric_coord = og2oc(record['long_X_East'], semi_major, semi_minor)\n",
" coord_360 = to_360(ocentric_coord)\n",
" return coord_360\n",
"def body_fix(record, semi_major, semi_minor, inverse=False):\n",
" \"\"\"\n",
" Parameters\n",
" ----------\n",
" record : ndarray\n",
" (n,3) where columns are x, y, height or lon, lat, alt\n",
" \"\"\"\n",
" \n",
" ecef = pyproj.Proj(proj='geocent', a=semi_major, b=semi_minor)\n",
" lla = pyproj.Proj(proj='latlon', a=semi_major, b=semi_minor)\n",
" if inverse:\n",
" lon, lat, height = pyproj.transform(ecef, lla, record[0], record[1], record[2])\n",
" return lon, lat, height\n",
" else:\n",
" y, x, z = pyproj.transform(lla, ecef, record[0], record[1], record[2])\n",
" return y, x, z\n",
"\n",
"def ignore_toggle(record):\n",
" if record['stat'] == 0:\n",
" return True\n",
" else:\n",
" return False\n",
"\n",
"# TODO: Does isis cnet need a convariance matrix for sigmas? Even with a static matrix of 1,1,1,1 \n",
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
"def compute_sigma_covariance_matrix(lat, lon, rad, latsigma, lonsigma, radsigma, semimajor_axis):\n",
" \n",
" \"\"\"\n",
" Given geospatial coordinates, desired accuracy sigmas, and an equitorial radius, compute a 2x3\n",
" sigma covariange matrix.\n",
" Parameters\n",
" ----------\n",
" lat : float\n",
" A point's latitude in degrees\n",
" lon : float\n",
" A point's longitude in degrees\n",
" rad : float\n",
" The radius (z-value) of the point in meters\n",
" latsigma : float\n",
" The desired latitude accuracy in meters (Default 10.0)\n",
" lonsigma : float\n",
" The desired longitude accuracy in meters (Default 10.0)\n",
" radsigma : float\n",
" The desired radius accuracy in meters (Defualt: 15.0)\n",
" semimajor_axis : float\n",
" The semi-major or equitorial radius in meters (Default: 1737400.0 - Moon)\n",
" Returns\n",
" -------\n",
" rectcov : ndarray\n",
" (2,3) covariance matrix\n",
" \"\"\"\n",
" \n",
" lat = math.radians(lat)\n",
" lon = math.radians(lon)\n",
" \n",
" # SetSphericalSigmasDistance\n",
" scaled_lat_sigma = latsigma / semimajor_axis\n",
"\n",
" # This is specific to each lon.\n",
" scaled_lon_sigma = lonsigma * math.cos(lat) / semimajor_axis\n",
" \n",
" # SetSphericalSigmas\n",
" cov = np.eye(3,3)\n",
" cov[0,0] = scaled_lat_sigma ** 2\n",
" cov[1,1] = scaled_lon_sigma ** 2\n",
" cov[2,2] = radsigma ** 2\n",
" \n",
" # Approximate the Jacobian\n",
" j = np.zeros((3,3))\n",
" cosphi = math.cos(lat)\n",
" sinphi = math.sin(lat)\n",
" coslambda = math.cos(lon)\n",
" sinlambda = math.sin(lon)\n",
" rcosphi = rad * cosphi\n",
" rsinphi = rad * sinphi\n",
" j[0,0] = -rsinphi * coslambda\n",
" j[0,1] = -rcosphi * sinlambda\n",
" j[0,2] = cosphi * coslambda\n",
" j[1,0] = -rsinphi * sinlambda\n",
" j[1,1] = rcosphi * coslambda\n",
" j[1,2] = cosphi * sinlambda\n",
" j[2,0] = rcosphi\n",
" j[2,1] = 0.\n",
" j[2,2] = sinphi\n",
" mat = j.dot(cov)\n",
" mat = mat.dot(j.T)\n",
" rectcov = np.zeros((2,3))\n",
" rectcov[0,0] = mat[0,0]\n",
" rectcov[0,1] = mat[0,1]\n",
" rectcov[0,2] = mat[0,2]\n",
" rectcov[1,0] = mat[1,1]\n",
" rectcov[1,1] = mat[1,2]\n",
" rectcov[1,2] = mat[2,2]\n",
" \n",
" return rectcov\n",
"# return np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])\n",
"\n",
"\n",
"def compute_cov_matrix(record, semimajor_axis):\n",
" cov_matrix = compute_sigma_covariance_matrix(record['lat_Y_North'], record['long_X_East'], record['ht'], record['sig0'], record['sig1'], record['sig2'], semimajor_axis)\n",
" return cov_matrix.ravel().tolist()\n",
"def apply_transformations(atf_dict, df):\n",
" prj_file = os.path.join(atf_dict['PATH'], atf_dict['PROJECT'].split('\\\\')[-1])\n",
" \n",
" lla = np.array([[df['long_X_East']], [df['lat_Y_North']], [df['ht']]])\n",
" \n",
" ecef = body_fix(lla, semi_major = eRadius, semi_minor = pRadius, inverse=False)\n",
" \n",
" df['s.'], df['l.'], df['image_index'] = (zip(*df.apply(line_sample_size, path = atf_dict['PATH'], axis=1)))\n",
" df['known'] = df.apply(known, axis=1)\n",
" df['long_X_East'] = ecef[0][0]\n",
" df['lat_Y_North'] = ecef[1][0]\n",
" df['ht'] = ecef[2][0] \n",
" df['aprioriCovar'] = df.apply(compute_cov_matrix, semimajor_axis = eRadius, axis=1)\n",
" df['ignore'] = df.apply(ignore_toggle, axis=1)\n",
" \n",
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
"def socet2isis(prj_file):\n",
" # Read in and setup the atf dict of information\n",
" atf_dict = read_atf(prj_file)\n",
" \n",
" # Get the gpf and ipf files using atf dict\n",
" gpf_file = os.path.join(atf_dict['PATH'], atf_dict['GP_FILE']);\n",
" ipf_list = [os.path.join(atf_dict['PATH'], i) for i in atf_dict['IMAGE_IPF']]\n",
" \n",
" # Read in the gpf file and ipf file(s) into seperate dataframes\n",
" gpf_df = read_gpf(gpf_file)\n",
" ipf_df = read_ipf(ipf_list)\n",
"\n",
" # Check for differences between point ids using each dataframes\n",
" # point ids as a reference\n",
" gpf_pt_idx = pd.Index(pd.unique(gpf_df['point_id']))\n",
" ipf_pt_idx = pd.Index(pd.unique(ipf_df['pt_id']))\n",
"\n",
" point_diff = ipf_pt_idx.difference(gpf_pt_idx)\n",
"\n",
" if len(point_diff) != 0:\n",
" warnings.warn(\"The following points found in ipf files missing from gpf file: \\n\\n{}. \\\n",
" \\n\\nContinuing, but these points will be missing from the control network\".format(list(point_diff)))\n",
" \n",
" # Merge the two dataframes on their point id columns\n",
" socet_df = ipf_df.merge(gpf_df, left_on='pt_id', right_on='point_id')\n",
" \n",
" # Apply the transformations\n",
" apply_transformations(atf_dict, socet_df)\n",
" \n",
" # Define column remap for socet dataframe\n",
" 'res_l': 'lineResidual', 'res_s': 'sampleResidual', 'known': 'Type',\n",
" 'lat_Y_North': 'AprioriY', 'long_X_East': 'AprioriX', 'ht': 'AprioriZ',\n",
" 'sig0': 'AprioriLatitudeSigma', 'sig1': 'AprioriLongitudeSigma', 'sig2': 'AprioriRadiusSigma',\n",
" 'sig_l': 'linesigma', 'sig_s': 'samplesigma'}\n",
" \n",
" # Rename the columns using the column remap above\n",
" socet_df.rename(columns = column_remap, inplace=True)\n",
" \n",
" # Return the socet dataframe to be converted to a control net\n",
" return socet_df\n",
"\n",
"# creates a dict of serial numbers with the cub being the key\n",
"def serial_numbers(images, path, extension):\n",
" serial_dict = dict()\n",
" \n",
" for image in images:\n",
" snum = sn.generate_serial_number(os.path.join(path, image + extension))\n",
" snum = snum.replace('Mars_Reconnaissance_Orbiter', 'MRO')\n",
" serial_dict[image] = snum\n",
"# path = '/home/tthatcher/Desktop/Projects/plio_imgs/quest_imgs/'\n",
"# extension = '.lev1.cub'\n",
"# atf_file = ('/home/tthatcher/Desktop/Projects/plio_imgs/quest_imgs/CTX_Athabasca_Middle_step0.atf')\n",
"\n",
"# Setup stuffs for the cub information namely the path and extension\n",
"path = '/path/where/cub/files/are/'\n",
"\n",
"# Extension of your cub files\n",
"\n",
"# Path to atf file\n",
"atf_file = ('/path/to/atf/file')\n",
"images = pd.unique(socet_df['ipf_file'])\n",
"serial_dict = serial_numbers(images, path, extension)\n",
"cn.to_isis('/path/you/want/the/cnet/to/be/in/cn.net', socet_df, serial_dict)\n",
"\n",
"# cn.to_isis('/home/tthatcher/Desktop/Projects/plio_imgs/quest_imgs/cn.net', socet_df, serial_dict)"
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
}
},
"nbformat": 4,
"nbformat_minor": 2
}