11import os
22import shutil
33
4- import mpas_tools .io
54import netCDF4
65import numpy as np
76from mpas_tools .io import write_netcdf
87from mpas_tools .logging import check_call
9- from mpas_tools .mesh .conversion import cull
8+ from mpas_tools .mesh .conversion import convert , cull
109from mpas_tools .planar_hex import make_planar_hex_mesh
1110from mpas_tools .scrip .from_mpas import scrip_from_mpas
1211from mpas_tools .translate import center , translate
@@ -72,30 +71,24 @@ def run(self):
7271 # factor of 2/sqrt(3) because of hexagonal mesh
7372 ny = max (2 * int (0.5 * ly * (2. / np .sqrt (3 )) / dc + 0.5 ), 4 )
7473
75- mpas_tools .io .default_format = 'NETCDF4'
76- mpas_tools .io .default_engine = 'netcdf4'
77-
7874 # call the mesh creation function
7975 dsMesh = make_planar_hex_mesh (nx = nx , ny = ny , dc = dc ,
8076 nonperiodic_x = True ,
8177 nonperiodic_y = True )
8278 dsMesh = cull (dsMesh , logger = logger )
83- # adding the time dimension is needed for netcdf4 formatting to work
84- dsMesh ['xtime' ] = ('Time' , ['2015-01-01_00:00:00' .ljust (64 )])
79+ dsMesh = convert (dsMesh , logger = logger )
8580 # translating the mesh center to x=0 & y=0
8681 center (dsMesh )
8782 # shift the center to a quarter or radius
8883 shift = 200000.0
8984 print (f'shifting the center by { shift } meters' )
9085 translate (dsMesh , shift , shift )
9186
92- fname_culled = 'culled_mesh_before_cdf5.nc'
93- write_netcdf (dsMesh , fname_culled )
94- args = ['ncks' , '-O' , '-5' , fname_culled , 'mpas_grid.nc' ]
95- check_call (args , logger = logger )
87+ fname_mpas = 'mpas_grid.nc'
88+ write_netcdf (dsMesh , fname_mpas )
9689
9790 levels = 3
98- args = ['create_landice_grid_from_generic_MPAS_grid.py ' ,
91+ args = ['create_landice_grid_from_generic_mpas_grid ' ,
9992 '-i' , 'mpas_grid.nc' ,
10093 '-o' , 'landice_grid.nc' ,
10194 '-l' , str (levels )]
@@ -115,7 +108,7 @@ def run(self):
115108 _build_mapping_files (config , logger , self .res , self .nglv ,
116109 mali_mesh_file = 'landice_grid.nc' )
117110
118- os .remove (fname_culled )
111+ os .remove (fname_mpas )
119112
120113
121114def _setup_circsheet_initial_conditions (config , logger , filename ):
@@ -294,13 +287,13 @@ def _create_smb_forcing_file(config, logger, mali_mesh_file, filename):
294287 if (Rt < 0 ):
295288 Rt = 0.0
296289 sfcMassBal [t , :] = 0.0
297- print (f'At time { start_year + dt_year * t } , \
290+ print (f'At time { start_year + dt_year * t } , \
298291 new radius will be { Rt } km' )
299292 else :
300293 indx = np .where (r >= Rt )[0 ]
301294 sfcMassBal [t , indx ] = smb
302- print (f'At time { start_year + dt_year * t } , \
303- new radius will be { Rt / 1000 } km' )
295+ print (f'At time { start_year + dt_year * t } , \
296+ new radius will be { Rt / 1000 } km' )
304297 smbfile .variables ['sfcMassBal' ][:, :] = sfcMassBal [:, :]
305298
306299 # add xtime variable
@@ -361,12 +354,12 @@ def _build_mapping_files(config, logger, res, nglv, mali_mesh_file):
361354 args = ['ncremap' ,
362355 '-g' , slm_scripfile ,
363356 '-G' ,
364- f'latlon={ slm_nglv } ,{ 2 * int (slm_nglv )} #lat_typ=gss#lat_drc=n2s' ]
357+ f'latlon={ slm_nglv } ,{ 2 * int (slm_nglv )} #lat_typ=gss#lat_drc=n2s' ]
365358
366359 check_call (args , logger = logger )
367360
368361 # adjust the lat-lon values
369- args = ['set_lat_lon_fields_in_planar_grid.py ' ,
362+ args = ['set_lat_lon_fields_in_planar_grid' ,
370363 '--file' , mali_mesh_file ,
371364 '--proj' , 'ais-bedmap2-sphere' ]
372365
0 commit comments