Skip to content

Commit fc176e9

Browse files
committed
Added the code written in the field
1 parent b4fcf82 commit fc176e9

9 files changed

+675
-0
lines changed

cresis_season.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
################ This is the import statement required to reference scripts within the package
2+
import os,sys,glob
3+
ndh_tools_path_opts = [
4+
'/mnt/data01/Code/',
5+
'/home/common/HolschuhLab/Code/'
6+
]
7+
for i in ndh_tools_path_opts:
8+
if os.path.isfile(i): sys.path.append(i)
9+
################################################################################################
10+
11+
12+
def cresis_season(y,m=0,d=0,ant1_gre2=1):
13+
"""
14+
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
15+
%
16+
% This function finds the season name associated with a flight day
17+
% There are a small number of flight days in which both campaigns
18+
% were running apparently. By default, this code will assume you want
19+
% the Antarctic Season. If you would prefer it prompt you to ask for
20+
% a selection, chanage the value to zero.
21+
%
22+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23+
% The inputs are:
24+
%
25+
% y - either the year, or a string for the filename you want the season for
26+
% m - the month
27+
% d - the day
28+
% ant1_gre2 - force a particular continent for days where there are surveys in both places
29+
%
30+
%%%%%%%%%%%%%%%
31+
% The outputs are:
32+
% season_out - A dictionary with information about the matching season
33+
%
34+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35+
"""
36+
from datetime import date
37+
import numpy as np
38+
import os
39+
import sys
40+
import glob
41+
sys.path.append('/mnt/data01/Code/')
42+
import NDH_Tools as ndh
43+
44+
########################### Here we find the season metadata. This file was produced
45+
########################### from an external matlab script
46+
season_metadata_dirs = [
47+
'/mnt/data01/Data/RadarData/CReSIS_Filestructure/'
48+
]
49+
for i in season_metadata_dirs:
50+
if os.path.isdir(i): season_metadata_path=i
51+
52+
53+
season_opts = ndh.loadmat(season_metadata_path+'season_metadata.mat')
54+
55+
if isinstance(y,str) == 1:
56+
if y[0] == 'D':
57+
m = int(y[9:11])
58+
d = int(y[11:13])
59+
y = int(y[5:9])
60+
else:
61+
m = int(y[4:6])
62+
d = int(y[6:8])
63+
y = int(y[0:4])
64+
65+
target_date = date.toordinal(date(y,m,d))
66+
67+
full_dates = np.concatenate([season_opts['a_dates'],season_opts['g_dates']])
68+
############### Matlab starts at year 0, python at year 1. So there is a 1 year offset applied here
69+
full_dates[:,0] = full_dates[:,0]-366
70+
full_dates = np.concatenate([full_dates,np.expand_dims(np.concatenate([np.ones(len(season_opts['a_dates'][:,0])),
71+
np.ones(len(season_opts['g_dates'][:,0]))*2]),0).T],1)
72+
73+
match_ind = np.where(full_dates[:,0] == target_date)[0]
74+
exact_flag = 1;
75+
76+
if ant1_gre2 == 1:
77+
if len(match_ind) > 1:
78+
match_ind = match_ind[0]
79+
else:
80+
if len(match_ind) > 1:
81+
match_ind = match_ind[1]
82+
83+
if len(match_ind) == 0:
84+
match_ind = ndh.find_nearest(full_dates[:,0],target_date);
85+
match_ind = match_ind['index'][0]
86+
exact_flag = 0;
87+
88+
############### You have to subtract one from the match ind to deal with matlabs indexing
89+
if full_dates[match_ind,2] == 1:
90+
season_out = season_opts['a_names'][int(full_dates[match_ind,1]-1)]
91+
else:
92+
season_out = season_opts['g_names'][int(full_dates[match_ind,1]-1)]
93+
94+
if exact_flag == 0:
95+
print('No exact match was found -- closest suggested season is the following: '+season_out[0])
96+
97+
season_out = {'exact_match':exact_flag,'season':season_out[0],'data_dir':season_out[1],'Date':season_out[2]}
98+
return season_out

find_cresisfiles.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
################ This is the import statement required to reference scripts within the package
2+
import os,sys,glob
3+
ndh_tools_path_opts = [
4+
'/mnt/data01/Code/',
5+
'/home/common/HolschuhLab/Code/'
6+
]
7+
for i in ndh_tools_path_opts:
8+
if os.path.isfile(i): sys.path.append(i)
9+
################################################################################################
10+
11+
12+
def find_cresisfiles(y,m=0,d=0,seg=0,frame=0):
13+
"""
14+
% (C) Nick Holschuh - Amherst College -- 2022 ([email protected])
15+
%
16+
% This function finds the season name associated with a flight day
17+
%
18+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19+
% The inputs are:
20+
%
21+
% y - either the year, or a string for the filename you want the season for
22+
% m - the month
23+
% d - the day
24+
% ant1_gre2 - force a particular continent for days where there are surveys in both places
25+
%
26+
%%%%%%%%%%%%%%%
27+
% The outputs are:
28+
% season_out - A dictionary with information about the matching season
29+
%
30+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31+
"""
32+
from datetime import date
33+
import os
34+
import sys
35+
import glob
36+
sys.path.append('/mnt/data01/Code/')
37+
import NDH_Tools as ndh
38+
39+
root_dir = '/mnt/data01/Data/RadarData/CReSIS_Filestructure/ct_data/rds/'
40+
41+
if isinstance(y,str) == 1:
42+
if y[0] == 'D':
43+
seg = int(y[14:16])
44+
frm = int(y[17:20])
45+
m = int(y[9:11])
46+
d = int(y[11:13])
47+
y = int(y[5:9])
48+
else:
49+
seg = int(y[9:11])
50+
frm = int(y[13:16])
51+
m = int(y[4:6])
52+
d = int(y[6:8])
53+
y = int(y[0:4])
54+
55+
season = ndh.cresis_season(y,m,d)
56+
dayseg_str = '%0.4d%0.2d%0.2d_%0.2d' % (y,m,d,seg)
57+
filestr = 'Data_%s_%0.3d' % (dayseg_str,frm)
58+
59+
processing_types = sorted(glob.glob(root_dir+season['season']+'/*/'))
60+
search_types = ['standard','music','surf','DEM']
61+
dir_names = [[],[],[],[]]
62+
found_files = [[],[],[],[]]
63+
64+
for ind0,ptype in enumerate(search_types):
65+
type_fdrs,type_fdrs_ind = ndh.str_compare(processing_types,ptype)
66+
67+
for ind1,type_fdr in enumerate(type_fdrs):
68+
file_opts = sorted(glob.glob(type_fdr+dayseg_str+'/'+filestr+'.mat'))
69+
for ind2, file_select in enumerate(file_opts):
70+
found_files[ind0].append(file_select)
71+
temp_dir_name = file_select.split('/')
72+
dir_names[ind0].append(temp_dir_name[-3])
73+
74+
#found_files[ind0] = ndh.flatten_list(found_files[ind0]);
75+
76+
found_files = {'standard':found_files[0],'standard_dirs':dir_names[0],
77+
'music':found_files[1],'music_dirs':dir_names[1],
78+
'surf':found_files[2],'surf_dirs':dir_names[2],
79+
'DEM':found_files[3],'DEM_dirs':dir_names[3]}
80+
81+
return found_files

0 commit comments

Comments
 (0)