lhico / pyroms_tools

Set of tools to create input files for ROMS simulations. Depends a little bit on PyROMS.
4 stars 2 forks source link

bdry_replace bug empty files #36

Open nilodna opened 1 year ago

nilodna commented 1 year ago

When using the entire experiment period to create empty boundary files with scripts/make_bdry_files.py, we will have an issue with the make_bdry_file_replace.py. This second script has a condition to avoid recreating boundary files for the same time twice. So, if already exist a file for 2001-12-01, then it will not be recreated again, even though the file is empty.

To fix this issue, my idea is to create an empty boundary file with another name, using the same time used for the initial condition:

wfiles = [
    f'remap_weights_{srcname}_to_{gridname}_bilinear_t_to_rho.nc',
    f'remap_weights_{srcname}_to_{gridname}_bilinear_u_to_rho.nc',
    f'remap_weights_{srcname}_to_{gridname}_bilinear_v_to_rho.nc'
    ]

src_grd = CGrid_glorys.A2CGrid(fpath, xrange=xrange, yrange=yrange, lonoffset=0, **varstr)
dst_grd = pyroms.grid.get_ROMS_grid(gridname)  # read data from the gridid.txt

it = pd.to_datetime(startTime)
tfile = sorted(dicts['ic.input_file'])

itstr = str(it).replace(' ', 'T')

# -- interpolates vector fields -- #
dfileu = f'{dst_grd.name}_u_bdry.nc'  # temporary interpolated file name
dfilev = f'{dst_grd.name}_v_bdry.nc'  # temporary interpolated file name

# interpolating
remap_bdry.make_bdry_uv_file(tfile, src_grd, dst_grd, itstr,
                dst_fileu=dfileu, dst_filev=dfilev, wts_file=wfiles)

# -- interpolates scalar fields -- #
for varb in ['so', 'thetao','zos']:
    dfile = f'{dst_grd.name}_{varb}_bdry.nc'  # temporary interpolated file
    remap_bdry.make_bdry_rho_file(tfile, src_grd, dst_grd, varb, itstr,
                            dst_file=dfile, weight_file=wfiles[0])

# name of the merged initial condition file
bdry_file = osp.join(outdir, f'{dst_grd.name}_bdry_{itstr}.nc')
out_file = f'{dst_grd.name}_%s_bdry.nc'  # temporary interpolated file

# -- merge files and remove temporary files --#
cont = 0
for istr in ['zos', 'so', 'thetao', 'u', 'v']:
    if cont ==0:
        command = ('ncks', '-a', '-O', out_file % istr, bdry_file)  # create ic
        cont += 1
    else:
        command = ('ncks', '-a', '-A', out_file % istr, bdry_file)  # append
    subprocess.call(command)
    os.remove(out_file % istr)  # remove temp files

[file: scripts/make_bdry_file.py]

This will generate a file as bdry_empty.nc, which must be inserted into the bdry.bdry_file key at the grid_config_esmf.txt:

'bdry.bdry_file': '/path/to/file/bdry_empty.nc
nilodna commented 1 year ago

Just to inform you that this modification is under test right now and soon will be merged into the 34_enhancement_boundary_xesmf branch.