Skip to content

Commit 1fc3b56

Browse files
committed
Check for existing files in testing/setup.py
1 parent a3098a6 commit 1fc3b56

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ jobs:
9898
- name: Install cdo 🌍
9999
run: |
100100
sudo apt-get update
101-
sudo apt-get install -y cdo --no-install-recommends
101+
sudo apt-get install -y cdo netcdf-bin --no-install-recommends
102102
103103
- name: Set up Python 🐍
104104
uses: actions/setup-python@v6

testing/setup.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def run_gridfile():
4545
output_path = constants.SHARE_PATH / 'gridarea.nc'
4646
output_path.parent.mkdir(parents=True, exist_ok=True)
4747

48-
helper.call(f'cdo gridarea {input_path} {output_path}')
48+
if not output_path.exists():
49+
helper.call(f'cdo gridarea {input_path} {output_path}')
4950

5051

5152
def run_seldate():
@@ -57,7 +58,9 @@ def run_seldate():
5758
('2019-01-01', '2020-12-31', '2019_2020')
5859
]:
5960
output_path = constants.DATASETS_PATH / constants.TAS_PATH.replace('2015_2020', specifiers)
60-
helper.call(f'cdo -f nc4c -z zip_5 -L seldate,{start_date},{end_date} {input_path} {output_path}')
61+
62+
if not output_path.exists():
63+
helper.call(f'cdo -f nc4c -z zip_5 -L seldate,{start_date},{end_date} {input_path} {output_path}')
6164

6265

6366
def run_select_time():
@@ -70,9 +73,9 @@ def run_select_time():
7073
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_select-time-cdo_') \
7174
.replace('2015_2020', '20180101')
7275
output_path.parent.mkdir(parents=True, exist_ok=True)
73-
output_path.unlink(missing_ok=True)
7476

75-
helper.call(f'cdo -f nc4c -z zip_5 -L seldate,{date} {input_path} {output_path}')
77+
if not output_path.exists():
78+
helper.call(f'cdo -f nc4c -z zip_5 -L seldate,{date} {input_path} {output_path}')
7679

7780

7881
def run_select_period():
@@ -85,9 +88,9 @@ def run_select_period():
8588
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_select-period-cdo_') \
8689
.replace('2015_2020', '2015')
8790
output_path.parent.mkdir(parents=True, exist_ok=True)
88-
output_path.unlink(missing_ok=True)
8991

90-
helper.call(f'cdo -f nc4c -z zip_5 -L seldate,{start_date},{end_date} {input_path} {output_path}')
92+
if not output_path.exists():
93+
helper.call(f'cdo -f nc4c -z zip_5 -L seldate,{start_date},{end_date} {input_path} {output_path}')
9194

9295

9396
def run_select_point():
@@ -96,50 +99,42 @@ def run_select_point():
9699
# add one since cdo is counting from 1!
97100
ix, iy = ix + 1, iy + 1
98101

99-
output_paths = []
100102
for path in [constants.TAS_PATH, *constants.TAS_SPLIT_PATHS]:
101103
input_path = constants.DATASETS_PATH / path
102104

103105
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_select-point-cdo_')
104106
output_path.parent.mkdir(parents=True, exist_ok=True)
105-
output_path.unlink(missing_ok=True)
106-
107-
output_paths.append(str(output_path))
108107

109-
helper.call(f'cdo -f nc4c -z zip_5 -L -selindexbox,{ix},{ix},{iy},{iy} {input_path} {output_path}')
108+
if not output_path.exists():
109+
helper.call(f'cdo -f nc4c -z zip_5 -L -selindexbox,{ix},{ix},{iy},{iy} {input_path} {output_path}')
110110

111111

112112
def run_select_bbox():
113113
west, east, south, north = constants.BBOX
114114

115-
output_paths = []
116115
for path in [constants.TAS_PATH, *constants.TAS_SPLIT_PATHS]:
117116
input_path = constants.DATASETS_PATH / path
118117

119118
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_select-bbox-cdo_')
120119
output_path.parent.mkdir(parents=True, exist_ok=True)
121-
output_path.unlink(missing_ok=True)
122120

123-
output_paths.append(str(output_path))
124-
125-
helper.call(f'cdo -f nc4c -z zip_5 -L -sellonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
121+
if not output_path.exists():
122+
helper.call(f'cdo -f nc4c -z zip_5 -L ' \
123+
f'-sellonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
126124

127125

128126
def run_select_bbox_mean():
129127
west, east, south, north = constants.BBOX
130128

131-
output_paths = []
132129
for path in [constants.TAS_PATH, *constants.TAS_SPLIT_PATHS]:
133130
input_path = constants.DATASETS_PATH / path
134131

135132
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_select-bbox-mean-cdo_')
136133
output_path.parent.mkdir(parents=True, exist_ok=True)
137-
output_path.unlink(missing_ok=True)
138-
139-
output_paths.append(str(output_path))
140134

141-
helper.call('cdo -f nc4c -z zip_5 -L -fldmean ' \
142-
f'-sellonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
135+
if not output_path.exists():
136+
helper.call('cdo -f nc4c -z zip_5 -L -fldmean '
137+
f'-sellonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
143138

144139

145140
def run_select_bbox_map():
@@ -150,42 +145,37 @@ def run_select_bbox_map():
150145

151146
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_select-bbox-map-cdo_')
152147
output_path.parent.mkdir(parents=True, exist_ok=True)
153-
output_path.unlink(missing_ok=True)
154148

155-
helper.call('cdo -f nc4c -z zip_5 -L timmean ' \
156-
f'-sellonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
149+
if not output_path.exists():
150+
helper.call('cdo -f nc4c -z zip_5 -L timmean '
151+
f'-sellonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
157152

158153

159154
def run_mask_bbox():
160155
west, east, south, north = constants.BBOX
161156

162-
output_paths = []
163157
for path in [constants.TAS_PATH, *constants.TAS_SPLIT_PATHS]:
164158
input_path = constants.DATASETS_PATH / path
165159

166160
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_mask-bbox-cdo_')
167161
output_path.parent.mkdir(parents=True, exist_ok=True)
168-
output_path.unlink(missing_ok=True)
169162

170-
output_paths.append(str(output_path))
171-
172-
helper.call(f'cdo -f nc4c -z zip_5 -L -masklonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
163+
if not output_path.exists():
164+
helper.call(f'cdo -f nc4c -z zip_5 -L '
165+
f'-masklonlatbox,{west},{east},{south},{north} {input_path} {output_path}')
173166

174167

175168
def run_mask_mask():
176169
mask_path = constants.DATASETS_PATH / constants.LANDSEAMASK_PATH
177170

178-
output_paths = []
179171
for path in [constants.TAS_PATH, *constants.TAS_SPLIT_PATHS]:
180172
input_path = constants.DATASETS_PATH / path
181173

182174
output_path = constants.EXTRACTIONS_PATH / path.replace('_global_', '_mask-mask-cdo_')
183175
output_path.parent.mkdir(parents=True, exist_ok=True)
184-
output_path.unlink(missing_ok=True)
185-
186-
output_paths.append(str(output_path))
187176

188-
helper.call(f'cdo -f nc4c -z zip_5 -L -ifthen -selname,mask {mask_path} {input_path} {output_path}')
177+
if not output_path.exists():
178+
helper.call(f'cdo -f nc4c -z zip_5 -L -ifthen -selname,mask {mask_path} {input_path} {output_path}')
189179

190180

191181
if __name__ == "__main__":

0 commit comments

Comments
 (0)