Skip to content

Commit 6969df9

Browse files
committed
Updated to add in compression of the files
1 parent e790938 commit 6969df9

7 files changed

+32
-3
lines changed

wah_extract_functions.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,17 @@ def get_output_field_name3(field):
121121
###############################################################################
122122

123123
def get_filename(taskpath, field,output_dir,zipstart,zipend,structure='std',zip_freq='month'):
124-
stream_map={'ma':'atmos','ga':'region','ka':'atmos','ko':'ocean'}
125124
# Different components used in file name and path
126125
boinc=taskpath.split('/')[-1]
127126

128127
# When splitting up the file name by underscore
129128
# hadcm3 apps have one less component (e.g. compared to wah2_eu50)
130-
if boinc[:6]=='hadcm3':
129+
if boinc[:6] in ['hadcm3','hadam4']:
130+
stream_map={'ma':'atmos','ga':'atmos','ka':'atmos','ko':'ocean'}
131131
umid=boinc.split('_')[1]
132132
datecode=boinc.split('_')[2]
133133
else:
134+
stream_map={'ma':'atmos','ga':'region','ka':'atmos','ko':'ocean'}
134135
umid=boinc.split('_')[2]
135136
datecode=boinc.split('_')[3]
136137
# Get start year and month (old filenames don't contain start month so assume 12)
@@ -824,4 +825,10 @@ def read_urls(urls_file):
824825
fh.close()
825826
urls = map(string.strip, urls)
826827
return urls
828+
829+
#####################################################
830+
831+
def compress_netcdf(fname):
832+
os.system('nccopy -d 2 -s '+fname+' '+fname+'_compressed')
833+
shutil.move(fname+'_compressed',fname)
827834

wah_extract_functions_hadam4.py

+6
Original file line numberDiff line numberDiff line change
@@ -824,4 +824,10 @@ def read_urls(urls_file):
824824
fh.close()
825825
urls = map(string.strip, urls)
826826
return urls
827+
828+
#####################################################
829+
830+
def compress_netcdf(fname):
831+
os.system('nccopy -d 2 -s '+fname+' '+fname+'_compressed')
832+
shutil.move(fname+'_compressed',fname)
827833

wah_extract_local.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,15 @@
134134
# Rename temp file to out_netcdf
135135
shutil.move(temp_nc,out_file)
136136
print os.path.basename(out_file)
137-
137+
138138
# Remove netcdf files to stop temp directory getting too big
139139
for nc_list in all_netcdfs.itervalues():
140140
for fname in nc_list:
141141
os.remove(fname)
142+
143+
# Compress the output netcdf file
144+
compress_netcdf(out_file)
145+
142146
except Exception,e:
143147
print 'Error extracting netcdf files',e
144148
traceback.print_exc()

wah_extract_local_Windows.py

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@
172172
for nc_list in all_netcdfs.itervalues():
173173
for fname in nc_list:
174174
os.remove(fname)
175+
176+
# Compress the output netcdf file
177+
compress_netcdf(out_file)
175178
except Exception,e:
176179
print 'Error extracting netcdf files',e
177180
traceback.print_exc()

wah_extract_local_hadam4.py

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
for nc_list in all_netcdfs.itervalues():
140140
for fname in nc_list:
141141
os.remove(fname)
142+
143+
# Compress the output netcdf file
144+
compress_netcdf(out_file)
142145
except Exception,e:
143146
print 'Error extracting netcdf files',e
144147
traceback.print_exc()

wah_extract_wget.py

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
for nc_list in all_netcdfs.itervalues():
143143
for fname in nc_list:
144144
os.remove(fname)
145+
146+
# Compress the output netcdf file
147+
compress_netcdf(out_file)
145148
except Exception,e:
146149
print 'Error extracting netcdf files',e
147150
traceback.print_exc()

wah_extract_wget_Windows.py

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
for nc_list in all_netcdfs.itervalues():
165165
for fname in nc_list:
166166
os.remove(fname)
167+
168+
# Compress the output netcdf file
169+
compress_netcdf(out_file)
167170
except Exception,e:
168171
print 'Error extracting netcdf files',e
169172
traceback.print_exc()

0 commit comments

Comments
 (0)