-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcresis_processing_string.py
More file actions
129 lines (105 loc) · 5.18 KB
/
cresis_processing_string.py
File metadata and controls
129 lines (105 loc) · 5.18 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
import os
import numpy as np
import tqdm
import glob
################## NDH Tools self imports
###########################################################
from .find_cresisfiles import find_cresisfiles
from .index_list import index_list
from .str_compare import str_compare
###########################################################
def cresis_processing_string(filelist,collate=0,excludes=[],param_dir='/mnt/NDH_data/Google_Drive2/Research_Projects/00_CresisData/opr_params/'):
"""
% (C) Nick Holschuh - Amherst College - 2025 ([email protected])
% This function creates a typical processing loop string for use with OPR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are as follows:
%
% filelist -- list of files to reprocess
% collate=0 -- set to 1 if used for tomo.collate run
"""
param_spreadsheets = glob.glob(param_dir+'*rds*')
ki = []
for ind0,fn in enumerate(filelist):
skipflag=0
for exclude in excludes:
if exclude in fn:
skipflag=1
if skipflag == 0:
ki.append(ind0)
filelist = index_list(filelist,ki)
if collate == 0:
seasons = []
seg_ids = []
frames = []
for fn in tqdm.tqdm(filelist):
true_fn = find_cresisfiles(fn)
seasons.append(true_fn['standard'][0].split('/')[-4])
seg_ids.append(true_fn['standard'][0].split('/')[-2])
frames.append(int(true_fn['standard'][0].split('/')[-1].split('_')[-1].split('.')[0]))
for ind0,season in enumerate(np.unique(seasons)):
season_name,wi = str_compare(seasons,season)
unique_seg_ids = sorted(np.unique(index_list(seg_ids,wi)))
####### Get the season name
ssname,ssind = str_compare(param_spreadsheets,season)
try:
ssname = ssname[0].split('/')[-1]
param_ss_string = 'param_ssheet_name = \''+ssname+'\';'
seg_id_string = 'seg_id_list = {\''
frame_id_string = 'frame_id_list = {'
for ind1,seg_id in enumerate(unique_seg_ids):
frame_names,frame_inds = str_compare(seg_ids,seg_id)
seg_id_string = seg_id_string+seg_id+'\', \''
frame_id_string = frame_id_string+'\'['
unique_frames = sorted(np.unique(index_list(frames,frame_inds)))
for ind2,frame_ind in enumerate(unique_frames):
frame_id_string = frame_id_string+str(frame_ind)+','
frame_id_string = frame_id_string[:-1]+']\','
seg_id_string = seg_id_string[:-3]+'};'
frame_id_string = frame_id_string[:-1]+'};'
print(' ')
print(param_ss_string)
print(seg_id_string)
print(frame_id_string)
except:
print('Coulding find parameter spreadsheet for '+season)
else:
#######################################
### Create objects to copy for tomo_collate
########### Get the unique seasons, and store seg_ids and frames
seasons = []
seg_ids = []
frames = []
for fn in tqdm.tqdm(filelist):
true_fn = find_cresisfiles(fn)
seasons.append(true_fn['standard'][0].split('/')[-4])
seg_ids.append(true_fn['standard'][0].split('/')[-2])
frames.append(int(true_fn['standard'][0].split('/')[-1].split('_')[-1].split('.')[0]))
seg_id_string = 'seg_id_lists = {\''
frame_id_string = 'frame_id_lists = {'
param_ss_string = 'param_ssheet_names = {\''
for ind0,season in enumerate(np.unique(seasons)):
season_name,wi = str_compare(seasons,season)
unique_seg_ids = sorted(np.unique(index_list(seg_ids,wi)))
####### Get the season name
ssname,ssind = str_compare(param_spreadsheets,season)
try:
ssname = ssname[0].split('/')[-1]
for ind1,seg_id in enumerate(unique_seg_ids):
frame_names,frame_inds = str_compare(seg_ids,seg_id)
param_ss_string = param_ss_string+ssname+'\',\''
seg_id_string = seg_id_string+seg_id+'\', \''
frame_id_string = frame_id_string+'['
unique_frames = sorted(np.unique(index_list(frames,frame_inds)))
for ind2,frame_ind in enumerate(unique_frames):
frame_id_string = frame_id_string+str(frame_ind)+','
frame_id_string = frame_id_string[:-1]+'],'
except:
print('Coulding find parameter spreadsheet for '+season)
seg_id_string = seg_id_string[:-3]+'};'
frame_id_string = frame_id_string[:-1]+'};'
param_ss_string = param_ss_string[:-1]+'};'
print(' ')
print(param_ss_string)
print(seg_id_string)
print(frame_id_string)