From b618776f8fa85bc3cd6c4a9e64d1ec5cdb860afd Mon Sep 17 00:00:00 2001 From: Fei Ye Date: Wed, 20 Nov 2024 18:38:28 -0500 Subject: [PATCH] STOFS3D scripts: remove leading zeros in *source.th for operation. Other minor changes. --- .../Source_sink/v7/gen_sourcesink.py | 2 +- .../Pre_processing/Bathy_edit/bathy_edit.py | 16 +- .../Bathy_edit/xGEOID/convert2xgeoid.py | 4 +- .../Relocate/relocate_source_feeder.py | 67 +++++- .../Pre_processing/stofs3d_atl_driver.py | 205 ++++-------------- 5 files changed, 125 insertions(+), 169 deletions(-) diff --git a/src/Utility/Pre-Processing/STOFS-3D-Atl-operation/Source_sink/v7/gen_sourcesink.py b/src/Utility/Pre-Processing/STOFS-3D-Atl-operation/Source_sink/v7/gen_sourcesink.py index abd367bf9..a8f4ff670 100644 --- a/src/Utility/Pre-Processing/STOFS-3D-Atl-operation/Source_sink/v7/gen_sourcesink.py +++ b/src/Utility/Pre-Processing/STOFS-3D-Atl-operation/Source_sink/v7/gen_sourcesink.py @@ -84,7 +84,7 @@ def main(): idx = np.argsort(np.array([int(key) for key in source2fid_dict.keys()])) # write source time history file np.savetxt(f'{working_dir}/vsource.th', - np.c_[times, sources[:, idx]], fmt='%10.4f', delimiter=' ') + np.c_[times, sources[:, idx]], fmt='%.4f', delimiter=' ') if __name__ == '__main__': diff --git a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/bathy_edit.py b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/bathy_edit.py index b4c690e01..f685d8e15 100755 --- a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/bathy_edit.py +++ b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/bathy_edit.py @@ -18,6 +18,12 @@ Some larger files are not included in the Git repository, you need to specify the paths in the "LARGE_FILES" dictionary below. + +Note that xGEOID is just a wrapper around vdatum.jar, +which takes a lot of memory and quite slow. +Running xGEOID on a large grid may take hours. +Use viz.sciclone.wm.edu; other SciClone subclusters often run out of memory. +This is deprecated, use Felicio's workflow after testing. ''' import os @@ -29,7 +35,7 @@ from pylib import grd2sms, sms2grd try: # c++ function to speed up the grid reading - from pylib_experimental.schism_file import cread_schism_hgrid as schism_read + from pylib_experimental.schism_file import xread_schism_hgrid as schism_read except ImportError: from pylib import schism_grid as schism_read @@ -217,11 +223,11 @@ def bathy_edit(wdir: Path, hgrid_fname: Path, tasks: list = None): # A grid without feeder is needed to identify which feeder points are outside and should be deepened # Only the boundary matters, the interior of the grid doesn't matter, # so if you don't have a grid without feeders, you can just generate a simplified grid with the lbnd_ocean map - gd_no_feeder = sms2grd('/sciclone/schism10/Hgrid_projects/STOFS3D-v7/v20.0/no_feeder.2dm') + gd_no_feeder = sms2grd('/sciclone/schism10/Hgrid_projects/STOFS3D-v8/v23.1/hgrid.2dm') gd_no_feeder.proj(prj0='esri:102008', prj1='epsg:4326') initial_dp = hgrid_obj.dp.copy() hgrid_obj = set_feeder_dp( - feeder_info_dir='/sciclone/schism10/Hgrid_projects/STOFS3D-v7/v20.0/Feeder/', + feeder_info_dir='/sciclone/schism10/Hgrid_projects/STOFS3D-v7/v23.3/Feeder/', hgrid_obj=hgrid_obj, hgrid_obj_no_feeder=gd_no_feeder ) dp_diff = initial_dp - hgrid_obj.dp @@ -239,12 +245,12 @@ def sample_usage(): ''' Sample usage of the bathy_edit function. ''' - WDIR = Path('/sciclone/schism10/feiye/STOFS3D-v8/I10/Bathy_edit/') + WDIR = Path('/sciclone/schism10/feiye/STOFS3D-v8/I10/Bathy_edit2/') HGRID_FNAME = Path( # Typically, this is the DEM-loaded hgrid '/sciclone/schism10/feiye/STOFS3D-v8/I10/Bathy_edit/' 'DEM_loading/hgrid.ll.dem_loaded.mpi.gr3' ) - TASKS = ['Regional_tweaks', 'NCF', 'Levee'] + TASKS = ['xGEOID'] bathy_edit(wdir=WDIR, hgrid_fname=HGRID_FNAME, tasks=TASKS) diff --git a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/xGEOID/convert2xgeoid.py b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/xGEOID/convert2xgeoid.py index 1d4f5ec72..eca960c0a 100644 --- a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/xGEOID/convert2xgeoid.py +++ b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Bathy_edit/xGEOID/convert2xgeoid.py @@ -223,7 +223,7 @@ def convert2xgeoid(wdir, hgrid_obj, diag_output=None): # this generates the input files for vdatum.jar, including # hgrid_stofs3d_inland_?.txt and hgrid_stofs3d_inland_ches_del.txt - generated_input_files = generate_input_txt(hgrid_obj=hgrid_obj, wdir=wdir, n_sub=100000) + generated_input_files = generate_input_txt(hgrid_obj=hgrid_obj, wdir=wdir, n_sub=500000) # see if the input files are complete @@ -241,7 +241,7 @@ def convert2xgeoid(wdir, hgrid_obj, diag_output=None): # the first group should have no failed files, since they are strictly in region 4 # this may not be true for other domains, so manually go over the workflow first before using the script - input_fnames = glob("*_[0-9].txt") + input_fnames = glob("hgrid*.txt") # Starting the processes processes = [subprocess.Popen( f"java -jar vdatum.jar ihorz:NAD83_2011 ivert:navd88:m:{z_convention} " diff --git a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Source_sink/Relocate/relocate_source_feeder.py b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Source_sink/Relocate/relocate_source_feeder.py index a5ce781a5..50e42478c 100755 --- a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Source_sink/Relocate/relocate_source_feeder.py +++ b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/Source_sink/Relocate/relocate_source_feeder.py @@ -103,6 +103,45 @@ [-72.06195833333334, 41.525600000000004, np.nan, np.nan], # Quinebaug River, CT ]).reshape(-1, 4) +v23p3_mandatory_sources_coor = np.array([ + [-73.90869, 42.13509, np.nan, np.nan], # Hudson River, NY + [-74.94442, 40.34478, np.nan, np.nan], # Delaware River, NJ + [-76.1011, 39.5802, np.nan, np.nan], # Susquehanna River, VA + [-78.425288, 34.508177, np.nan, np.nan], # Cape Fear River, NC + [-91.72306, 31.04462, np.nan, np.nan], # Red River (upstream of Atchafalaya River), LA + [-80.10808, 33.50005, np.nan, np.nan], # Santee River, SC + [-79.81703, 33.59694, np.nan, np.nan], # Black River, SC + [-79.57210, 33.71223, np.nan, np.nan], # Black Mingo Creek, SC + [-79.49997, 33.84686, np.nan, np.nan], # Lynches River, SC + [-79.48467, 33.93939, np.nan, np.nan], # Pee Dee River, SC + [-79.33247, 33.98196, np.nan, np.nan], # Little Pee Dee River, SC + [-77.917829, 34.749979, np.nan, np.nan], # Northeast Cape Fear River, NC + [-87.9523, 30.8472, np.nan, np.nan], # Mobile River, AL + [-96.695401, 28.968284, -96.69652166667, 28.990345], # Lavaca River, TX + [-96.548436, 28.999706, -96.554498, 29.024612666667], # Lake Texana, TX + [-93.83342666667, 30.355123333333, -93.83342666667, 30.355123333333], # Cypress Creek, TX + [-89.764476, 30.551926, -89.76781133333, 30.538070666667], # Lotts Creek, LA + [-87.219805, 30.567296, -87.24471466667, 30.601442333333], # Escambia River, FL + [-83.987035, 30.331327, np.nan, np.nan], # Horsehead Creek and Little River, FL + [-83.928038, 30.30404, np.nan, np.nan], # Bailey Mill Creek, FL + [-82.950913, 29.958097, -82.99605566667, 30.007415], # Suwannee River, FL + [-81.02370433333333, 27.315079666666666, np.nan, np.nan], # Kissimmee River, FL + [-81.997572, 30.786870, -82.040457, 30.74494233333333], # St Marys River, FL + [-91.56184, 31.05043, np.nan, np.nan], # Mississippi River + [-79.43425, 33.84487, -79.50974266666667, 33.85385866666667], # Lyches River, SC + [-74.74868, 39.47915, -74.75470666666668, 39.485390333333335], # Great Egg Harbor River, NJ + [-73.94009733333333, 42.06972966666667, np.nan, np.nan], # Saugeties Creek, NY + [-73.971293, 41.920595999999996, np.nan, np.nan], # Hudson River branch, NY + [-73.92918633333333, 41.592421333333334, np.nan, np.nan], # Hudson River branch, NY + [-73.07229533333333, 41.303546000000004, np.nan, np.nan], # Housatonic River, CT + [-72.625735, 41.656137666666666, np.nan, np.nan], # Connecticut River, CT + [-72.64970633333333, 41.572111666666665, np.nan, np.nan], # Mattabesset River, CT + [-72.470818, 41.47020933333334, np.nan, np.nan], # Salmon River, CT + [-72.11158266666666, 41.455657333333335, np.nan, np.nan], # Stony Brook, CT + [-72.090553, 41.535118000000004, np.nan, np.nan], # Yantic River, CT + [-72.06195833333334, 41.525600000000004, np.nan, np.nan], # Quinebaug River, CT +]).reshape(-1, 4) + def nearest_neighbour(points_a, points_b): '''A wrapper for scipy.spatial.cKDTree to find the nearest neighbour of points_a in points_b''' @@ -130,6 +169,17 @@ def lonlat2cpp(lon, lat, lon0=0, lat0=0): return [xout, yout] +def cpp2lonlat(x, y, lon0=0, lat0=0): + """ + Convert cpp in meters to lon/lat + """ + R_EARTH = 6378206.4 + lon0_radian, lat0_radian = lon0/180*np.pi, lat0/180*np.pi + lon_radian = x / R_EARTH / np.cos(lat0_radian) + lon0_radian + lat0_radian = y / R_EARTH + return [lon_radian/np.pi*180, lat0_radian/np.pi*180] + + def relocate_sources2( old_ss_dir=None, outdir=None, feeder_info_file=None, hgrid_fname=None, allow_neglection=True, @@ -262,6 +312,8 @@ def relocate_sources2( relocation_distance[i] = distance[target_old_source] else: if i < len(mandatory_sources_coor): + # mandatory sources are the first len(manadatory_sources_coor) new_sources, + # which must be relocated raise ValueError(f'mandatory new source {i}: {x, y} cannot be mapped to an old source') # -------------------------------------clean up odd cases------------------------------------- @@ -358,6 +410,7 @@ def relocate_sources2( def relocate_sources( old_ss_dir=None, outdir=None, relocate_map=None, + no_feeder=False, allow_neglection=True, feeder_info_file=None, hgrid_fname=None, max_search_radius=1000.0, mandatory_sources_coor=np.empty((0, 4)), region_list=None, @@ -373,8 +426,10 @@ def relocate_sources( which is useful for the operational forecast to save time, in this case no need to provide the arguments below; otherwise, the relocation map will be generated. + : no_feeder: if true, feeder_bases (which should still be present in a mesh without feeders) + will be used; otherwise, feeder_heads will be used. :allow_neglection: Allow neglecting channels that cannot be matched to a new source location. - This is useful when the relocation is only for a specific region. + This is useful when the relocation is restricted to a specific region. If False, any unassigned old sources will be linked to the closest new source. :feeder_info_file: Feeder channel information generated by make_feeder_channel.py after RiverMapper @@ -453,7 +508,13 @@ def relocate_sources( # -------------------------------------relocation------------------------------------- # Find matching source point at mandatory_sources_coor and feeders # These are the desired new source locations - new_sources_coor = np.r_[mandatory_sources_coor[:, :2], feeder_heads[:, :2]] + if no_feeder: + # If feeders are not implemented in the mesh, use "feeder_bases" instead of "feeder_heads", + # because "feeder_bases" are the locations where the feeders are to be placed. + # The relocation still works in the sense that only resolved rivers receive new sources. + new_sources_coor = np.r_[mandatory_sources_coor[:, :2], feeder_bases[:, :2]] + else: + new_sources_coor = np.r_[mandatory_sources_coor[:, :2], feeder_heads[:, :2]] # These are the locations used to search for the closest old source # ; in other words, to link the new source to the old source. # For the mandatory sources, these may be different from the new source locations @@ -650,7 +711,7 @@ def test(): old_ss_dir='/sciclone/schism10/feiye/STOFS3D-v7/Inputs/I12z/Source_sink/original_source_sink/', feeder_info_file='/sciclone/schism10/Hgrid_projects/STOFS3D-v7/v20.0/Feeder/feeder_heads_bases.xy', hgrid_fname=f'{wdir}/hgrid.gr3', outdir=wdir, - max_search_radius=2100, mandatory_sources_coor=v19p2_mandatory_sources_coor, + max_search_radius=2100, mandatory_sources_coor=v23p3_mandatory_sources_coor, allow_neglection=False ) diff --git a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/stofs3d_atl_driver.py b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/stofs3d_atl_driver.py index 32f86ac27..2b024e3c3 100755 --- a/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/stofs3d_atl_driver.py +++ b/src/Utility/Pre-Processing/STOFS-3D-Atl-shadow-VIMS/Pre_processing/stofs3d_atl_driver.py @@ -48,7 +48,8 @@ else: from pylib import schism_grid as schism_read print('Using python function to read hgrid') -from pyschism.mesh import Hgrid +from pyschism.mesh import Hgrid, Vgrid +from pyschism.forcing.hycom.hycom2schism import Nudge # Import from the sub folders. These are not from installed packages. from Source_sink.NWM.gen_sourcesink_nwm import gen_sourcesink_nwm @@ -59,6 +60,9 @@ from Bctides.bctides.bctides import Bctides # temporary, bctides.py will be merged into pyschism # from pyschism.forcing.bctides import Bctides +# Import configuration +from stofs3d_atl_config import ConfigStofs3dAtlantic + # Global variables: # use the full path of the Pre-Processing dir inside your schism repo # e.g, script_path = '/my_dir/schism/src/Utility/Pre-Processing/' @@ -69,145 +73,6 @@ DRIVER_PRINT_PREFIX = '\n-----------------STOFS3D-ATL driver:---------------------\n' -# --------------------------------------------------------------------- -# Classes -# --------------------------------------------------------------------- -class ConfigStofs3dAtlantic(): - '''A class to handle the configuration of STOFS-3D-ATL model, - i.e., processing the parameters and storing the factory settings. - ''' - def __init__( - self, - startdate=datetime(2017, 12, 1), # start date of the model - rnday=60, # number of days to run the model - nudging_zone_width=1.5, # in degrees - nudging_day=1.0, # in days - shapiro_zone_width=2.5, # in degrees - shapiro_tilt=2.0, # more abrupt transition in the shapiro zone - bctides_flags=None, # a list of lists, each sublist is a set of flags for an open boundary - nwm_cache_folder=None, - relocate_source=True, - feeder_info_file=None, # file containing feeder info, - # made by make_feeder_channel.py in RiverMapper - gr3_values=None, - tvd_regions=None - ): - - self.startdate = startdate - self.rnday = rnday - self.nudging_zone_width = nudging_zone_width - self.nudging_day = nudging_day - self.shapiro_zone_width = shapiro_zone_width - self.shapiro_tilt = shapiro_tilt - self.relocate_source = relocate_source - self.nwm_cache_folder = nwm_cache_folder - self.feeder_info_file = feeder_info_file - if bctides_flags is None: - self.bctides_flags = [ - [3, 3, 0, 0], # tides for elev and vel - [3, 3, 0, 0], # tides for elev and vel - [3, 3, 0, 0], # tides for elev and vel - [3, 3, 0, 0], # tides for elev and vel - [3, 3, 0, 0], # tides for elev and vel - ] - else: - self.bctides_flags = bctides_flags - - if gr3_values is None: - self.gr3_values = { # uniform gr3 values - 'albedo': 0.1, - 'diffmax': 1.0, - 'diffmin': 1e-6, - 'watertype': 1.0, - 'windrot_geo2proj': 0.0 - } - else: - self.gr3_values = gr3_values - - if tvd_regions is None: - self.tvd_regions = [] - else: - self.tvd_regions = tvd_regions - - @classmethod - def v6(cls): - '''Factory method to create a configuration for STOFS3D-v6''' - return cls( - nudging_zone_width=.3, # very wide nudging zone - shapiro_zone_width=11.5, # very wide shapiro zone - shapiro_tilt=3.5, # very abrupt transition in the shapiro zone - feeder_info_file=( - '/sciclone/schism10/feiye/STOFS3D-v5/Inputs/v14/Parallel/' - 'SMS_proj/feeder/feeder.pkl'), - bctides_flags=[[5, 5, 4, 4]], - tvd_regions=[ - 'tvd0_1.reg', 'tvd0_2.reg', 'tvd0_3.reg', 'tvd0_4.reg', - 'tvd0_5.reg', 'tvd0_6.reg', 'tvd0_7.reg', - 'upwind_east_Carribbean.rgn', 'upwind_west_Carribbean.rgn' - ] - ) - - @classmethod - def v7(cls): - '''Factory method to create a configuration for STOFS3D-v7''' - return cls( - nudging_zone_width=7.3, # default nudging zone - shapiro_zone_width=11.5, # default shapiro zone - shapiro_tilt=3.5, # default abrupt transition in the shapiro zone - feeder_info_file=( - '/sciclone/schism10/Hgrid_projects/STOFS3D-v7/v20.0/Feeder/' - 'feeder_heads_bases.xy'), - nwm_cache_folder=Path('/sciclone/schism10/whuang07/schism20/NWM_v2.1/'), - bctides_flags=[ - [3, 3, 0, 0], # Atlantic Ocean - [3, 3, 0, 0], # Gulf of St. Lawrence - [0, 1, 0, 0], # St. Lawrence River - ], - tvd_regions=[ - 'tvd0_1.reg', 'tvd0_2.reg', 'tvd0_3.reg', 'tvd0_4.reg', - 'tvd0_5.reg', 'tvd0_6.reg', 'tvd0_7.reg', - 'upwind_east_Carribbean.rgn', 'upwind_west_Carribbean.rgn' - ] - ) - - @classmethod - def v7_hercules_test(cls): - '''Factory method to create a configuration for STOFS3D-v7''' - return cls( - nudging_zone_width=7.3, # default nudging zone - shapiro_zone_width=11.5, # default shapiro zone - shapiro_tilt=3.5, # default abrupt transition in the shapiro zone - relocate_source=True, # need the feeder info file - feeder_info_file=( - '/work/noaa/nosofs/feiye/STOFS-3D-Atl-Example-Setup/DATA/' - 'Feeder_channels/feeder_heads_bases.xy'), - nwm_cache_folder=None, - bctides_flags=[ - [3, 3, 0, 0], # Atlantic Ocean - [3, 3, 0, 0], # Gulf of St. Lawrence - [0, 1, 0, 0], # St. Lawrence River - ], - tvd_regions=[ - 'tvd0_1.reg', 'tvd0_2.reg', 'tvd0_3.reg', 'tvd0_4.reg', - 'tvd0_5.reg', 'tvd0_6.reg', 'tvd0_7.reg', - 'upwind_east_Carribbean.rgn', 'upwind_west_Carribbean.rgn' - ] - ) - - @classmethod - def v8_louisianna(cls): - '''Factory method to create a configuration for STOFS3D-v8's local test in Louisianna''' - return cls( - nudging_zone_width=0, # default nudging zone - shapiro_zone_width=0, # default shapiro zone - shapiro_tilt=0, # default abrupt transition in the shapiro zone - feeder_info_file='', - relocate_source=False, - nwm_cache_folder=Path('/sciclone/schism10/whuang07/schism20/NWM_v2.1/'), - bctides_flags=[[5, 5, 4, 4]] - ) - - # --------------------------------------------------------------------- # Utility functions # --------------------------------------------------------------------- @@ -337,6 +202,22 @@ def gen_nudge_coef(hgrid: pylib.schism_grid, rlmax=1.5, rnu_day=0.25, open_bnd_l return nudge_coeff +def gen_nudge_stofs(hgrid_fname, vgrid_fname, outdir, start_date, rnday): + ''' + Generate nudge coefficient, + adapted from pyschism's sample script + ''' + hgrid = Hgrid.open(hgrid_fname, crs='epsg:4326') + + # ocean_bnd_ids - segment indices, starting from zero. + nudge = Nudge(hgrid=hgrid, ocean_bnd_ids=[0, 1]) + + # rlmax - max relax distance in m or degree + # rnu_day - max relax strength in days + # restart = True will append to the existing nc file, works when first try doesn't break. + nudge.fetch_data(outdir, vgrid_fname, start_date, rnday, restart=False, rnu_day=1, rlmax=7.3) + + def gen_drag(hgrid: pylib.schism_grid): '''generate drag coefficient based on the depth and regions''' @@ -491,12 +372,12 @@ def main(): # -----------------input--------------------- # hgrid generated by SMS, pre-processed, and converted to *.gr3 - hgrid_path = ('/sciclone/schism10/feiye/STOFS3D-v8/I10a/hgrid.gr3') + hgrid_path = ('/sciclone/schism10/Hgrid_projects/STOFS3D-v8/v23.1/hgrid_with_bnd.gr3') # get a configuration preset and make changes if necessary # alternatively, you can set the parameters directly on an # new instance of ConfigStofs3dAtlantic - config = ConfigStofs3dAtlantic.v7() + config = ConfigStofs3dAtlantic.v8() config.rnday = 36 config.startdate = datetime(2024, 3, 5) config.nwm_cache_folder = Path( @@ -510,7 +391,7 @@ def main(): # R{runid}: run directory, where the run will be submitted to queue; # O{runid}: output directory for holding raw outputs and post-processing. # under project_dir - runid = '10a' + runid = '11a' # swithes to generate different input files input_files = { @@ -518,13 +399,13 @@ def main(): 'vgrid': False, 'gr3': False, 'nudge_gr3': False, - 'shapiro': True, - 'drag': True, - 'elev_ic': True, + 'shapiro': False, + 'drag': False, + 'elev_ic': False, 'source_sink': False, 'hotstart.nc': False, '*D.th.nc': False, - '*nu.nc': False, + '*nu.nc': True, '*.prop': False, } # -----------------end input--------------------- @@ -703,13 +584,13 @@ def main(): # mkcd_new_dir(f'{model_input_path}/{sub_dir}') - # generate source_sink files by intersecting NWM river segments - # with the model land boundary - mkcd_new_dir(f'{model_input_path}/{sub_dir}/original_source_sink/') - os.symlink(f'{model_input_path}/hgrid.gr3', 'hgrid.gr3') - gen_sourcesink_nwm( - startdate=config.startdate, rnday=config.rnday, - cache_folder=config.nwm_cache_folder) + # # generate source_sink files by intersecting NWM river segments + # # with the model land boundary + # mkcd_new_dir(f'{model_input_path}/{sub_dir}/original_source_sink/') + # os.symlink(f'{model_input_path}/hgrid.gr3', 'hgrid.gr3') + # gen_sourcesink_nwm( + # startdate=config.startdate, rnday=config.rnday, + # cache_folder=config.nwm_cache_folder) # relocate source locations to resolved river channels, the result is the "base" source/sink if config.relocate_source: @@ -721,7 +602,7 @@ def main(): feeder_info_file=config.feeder_info_file, hgrid_fname=f'{model_input_path}/hgrid.gr3', outdir=f'{model_input_path}/{sub_dir}/relocated_source_sink/', - max_search_radius=2100, mandatory_sources_coor=v19p2_mandatory_sources_coor, + max_search_radius=2100, mandatory_sources_coor=config.mandatory_sources_coor, allow_neglection=False ) # regenerate source/sink based on relocated sources.json and sinks.json @@ -803,12 +684,20 @@ def main(): # -----------------*nu.nc--------------------- if input_files['*nu.nc']: - sub_dir = 'Nu' + sub_dir = 'Nudge' print(f'{DRIVER_PRINT_PREFIX}Generating *nu.nc files ...') mkcd_new_dir(f'{model_input_path}/{sub_dir}') - # generate *nu.nc - raise NotImplementedError('*nu.nc is not implemented yet') + os.system(f'cp {script_path}/Nudge/* .') + gen_nudge_stofs( + hgrid_fname=f'{model_input_path}/hgrid.gr3', + vgrid_fname=f'{model_input_path}/vgrid.in', + outdir=f'{model_input_path}/{sub_dir}', + rnday=config.rnday, start_date=config.startdate + ) + + os.chdir(run_dir) + os.system(f'ln -sf ../I{runid}/{sub_dir}/*nu.nc .') def test():