Skip to content

Commit 84c3d99

Browse files
committed
Update preprocessing for pyremap 2.0.0
1 parent ba0a3d9 commit 84c3d99

File tree

5 files changed

+47
-39
lines changed

5 files changed

+47
-39
lines changed

preprocess_observations/preprocess_SOSE_data.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import gsw
3333

3434
from mpas_analysis.shared.io.download import download_files
35-
from mpas_analysis.shared.interpolation import Remapper
36-
from mpas_analysis.shared.grid import LatLonGridDescriptor
35+
from pyremap import LatLonGridDescriptor, Remapper
3736
from mpas_analysis.shared.climatology.comparison_descriptors \
3837
import get_comparison_descriptor
3938
from mpas_analysis.configuration \
@@ -486,24 +485,27 @@ def remap(ds, outDescriptor, mappingFileName, inDir, outFileName):
486485
ds.close()
487486

488487
inDescriptor = LatLonGridDescriptor.read(tempFileName1,
489-
latVarName='lat',
490-
lonVarName='lon')
488+
lat_var_name='lat',
489+
lon_var_name='lon')
491490

492-
remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)
491+
remapper = Remapper(map_filename=mappingFileName, method='bilinear')
492+
remapper.src_descriptor = inDescriptor
493+
remapper.dst_descriptor = outDescriptor
494+
remapper.build_map()
493495

494-
remapper.build_mapping_file(method='bilinear')
495-
496-
remapper.remap_file(inFileName=tempFileName1,
497-
outFileName=tempFileName2,
498-
overwrite=True,
499-
renormalize=0.01)
496+
remapper.ncremap(
497+
in_filename=tempFileName1,
498+
out_filename=tempFileName2,
499+
overwrite=True,
500+
renormalize=0.01
501+
)
500502

501503
ds = xarray.open_dataset(tempFileName2)
502504
if 'z' in ds:
503505
print(' transposing back...')
504506
ds = ds.chunk({'Time': 4})
505507
ds = ds.transpose('Time', 'x', 'y', 'z', 'nvertices')
506-
ds.attrs['meshName'] = outDescriptor.meshName
508+
ds.attrs['meshName'] = outDescriptor.mesh_name
507509

508510
for coord in ['x', 'y']:
509511
ds.coords[coord] = xarray.DataArray.from_dict(
@@ -765,7 +767,7 @@ def main():
765767
'{}'.format(antarcticStereoWidth))
766768

767769
outDescriptor = get_comparison_descriptor(config, 'antarctic')
768-
outGridName = '{}_{}'.format(outDescriptor.meshName, date)
770+
outGridName = '{}_{}'.format(outDescriptor.mesh_name, date)
769771

770772
inPrefixes = [inTPrefix, inSPrefix, inMLDPrefix, inUPrefix, inVPrefix,
771773
inGammaNPrefix]

preprocess_observations/preprocess_Schmidtko_data.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
from mpas_analysis.shared.io.download import download_files
3333

34-
from mpas_analysis.shared.interpolation import Remapper
35-
from mpas_analysis.shared.grid import LatLonGridDescriptor
34+
from pyremap import LatLonGridDescriptor, Remapper
3635
from mpas_analysis.shared.climatology.comparison_descriptors \
3736
import get_comparison_descriptor
3837
from mpas_analysis.configuration \
@@ -150,26 +149,27 @@ def remap(inDir, outDir):
150149
inDescriptor = LatLonGridDescriptor()
151150

152151
inDescriptor = LatLonGridDescriptor.read(inFileName,
153-
latVarName='lat',
154-
lonVarName='lon')
152+
lat_var_name='lat',
153+
lon_var_name='lon')
155154

156155
outDescriptor = get_comparison_descriptor(config, 'antarctic')
157-
outGridName = outDescriptor.meshName
156+
outGridName = outDescriptor.mesh_name
158157

159158
outFileName = '{}/Schmidtko_et_al_2014_bottom_PT_S_PD_{}.nc'.format(
160159
outDir, outGridName)
161160

162161
mappingFileName = '{}/map_{}_to_{}.nc'.format(inDir, inGridName,
163162
outGridName)
164163

165-
remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)
166-
167-
remapper.build_mapping_file(method='bilinear')
164+
remapper = Remapper(map_filename=mappingFileName, method='bilinear')
165+
remapper.src_descriptor = inDescriptor
166+
remapper.dst_descriptor = outDescriptor
167+
remapper.build_map()
168168

169169
if not os.path.exists(outFileName):
170170
print('Remapping...')
171171
with xarray.open_dataset(inFileName) as dsIn:
172-
with remapper.remap(dsIn, renormalizationThreshold=0.01) \
172+
with remapper.remap_numpy(dsIn, renormalizationThreshold=0.01) \
173173
as remappedMLD:
174174
print('Done.')
175175
remappedMLD.attrs['history'] = ' '.join(sys.argv)

preprocess_observations/preprocess_adusumilli_melt.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,16 @@ def remap_adusumilli(in_filename, out_prefix, date, task_count=512):
163163

164164
map_filename = f'map_{in_grid_name}_to_{out_grid_name}_{method}.nc'
165165

166-
remapper = Remapper(in_descriptor, out_descriptor, map_filename)
166+
remapper = Remapper(
167+
ntasks=task_count, map_filename=map_filename, method=method)
168+
remapper.src_descriptor = in_descriptor
169+
remapper.dst_descriptor = out_descriptor
170+
remapper.parallel_exec = 'srun'
167171

168172
if not os.path.exists(map_filename):
169-
remapper.build_mapping_file(method=method, mpiTasks=task_count,
170-
esmf_parallel_exec='srun')
173+
remapper.build_map()
171174

172-
ds_out = remapper.remap(ds)
175+
ds_out = remapper.remap_numpy(ds)
173176
mask = ds_out.meltMask > 0.
174177
ds_out['meltRate'] = ds_out.meltRate.where(mask)
175178
ds_out.meltRate.attrs = melt_attrs

preprocess_observations/preprocess_paolo_melt.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,16 @@ def remap_paolo(in_filename, out_prefix, date, task_count=128):
158158

159159
map_filename = f'map_{in_grid_name}_to_{out_grid_name}_{method}.nc'
160160

161-
remapper = Remapper(in_descriptor, out_descriptor, map_filename)
161+
remapper = Remapper(
162+
ntasks=task_count, map_filename=map_filename, method=method)
163+
remapper.src_descriptor = in_descriptor
164+
remapper.dst_descriptor = out_descriptor
165+
remapper.parallel_exec = 'srun'
162166

163167
if not os.path.exists(map_filename):
164-
remapper.build_mapping_file(method=method, mpiTasks=task_count,
165-
esmf_parallel_exec='srun')
168+
remapper.build_map()
166169

167-
ds_out = remapper.remap(ds)
170+
ds_out = remapper.remap_numpy(ds)
168171
mask = ds_out.meltMask > 0.
169172
ds_out['meltRate'] = ds_out.meltRate.where(mask)
170173
ds_out.meltRate.attrs = melt_attrs

preprocess_observations/remap_rignot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
import pyproj
1616
import sys
1717

18-
from mpas_analysis.shared.interpolation import Remapper
19-
from mpas_analysis.shared.grid import ProjectionGridDescriptor
18+
from pyremap import ProjectionGridDescriptor, Remapper
2019
from mpas_analysis.shared.mpas_xarray.mpas_xarray import subset_variables
2120
from mpas_analysis.shared.climatology \
2221
import get_Antarctic_stereographic_comparison_descriptor
@@ -50,21 +49,22 @@
5049

5150
inDescriptor = ProjectionGridDescriptor(projection)
5251

53-
inDescriptor.read(inFileName, xVarName='xaxis', yVarName='yaxis',
54-
meshName=inGridName)
52+
inDescriptor.read(inFileName, x_var_name='xaxis', y_var_name='yaxis',
53+
mesh_name=inGridName)
5554

5655
outDescriptor = get_Antarctic_stereographic_comparison_descriptor(config)
57-
outGridName = outDescriptor.meshName
56+
outGridName = outDescriptor.mesh_name
5857

5958
outFileName = 'Rignot_2013_melt_rates_{}.nc'.format(outGridName)
6059

6160
mappingFileName = 'map_{}_to_{}.nc'.format(inGridName, outGridName)
6261

63-
remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)
62+
remapper = Remapper(map_filename=mappingFileName, method='bilinear')
63+
remapper.src_descriptor = inDescriptor
64+
remapper.dst_descriptor = outDescriptor
65+
remapper.build_map()
6466

65-
remapper.build_mapping_file(method='bilinear')
66-
67-
remappedDataset = remapper.remap(ds, renormalizationThreshold=0.01)
67+
remappedDataset = remapper.remap_numpy(ds, renormalizationThreshold=0.01)
6868

6969
remappedDataset.attrs['history'] = ' '.join(sys.argv)
7070
remappedDataset.to_netcdf(outFileName)

0 commit comments

Comments
 (0)