3030
3131# from pyremo.core.remo_ds import update_meta_info
3232
33+ # required variables for initial conditions:
34+
35+ # ['T', 'U', 'V', 'PS', 'RF', 'QW', 'QD', 'QDBL', 'PSEH', 'TSW', 'TSI', 'SEAICE', 'DTPB',
36+ # 'TSL', 'TSN', 'TD3', 'TD4', 'TD5', 'TD', 'TDCL', 'WS', 'WL', 'SN',
37+ # 'FIB', 'BLA', 'AZ0', 'ALB', 'VGRAT', 'VAROR', 'VLT',
38+ # 'FOREST', 'FAO', 'WSMX', 'BETA', 'WMINLOK', 'WMAXLOK', 'TSLEH', 'GLAC']
3339
3440xr .set_options (keep_attrs = True )
3541
@@ -668,7 +674,7 @@ def update_soil_temperatures(ds):
668674 return ds
669675
670676
671- def create_initial_soil (ds , domain_info , surflib ):
677+ def remap_era5_soil (ds , domain_info , surflib ):
672678 """Create initial soil dataset from atmospheric dataset."""
673679 # rename vertical coordinate of input to avoid conflict with output lev
674680 ds = ds .copy ()
@@ -688,13 +694,16 @@ def create_initial_soil(ds, domain_info, surflib):
688694 # broadcast 1d global coordinates
689695 lamgm , phigm = broadcast_coords (ds )
690696
697+ print ("getting matrix" )
691698 # compute remap matrix
692699 indii , indjj = intersect (lamgm , phigm , lamem , phiem ) # .compute()
693700
701+ print ("remapping" )
694702 # horizontal interpolation
695703 wsge = interpolate_horizontal (
696704 wsgm , lamem , phiem , lamgm , phigm , "WS" , indii = indii , indjj = indjj
697705 )
706+
698707 td3ge = interpolate_horizontal (
699708 ds .tsl1 , lamem , phiem , lamgm , phigm , "TD3" , indii = indii , indjj = indjj
700709 )
@@ -707,24 +716,46 @@ def create_initial_soil(ds, domain_info, surflib):
707716 tdge = interpolate_horizontal (
708717 ds .tsl4 , lamem , phiem , lamgm , phigm , "TD" , indii = indii , indjj = indjj
709718 )
710- snge = interpolate_horizontal (
719+ snem = interpolate_horizontal (
711720 ds .snd , lamem , phiem , lamgm , phigm , "SN" , indii = indii , indjj = indjj
712721 )
713- wlge = interpolate_horizontal (
722+ wlem = interpolate_horizontal (
714723 ds .src , lamem , phiem , lamgm , phigm , "WL" , indii = indii , indjj = indjj
715724 )
725+ fibge = interpolate_horizontal (
726+ ds .orog , lamem , phiem , lamgm , phigm , "FIB" , indii = indii , indjj = indjj
727+ )
728+ tslge = interpolate_horizontal (
729+ ds .skt , lamem , phiem , lamgm , phigm , "TSL" , indii = indii , indjj = indjj
730+ )
731+
716732 tswge = remap_sst (
717733 ds .tos ,
718734 lamem ,
719735 phiem ,
720736 lamgm ,
721737 phigm ,
722- blagm = xr .where (ds .tos .isel (time = 0 ).isnull (), 1.0 , 0.0 ),
738+ blagm = xr .where (
739+ ds .tos .isel (time = 0 ).isnull () if "time" in ds else ds .tos .isnull (), 1.0 , 0.0
740+ ),
723741 blaem = blaem ,
724742 )
725- soil = xr .merge ([wsge , td3ge , td4ge , td5ge , tdge , snge , wlge , tswge ])
743+
744+ wsmxem = surflib .WSMX .squeeze (drop = True )
745+ wsem = np .minimum (wsmxem , wsge * wsmxem )
746+
747+ # Initialize temperatures
748+ tslem , tswem , tsnem , td3em , td4em , td5em , tdem , tdclem = (
749+ physics .adapt_soil_temperatures (
750+ tdge , tswge , tslge , td3ge , td4ge , td5ge , fibem , fibge , blaem
751+ )
752+ )
753+
754+ soil = xr .merge (
755+ [tslem , tswem , tsnem , td3em , td4em , td5em , tdem , tdclem , wlem , snem , wsem ]
756+ )
726757 soil .attrs ["history" ] = "preprocessing with pyremo = {}" .format (pr .__version__ )
727- soil .attrs ["domain_id" ] = domain_info .get ("domain_id" , "no name " )
758+ soil .attrs ["domain_id" ] = domain_info .get ("domain_id" , "UNKNOWNs " )
728759
729760 soil = update_attrs (soil )
730761
0 commit comments