Skip to content

Commit

Permalink
Update example with projection grid
Browse files Browse the repository at this point in the history
The grid is no longer square, does remapping with both remap_file
and remap, and the first time index and top vertical level are
selected from the input data for easier viz.
  • Loading branch information
xylar committed May 24, 2021
1 parent c796ad6 commit be036ee
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions examples/make_mpas_to_Antarctic_stereo_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,29 @@
inDescriptor = MpasMeshDescriptor(inGridFileName, inGridName)

# modify the size and resolution of the Antarctic grid as desired
outDescriptor = get_polar_descriptor(Lx=6000., Ly=6000., dx=10., dy=10.,
outDescriptor = get_polar_descriptor(Lx=6000., Ly=5000., dx=10., dy=10.,
projection='antarctic')
outGridName = outDescriptor.meshName

mappingFileName = 'map_{}_to_{}_conserve.nc'.format(inGridName, outGridName)
mappingFileName = 'map_{}_to_{}_bilinear.nc'.format(inGridName, outGridName)

remapper = Remapper(inDescriptor, outDescriptor, mappingFileName)

# conservative remapping with 4 MPI tasks (using mpirun)
remapper.build_mapping_file(method='conserve', mpiTasks=4)
remapper.build_mapping_file(method='bilinear', mpiTasks=4)

outFileName = 'temp_{}.nc'.format(outGridName)
# select the SST at the initial time as an example data set
srcFileName = 'temp_{}.nc'.format(inGridName)
ds = xarray.open_dataset(inGridFileName)
dsOut = xarray.Dataset()
dsOut['temperature'] = ds['temperature']
dsOut['temperature'] = ds['temperature'].isel(nVertLevels=0, Time=0)
dsOut.to_netcdf(srcFileName)

# do remapping with ncremap
outFileName = 'temp_{}_file.nc'.format(outGridName)
remapper.remap_file(srcFileName, outFileName)

# do remapping again, this time with python remapping
outFileName = 'temp_{}_array.nc'.format(outGridName)
dsOut = remapper.remap(dsOut)
dsOut.to_netcdf(outFileName)

0 comments on commit be036ee

Please sign in to comment.