Skip to content

Commit 2121e22

Browse files
committed
Convert SCRIP files to CDF5 format for moab
This is more efficient than partitioning them as we did previously.
1 parent 0e436d1 commit 2121e22

File tree

1 file changed

+17
-40
lines changed

1 file changed

+17
-40
lines changed

pyremap/remapper/build_map.py

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ def _build_map(remapper, logger=None):
5858

5959
elif map_tool == 'moab':
6060
moab_path = remapper.moab_path
61-
src_scrip_filename = _moab_partition_scrip_file(
62-
remapper, src_scrip_filename, moab_path, logger
63-
)
64-
dst_scrip_filename = _moab_partition_scrip_file(
65-
remapper, dst_scrip_filename, moab_path, logger
66-
)
61+
if src_descriptor.format != 'NETCDF3_64BIT_DATA':
62+
# we need to convert to CDF5 for moab compatibility
63+
cdf_filename = src_scrip_filename.replace('.nc', '.cdf5.nc')
64+
src_scrip_filename = _convert_to_cdf5(
65+
src_scrip_filename, cdf_filename, logger
66+
)
67+
if dst_descriptor.format != 'NETCDF3_64BIT_DATA':
68+
# we need to convert to CDF5 for moab compatibility
69+
cdf_filename = dst_scrip_filename.replace('.nc', '.cdf5.nc')
70+
dst_scrip_filename = _convert_to_cdf5(
71+
dst_scrip_filename, cdf_filename, logger
72+
)
6773
args = _moab_build_map_args(
6874
remapper, src_scrip_filename, dst_scrip_filename
6975
)
@@ -93,47 +99,18 @@ def _build_map(remapper, logger=None):
9399
tempobj.cleanup()
94100

95101

96-
def _moab_partition_scrip_file(remapper, in_filename, moab_path, logger):
102+
def _convert_to_cdf5(in_filename, out_filename, logger):
97103
"""
98-
Partition SCRIP file for parallel mbtempest use
104+
Convert SCRIP file to NetCDF3_64BIT_DATA
99105
"""
100-
ntasks = remapper.ntasks
101-
102-
print(f'Partition SCRIP file {in_filename}')
106+
print(f'Converting {in_filename} to CDF5 format in {out_filename}')
103107

104-
h5m_filename = in_filename.replace('.nc', '.h5m')
105-
h5m_part_filename = in_filename.replace('.nc', f'.p{ntasks}.h5m')
106-
107-
if moab_path is None:
108-
mbconvert = 'mbconvert'
109-
mbpart = 'mbpart'
110-
else:
111-
mbconvert = os.path.join(moab_path, 'bin', 'mbconvert')
112-
mbpart = os.path.join(moab_path, 'bin', 'mbpart')
113-
114-
# Convert source SCRIP to mbtempest
115-
args = [
116-
mbconvert,
117-
'-B',
118-
in_filename,
119-
h5m_filename,
120-
]
121-
check_call(args, logger=logger)
122-
123-
# Partition source SCRIP
124-
args = [
125-
mbpart,
126-
f'{ntasks}',
127-
'-z',
128-
'RCB',
129-
h5m_filename,
130-
h5m_part_filename,
131-
]
108+
args = ['ncks', '-O', '-5', in_filename, out_filename]
132109
check_call(args, logger=logger)
133110

134111
print(' Done.')
135112

136-
return h5m_part_filename
113+
return out_filename
137114

138115

139116
def _esmf_build_map_args(remapper, src_scrip_filename, dst_scrip_filename):

0 commit comments

Comments
 (0)