@@ -647,16 +647,12 @@ def write_fsm2_met(ds_pt,
647647
648648
649649
650- def to_fsm2oshd (ds_down ,
651- fsm_param ,
650+ def to_fsm2oshd (mp ,
652651 ds_tvt ,
653652 simulation_path = 'fsm_sim' ,
654653 fname_format = 'fsm_' ,
655654 namelist_options = None ,
656- n_digits = None ,
657655 snow_partition_method = 'continuous' ,
658- cluster_method = True ,
659- epsg_ds_param = 2056 ,
660656 temperature_correction = 0 ,
661657 forest_param_scaler = {'vfhp' :100 , 'fveg' :100 , 'fves' :100 , 'hcan' :100 , 'lai5' :100 }):
662658 """
@@ -668,8 +664,7 @@ def to_fsm2oshd(ds_down,
668664 - param.nam with canopy and model constants. See https://github.com/oshd-slf/FSM2oshd/blob/048e824fb1077b3a38cc24c0172ee3533475a868/runner.py#L10
669665
670666 Args:
671- ds_down: Downscaled weather variable dataset
672- fsm_param: terrain and canopy parameter dataset
667+ mp: TopoClass object
673668 df_centroids: cluster centroids statistics (terrain + canopy)
674669 ds_tvt (dataset, int, float, or str): transmisivity. Can be a dataset, a constant or 'svf_for'
675670 simulation_path (str): 'fsm_sim'
@@ -681,7 +676,10 @@ def to_fsm2oshd(ds_down,
681676 epsg_ds_param (int): epsg code of ds_parma: example: 2056
682677
683678 """
684-
679+ fsm_param = mp .toposub .ds_param
680+ epsg_ds_param = mp .config .dem .epsg
681+ sampling_method = mp .config .sampling .method
682+
685683
686684 def write_fsm2oshd_namelist (row ,
687685 pt_ind ,
@@ -883,10 +881,9 @@ def write_fsm2oshd_met(ds_pt,
883881 if namelist_options is not None :
884882 namelist_param .update (namelist_options )
885883
886- if n_digits is None :
887- n_digits = len (str (len (ds_down .point_name ))) + 1
884+ n_digits = len (str (len (mp .downscaled_pts .point_name ))) + 1
888885
889- if cluster_method :
886+ if sampling_method == 'clusters' :
890887 # extract FSM forest parameters for each clusters
891888 # Aggregate forest parameters only to fores area
892889
@@ -901,8 +898,24 @@ def write_fsm2oshd_met(ds_pt,
901898 df_forest .forest_cover .loc [df_forest .proportion_with_forest < 0.01 ] = 0
902899 df_forest ['lon' ], df_forest ['lat' ] = tp .convert_epsg_pts (df_forest .x , df_forest .y , epsg_ds_param , 4326 )
903900
901+ elif sampling_method == 'points' :
902+ df_forest = mp .toposub .df_centroids .drop_vars ([[
903+ 'slope' , 'aspect' , 'aspect_cos' , 'aspect_sin' , 'svf' ,
904+ 'longitude' , 'latitude' , 'hori_azi_-175.0' , 'hori_azi_-165.0' ,
905+ 'hori_azi_-155.0' , 'hori_azi_-145.0' , 'hori_azi_-135.0' ,
906+ 'hori_azi_-125.0' , 'hori_azi_-115.0' , 'hori_azi_-105.0' ,
907+ 'hori_azi_-95.0' , 'hori_azi_-85.0' , 'hori_azi_-75.0' , 'hori_azi_-65.0' ,
908+ 'hori_azi_-55.0' , 'hori_azi_-45.0' , 'hori_azi_-35.0' , 'hori_azi_-25.0' ,
909+ 'hori_azi_-15.0' , 'hori_azi_-5.0' , 'hori_azi_5.0' , 'hori_azi_15.0' ,
910+ 'hori_azi_25.0' , 'hori_azi_35.0' , 'hori_azi_45.0' , 'hori_azi_55.0' ,
911+ 'hori_azi_65.0' , 'hori_azi_75.0' , 'hori_azi_85.0' , 'hori_azi_95.0' ,
912+ 'hori_azi_105.0' , 'hori_azi_115.0' , 'hori_azi_125.0' , 'hori_azi_135.0' ,
913+ 'hori_azi_145.0' , 'hori_azi_155.0' , 'hori_azi_165.0' , 'hori_azi_175.0' ]]).copy ()
914+
915+
916+
904917 else :
905- pass
918+ raise ValueError ( "Sampling method not yet supported. Avail: clusters, points" )
906919
907920 p = Path (simulation_path )
908921 # rename variable columns to match namelist functino varnames
@@ -912,9 +925,9 @@ def write_fsm2oshd_met(ds_pt,
912925
913926 # ----- Loop through all points-------
914927 # NOTE: eventually this for loop could be parallelized to several cores -----
915- for pt_ind , pt_name in enumerate (ds_down .point_name .values ):
928+ for pt_ind , pt_name in enumerate (mp . downscaled_pts .point_name .values ):
916929
917- ds_pt = ds_down .sel (point_name = pt_name ).copy ()
930+ ds_pt = mp . downscaled_pts .sel (point_name = pt_name ).copy ()
918931
919932
920933 # [ ] Add checking of NaNs in ds_tvt. If NaN present stop process and send ERROR message
@@ -943,7 +956,7 @@ def write_fsm2oshd_met(ds_pt,
943956 namelist_param = namelist_param ,
944957 scaler = forest_param_scaler ) # write forest namelist
945958
946- if cluster_method :
959+ if sampling_method == 'clusters' :
947960 row_open = df_forest .iloc [pt_ind ]
948961 write_fsm2oshd_namelist (row_open ,
949962 pt_ind = pt_ind ,
0 commit comments