forked from ET-NCMP/MarineQC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_BackgroundField.py
157 lines (88 loc) · 4.79 KB
/
test_BackgroundField.py
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
import unittest
import BackgroundField as bf
class TestBuildCompletions(unittest.TestCase):
def test_simple(self):
base = 'a'
subs = ['b', 'c']
completions = bf.build_completions(base, subs)
self.assertEqual(completions[0], 'a/b')
self.assertEqual(completions[1], 'a/b/c')
def test_even_simpler(self):
base = 'a'
subs = ['b']
completions = bf.build_completions(base, subs)
self.assertEqual(completions[0], 'a/b')
def test_too_many_slashes(self):
base = 'a/'
subs = ['b']
completions = bf.build_completions(base, subs)
self.assertEqual(completions[0], 'a/b')
class TestProcessString(unittest.TestCase):
def test_simple(self):
teststring = 'OnceUponAYYYYMMMMDDDD'
correctstring = 'OnceUponA20190331'
outstring = bf.process_string(teststring, 2019, 3, 31)
self.assertEqual(outstring, correctstring)
class TestMakeFilename(unittest.TestCase):
def test_basic(self):
dirstub = '/project/data/coriolis/YYYY/MMMM/DDDD/'
filenamestub = 'AwesomeData_YYYYMMMMDDDD.nc'
year = 2002
month = 2
day = 17
outstring = bf.make_filename(dirstub, filenamestub, year, month, day)
correctstring = '/project/data/coriolis/2002/02/17/AwesomeData_20020217.nc'
self.assertEqual(outstring, correctstring)
def test_non_terminating_slash(self):
dirstub = '/project/data/coriolis/YYYY/MMMM/DDDD'
filenamestub = 'AwesomeData_YYYYMMMMDDDD.nc'
year = 2002
month = 2
day = 17
outstring = bf.make_filename(dirstub, filenamestub, year, month, day)
correctstring = '/project/data/coriolis/2002/02/17/AwesomeData_20020217.nc'
self.assertEqual(outstring, correctstring)
class TestGetBackgroundFilename(unittest.TestCase):
def test_simple_cci(self):
dirstubs = ['/project/earthobs/SST/ESACCI_SST/CDR2.1_release/Analysis/L4/YYYY/MMMM/DDDD/']
filenamestubs = ['YYYYMMMMDDDD120000-ESACCI-L4_GHRSST-SSTdepth-OSTIA-GLOB_CDR2.1-v02.0-fv01.0.nc']
outfile = bf.get_background_filename(dirstubs, filenamestubs, 2002, 11, 30)
correctfile = '/project/earthobs/SST/ESACCI_SST/CDR2.1_release/Analysis/L4/2002/11/30/' +\
'20021130120000-ESACCI-L4_GHRSST-SSTdepth-OSTIA-GLOB_CDR2.1-v02.0-fv01.0.nc'
self.assertEqual(outfile, correctfile)
def test_missing_cci(self):
dirstubs = ['/project/earthobs/SST/ESACCI_SST/CDR2.1_release/Analysis/L4/YYYY/MMMM/DDDD/']
filenamestubs = ['YYYYMMMMDDDD120000-ESACCI-L4_GHRSST-SSTdepth-OSTIA-GLOB_CDR2.1-v02.0-fv01.0.nc']
outfile = bf.get_background_filename(dirstubs, filenamestubs, 1922, 11, 30)
self.assertIsNone(outfile)
def test_pre_2007_ostia(self):
dirstubs = ['/project/ofrd/ostia/reanalysis/v1.0/YYYY/MMMM/',
'/project/ofrd/ostia/data/netcdf/YYYY/MMMM/']
filenamestubs = ['YYYYMMMMDDDD-UKMO-L4HRfnd-GLOB-v01-fv02-OSTIARAN.nc',
'YYYYMMMMDDDD-UKMO-L4HRfnd-GLOB-v01-fv02-OSTIA.nc']
outfile = bf.get_background_filename(dirstubs, filenamestubs, 2002, 11, 30)
correctfile = '/scratch/hadjj/20021130-UKMO-L4HRfnd-GLOB-v01-fv02-OSTIARAN.nc'
self.assertEqual(outfile, correctfile)
def test_post_2007_ostia(self):
dirstubs = ['/project/ofrd/ostia/reanalysis/v1.0/YYYY/MMMM/',
'/project/ofrd/ostia/data/netcdf/YYYY/MMMM/']
filenamestubs = ['YYYYMMMMDDDD-UKMO-L4HRfnd-GLOB-v01-fv02-OSTIARAN.nc',
'YYYYMMMMDDDD-UKMO-L4HRfnd-GLOB-v01-fv02-OSTIA.nc']
outfile = bf.get_background_filename(dirstubs, filenamestubs, 2010, 8, 3)
correctfile = '/scratch/hadjj/20100803-UKMO-L4HRfnd-GLOB-v01-fv02-OSTIA.nc'
self.assertEqual(outfile, correctfile)
class TestIcoadsFilenameFromStub(unittest.TestCase):
def test_2013(self):
dirstubs = ["/project/earthobs/ICOADS/ICOADS.3.0.0/", "/project/earthobs/ICOADS/ICOADS.3.0.1/"]
filenamestubs = ["IMMA1_R3.0.0_YYYY-MMMM.gz", "IMMA1_R3.0.1_YYYY-MMMM.gz"]
testname = bf.icoads_filename_from_stub(dirstubs, filenamestubs, 2003, 9)
correctname = "/project/earthobs/ICOADS/ICOADS.3.0.0/IMMA1_R3.0.0_2003-09.gz"
self.assertEqual(testname, correctname)
def test_2016(self):
dirstubs = ["/project/earthobs/ICOADS/ICOADS.3.0.0/", "/project/earthobs/ICOADS/ICOADS.3.0.1/"]
filenamestubs = ["IMMA1_R3.0.0_YYYY-MMMM.gz", "IMMA1_R3.0.1_YYYY-MMMM.gz"]
testname = bf.icoads_filename_from_stub(dirstubs, filenamestubs, 2016, 12)
correctname = "/project/earthobs/ICOADS/ICOADS.3.0.1/IMMA1_R3.0.1_2016-12.gz"
self.assertEqual(testname, correctname)
if __name__ == '__main__':
unittest.main()