Ignore:
Timestamp:
11/15/23 16:41:21 (6 months ago)
Author:
omamce
Message:

O.M. : WATER_BUDGET

Code restructuration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/WATER_BUDGET/CPL_waterbudget.py

    r6665 r6676  
    2828    } 
    2929### 
    30 ## Import system modules 
    31 import sys, os, shutil, subprocess, platform 
    32 import numpy as np 
    33 import configparser, re 
    34 from pathlib import Path 
    35  
    3630### 
    3731## Import system modules 
    38 import sys, os, shutil#, subprocess, platform 
    39 import configparser, re 
     32import sys 
     33import os 
     34import configparser 
    4035 
    4136## Import needed scientific modules 
    42 import numpy as np, xarray as xr 
     37import numpy as np 
     38import xarray as xr 
    4339 
    4440## Import local modules 
    4541import WaterUtils as wu 
    46 import libIGCM_sys 
    4742import nemo, lmdz 
    48  
    49 from WaterUtils import RA, GRAV, ICE_RHO_ICE, ICE_RHO_SNO, OCE_RHO_LIQ, \ 
    50                        ATM_RHO, SRF_RHO, RUN_RHO, ICE_RHO_PND, YEAR_LENGTH 
    51  
    52 ## Creates parser for reading .ini input file 
    53 ## ------------------------------------------- 
    54 config = configparser.ConfigParser ( interpolation=configparser.ExtendedInterpolation() ) 
    55 config.optionxform = str # To keep capitals 
    56  
    57 ## Experiment parameters 
    58 ## --------------------- 
    59 ATM=None ; ATM_HIS='latlon' ; SRF_HIS='latlon' ; RUN_HIS='latlon' ; ORCA=None ; NEMO=None ; OCE_relax=False 
    60 OCE_icb=False ; Coupled=False ; Routing=None ; TestInterp=None 
    61 TarRestartPeriod_beg=None ; TarRestartPeriod_end=None ; Comment=None ; Period=None ; Title=None 
    62 YearBegin=None ; YearEnd=None ; DateBegin=None ; DateEnd=None 
    63  
    64 Timer=False ; Debug=False 
    65 ## 
    66 ARCHIVE=None ; STORAGE=None ; SCRATCHDIR=None ; R_IN=None ; rebuild=None ; TmpDir=None 
    67 FileDir=None ; FileOut=None ; R_OUT=None ; R_FIG=None ; R_FIGR=None ; R_BUFR=None ; R_SAVE=None 
    68 R_BUF_KSH=None ; REBUILD_DIR=None ; POST_DIR=None ; L_EXP=None 
    69  
    70 dir_ATM_his=None ; dir_SRF_his=None ; dir_OCE_his=None ; dir_ICE_his=None 
    71 FileCommon=None ; file_ATM_his=None ; file_SRF_his=None ; file_RUN_his=None 
    72 file_OCE_his=None ;  file_ICE_his=None ; file_OCE_sca=None ; file_OCE_srf=None 
    73 tar_restart_beg=None ; tar_restart_end=None ; file_ATM_beg=None ; file_ATM_end=None ; file_DYN_beg=None 
    74 file_DYN_end=None ; file_SRF_beg=None ; file_SRF_end=None 
    75 file_RUN_beg=None ; file_RUN_end=None ; file_RUN_end=None ; file_OCE_beg=None 
    76 file_ICE_beg=None ; file_OCE_beg=None 
    77 file_OCE_end=None ; file_ICE_beg=None ; file_OCE_end=None ; file_ICE_end=None 
    78 TarRestartDate_beg=None ; TarRestartDate_end=None 
    79 file_DYN_aire=None 
    80 tar_restart_beg_ATM=None ; tar_restart_beg_DYN=None ; tar_restart_beg_SRF=None 
    81 tar_restart_beg_RUN=None ; tar_restart_beg_OCE=None ; tar_restart_beg_ICE=None 
    82 tar_restart_end_ATM=None ; tar_restart_end_DYN=None ; tar_restart_end_SRF=None 
    83 tar_restart_end_RUN=None ; tar_restart_end_OCE=None ; tar_restart_end_ICE=None 
    84 ContinueOnError=False ; ErrorCount=0 
    85 FileDirOCE=None ; FileDirATM=None ; FileDirICE=None ; FileDirSRF=None ; FileDirRUN=None 
    86  
    87 ## 
    88 ## Precision of history file reading 
    89 ## --------------------------------- 
    90 # Default is float (full precision). Degrade the precision by using np.float32 
    91 # Restart files are always read at the full precision 
    92 readPrec=float 
    9343 
    9444## Read command line arguments 
     
    10151    raise FileExistsError ( f"File not found : {IniFile = }" ) 
    10252 
    103 if 'full' in IniFile : FullIniFile = IniFile 
    104 else                 : FullIniFile = 'full_' + IniFile 
    105      
    106 print ("Input file : ", IniFile ) 
    107 config.read (IniFile) 
    108 FullIniFile = 'full_' + IniFile 
    109  
    110 ## Reading config.card if possible 
    111 ## ------------------------------- 
    112 ConfigCard = None 
    113  
    114 if 'Experiment' in config.keys ()  : ## Read Experiment on Config file if possible 
    115     if 'ConfigCard' in config['Experiment'].keys () : 
    116         ConfigCard = config['Experiment']['ConfigCard'] 
    117         print ( f'{ConfigCard=}' ) 
    118  
    119 if ConfigCard : ## Read config card if it exists 
    120     # Text existence of ConfigCard 
    121     if os.path.exists ( ConfigCard ) : 
    122         print ( f'Reading Config Card : {ConfigCard}' ) 
    123         ## Creates parser for reading .ini input file 
    124         MyReader = configparser.ConfigParser (interpolation=configparser.ExtendedInterpolation() ) 
    125         MyReader.optionxform = str # To keep capitals 
    126          
    127         MyReader.read (ConfigCard) 
    128  
    129         for VarName in ['JobName', 'ExperimentName', 'SpaceName', 'LongName', 'ModelName', 'TagName'] : 
    130             if VarName in MyReader['UserChoices'].keys() : 
    131                 locals()[VarName] = MyReader['UserChoices'][VarName] 
    132                 exec  ( f'{VarName} = wu.setBool ({VarName})' ) 
    133                 exec  ( f'{VarName} = wu.setNum  ({VarName})' ) 
    134                 exec  ( f'{VarName} = wu.setNone ({VarName})' ) 
    135                 exec  ( f'wu.{VarName} = {VarName}' ) 
    136                 print ( f'    {VarName:21} set to : {locals()[VarName]:}' ) 
    137                  
    138         for VarName in ['PackFrequency'] : 
    139             if VarName in MyReader['Post'].keys() : 
    140                 locals()[VarName] = MyReader['Post'][VarName] 
    141                 exec  ( f'{VarName} = wu.setBool ({VarName})' ) 
    142                 exec  ( f'{VarName} = wu.setNum  ({VarName})' ) 
    143                 exec  ( f'{VarName} = wu.setNone ({VarName})' ) 
    144                 exec  ( f'wu.{VarName} = {VarName}' ) 
    145                 print ( f'    {VarName:21} set to : {locals()[VarName]:}' ) 
    146     else : 
    147         raise FileExistsError ( f"File not found : {ConfigCard = }" ) 
    148  
    149      
    150 ## Reading config file 
    151 ## ------------------- 
    152 # Each entry in the .ini file will create a Python variable with the same name 
    153 for Section in config.keys () :  
    154     print ( f'\nReading [{Section}]' ) 
    155     for VarName in config[Section].keys() : 
    156         locals()[VarName] = config[Section][VarName] 
    157         exec  ( f'{VarName} = wu.setBool ({VarName})' ) 
    158         exec  ( f'{VarName} = wu.setNum  ({VarName})' ) 
    159         exec  ( f'{VarName} = wu.setNone ({VarName})' ) 
    160         exec  ( f'wu.{VarName} = {VarName}' ) 
    161         print ( f'    {VarName:21} set to : {locals()[VarName]}' ) 
    162  
    163 print ( f'\nConfig file readed : {IniFile} ' ) 
    164  
    165 ## 
    166 ## Reading prec 
    167 if not readPrec  : 
    168     readPrec = np.float64 
     53if 'full' in IniFile or 'ATM' in IniFile : 
     54    FullIniFile = IniFile 
    16955else : 
    170     if readPrec in ["float", "float64", "r8", "double", "<class 'float'>"         ] : readPrec = float 
    171     if readPrec in [         "float32", "r4", "single", "<class 'numpy.float32'>" ] : readPrec = np.float32 
    172     if readPrec in [         "float16", "r2", "half"  , "<class 'numpy.float16'>" ] : readPrec = np.float16 
    173      
    174 # Some physical constants 
    175 ## ======================= 
    176 if not RA           : RA          = wu.RA           #-- Earth Radius (m) 
    177 if not GRAV         : GRAV        = wu.GRAV         #-- Gravity (m^2/s 
    178 if not ICE_RHO_ICE  : ICE_RHO_ICE = wu.ICE_RHO_ICE  #-- Ice volumic mass (kg/m3) in LIM3 
    179 if not ICE_RHO_SNO  : ICE_RHO_SNO = wu.ICE_RHO_SNO  #-- Snow volumic mass (kg/m3) in LIM3 
    180 if not OCE_RHO_LIQ  : OCE_RHO_LIQ = wu.OCE_RHO_LIQ  #-- Ocean water volumic mass (kg/m3) in NEMO 
    181 if not ATM_RHO      : ATM_RHO     = wu.ATM_RHO      #-- Water volumic mass in atmosphere (kg/m^3) 
    182 if not SRF_RHO      : SRF_RHO     = wu.SRF_RHO      #-- Water volumic mass in surface reservoir (kg/m^3) 
    183 if not RUN_RHO      : RUN_RHO     = wu.RUN_RHO      #-- Water volumic mass of rivers (kg/m^3) 
    184 if not ICE_RHO_PND  : ICE_RHO_PND = wu.ICE_RHO_PND  #-- Water volumic mass in ice ponds (kg/m^3) 
    185 if not YEAR_LENGTH   : YEAR_LENGTH  = wu.YEAR_LENGTH   #-- Year length (s) 
    186  
    187 if not 'Files'   in config.keys () : config['Files']   = {} 
    188 if not 'Physics' in config.keys () : config['Physics'] = {} 
    189 if not 'Config'  in config.keys () : config['Physics'] = {} 
    190      
    191  
    192 config['Physics'].update ( { 'RA':str(RA), 'GRAV':str(GRAV), 'ICE_RHO_ICE':str(ICE_RHO_ICE), 'ICE_RHO_SNO':str(ICE_RHO_SNO), 
    193                       'OCE_RHO_LIQ':str(OCE_RHO_LIQ), 'ATM_RHO':str(ATM_RHO), 'SRF_RHO':str(SRF_RHO), 'RUN_RHO':str(RUN_RHO)} ) 
    194  
    195 config['Config'].update ( { 'ContinueOnError':str(ContinueOnError), 'TestInterp':str(TestInterp), 'readPrec':str(readPrec), 
    196                             'Debug':str(Debug), 'Timer':str(Timer) } ) 
    197  
    198 ## -------------------------- 
    199 ICO  = ( 'ICO' in wu.ATM ) 
    200 LMDZ = ( 'LMD' in wu.ATM ) 
    201  
    202 mm = libIGCM_sys.config ( TagName=TagName, SpaceName=SpaceName, ExperimentName=ExperimentName, JobName=JobName, User=User, Group=Group, 
    203              ARCHIVE=ARCHIVE, SCRATCHDIR=SCRATCHDIR, STORAGE=STORAGE, R_IN=R_IN, R_OUT=R_OUT, R_FIG=R_FIG, rebuild=rebuild, TmpDir=TmpDir,  
    204              R_SAVE=R_SAVE, R_FIGR=R_FIGR, R_BUFR=R_BUFR, R_BUF_KSH=R_BUF_KSH, REBUILD_DIR=REBUILD_DIR, POST_DIR=POST_DIR, L_EXP=L_EXP ) 
    205 globals().update(mm) 
    206  
    207 config['Files']['TmpDir'] = TmpDir 
    208 if not 'libIGCM'  in config.keys () : config['libIGCM'] = {} 
    209 config['libIGCM'].update ( { 'ARCHIVE':str(ARCHIVE), 'STORAGE':str(STORAGE), 'TmpDir':str(TmpDir), 'R_IN':str(R_IN), 'rebuild':str(rebuild) } ) 
    210  
    211 ## Debuging and timer 
    212 Timer = wu.functools.partial (wu.Timer, debug=Debug, timer=Timer) 
    213  
    214 ## Defines begining and end of experiment 
    215 ## -------------------------------------- 
    216 if not DateBegin : 
    217     DateBegin = f'{YearBegin}0101' 
    218     config['Experiment']['DateBegin'] = str(DateBegin) 
    219 else : 
    220     YearBegin, MonthBegin, DayBegin = wu.SplitDate ( DateBegin ) 
    221     DateBegin = wu.FormatToGregorian (DateBegin) 
    222     config['Experiment']['YearBegin'] = str(YearBegin) 
    223  
    224 if not DateEnd : 
    225     DateEnd   = f'{YearEnd}1231' 
    226     config['Experiment']['DateEnd'] = str(DateEnd) 
    227 else : 
    228     YearEnd, MonthEnd, DayEnd = wu.SplitDate ( DateEnd ) 
    229     DateEnd   = wu.FormatToGregorian (DateEnd) 
    230     config['Experiment']['DateEnd'] = str(DateEnd) 
    231  
    232 if not PackFrequency :  
    233     PackFrequency = YearEnd - YearBegin + 1 
    234     config['Experiment']['PackFrequency']   = f'{PackFrequency}' 
    235  
    236 if type ( PackFrequency ) == str :  
    237     if 'Y' in PackFrequency : PackFrequency = PackFrequency.replace ( 'Y', '')  
    238     if 'M' in PackFrequency : PackFrequency = PackFrequency.replace ( 'M', '') 
    239     PackFrequency = int ( PackFrequency ) 
    240      
     56    FullIniFile = 'ATM_' + IniFile 
     57 
     58print ("Output file : ", FullIniFile ) 
     59 
     60## Experiment parameters 
     61## -------------------- 
     62dpar = wu.ReadConfig ( IniFile ) 
     63 
     64## Configure all needed parameter from existant parameters 
     65## ------------------------------------------------------- 
     66dpar = wu.SetDatesAndFiles ( dpar ) 
     67 
    24168## Output file with water budget diagnostics 
    24269## ----------------------------------------- 
    243 if not FileOut : 
    244     FileOut = f'CPL_waterbudget_{JobName}_{YearBegin}_{YearEnd}' 
    245     if ICO :  
    246         if ATM_HIS == 'latlon' : FileOut = f'{FileOut}_LATLON' 
    247         if ATM_HIS == 'ico'    : FileOut = f'{FileOut}_ICO' 
    248     if readPrec == np.float32  : FileOut = f'{FileOut}_float32' 
    249     FileOut = f'{FileOut}.out' 
    250  
    251 config['Files']['FileOut'] = FileOut 
    252  
    253 f_out = open ( FileOut, mode = 'w' ) 
    254      
     70f_out = dpar['Files']['f_out'] 
     71 
     72## Put dpar values in local namespace 
     73## ---------------------------------- 
     74for Section in dpar.keys () :  
     75    print ( f'\nReading [{Section}]' ) 
     76    for VarName in dpar[Section].keys() : 
     77        locals()[VarName] = dpar[Section][VarName] 
     78        print ( f'    {VarName:21} set to : {locals()[VarName]}' ) 
     79         
     80## Debuging and timer 
     81Timer = wu.functools.partial (wu.Timer, debug=Debug, timer=Timing) 
     82    
    25583## Useful functions 
    25684## ---------------- 
     
    299127    return None 
    300128 
    301 echo ( f'{ContinueOnError = }' ) 
    302 echo ( f'{readPrec        = }' ) 
    303  
    304 echo ( f'{JobName         = }' ) 
    305 echo ( f'{ConfigCard      = }' ) 
    306 echo ( f'{libIGCM         = }' )      
    307 echo ( f'{User            = }' )        
    308 echo ( f'{Group           = }' )        
    309 echo ( f'{Freq            = }' )        
    310 echo ( f'{YearBegin       = }' )      
    311 echo ( f'{YearEnd         = }' )      
    312 echo ( f'{DateBegin       = }' ) 
    313 echo ( f'{DateEnd         = }' ) 
    314 echo ( f'{PackFrequency   = }' )  
    315 echo ( f'{ATM             = }' )        
    316 echo ( f'{Routing         = }' )        
    317 echo ( f'{ORCA            = }' )       
    318 echo ( f'{NEMO            = }' )       
    319 echo ( f'{Coupled         = }' )       
    320 echo ( f'{ATM_HIS         = }' )       
    321 echo ( f'{SRF_HIS         = }' )       
    322 echo ( f'{RUN_HIS         = }' ) 
    323  
    324 ## Set libIGCM directories 
    325 ## ----------------------- 
    326 if not R_OUT       : R_OUT       = os.path.join ( ARCHIVE   , 'IGCM_OUT' ) 
    327 if not R_BUF       : R_BUF       = os.path.join ( SCRATCHDIR, 'IGCM_OUT' ) 
    328 if not L_EXP       : L_EXP       = os.path.join (TagName, SpaceName, ExperimentName, JobName) 
    329 if not R_SAVE      : R_SAVE      = os.path.join ( R_OUT, L_EXP ) 
    330 if not R_BUFR      : R_BUFR      = os.path.join ( R_BUF, L_EXP ) 
    331 if not POST_DIR    : POST_DIR    = os.path.join ( R_BUFR, 'Out' ) 
    332 if not REBUILD_DIR : REBUILD_DIR = os.path.join ( R_BUFR, 'REBUILD' ) 
    333 if not R_BUF_KSH   : R_BUF_KSH   = os.path.join ( R_BUFR, 'Out' ) 
    334 if not R_FIGR      : R_FIGR      = os.path.join ( STORAGE, 'IGCM_OUT', L_EXP ) 
    335  
    336 config['libIGCM'].update ( { 'R_OUT':R_OUT, 'R_BUF':R_BUF, 'L_EXP':L_EXP, 'R_BUFR':R_BUFR, 'R_SAVE':R_SAVE, 'POST_DIR':POST_DIR, 
    337                              'REBUILD_DIR':REBUILD_DIR, 'R_BUF_KSH':R_BUF_KSH, 'R_FIGR':R_FIGR, 'rebuild':rebuild, 
    338                              'YEAR_LENGTH':str(YEAR_LENGTH)} ) 
    339  
    340 ## Set directory to extract files 
    341 ## ------------------------------ 
    342 if not FileDir : FileDir = os.path.join ( TmpDir, f'WATER_{JobName}' ) 
    343 config['Files']['FileDir'] = FileDir 
    344  
    345 if not os.path.isdir ( FileDir ) : os.makedirs ( FileDir ) 
    346  
    347 ##- Set directories to rebuild ocean and ice restart files 
    348 if not FileDirOCE : FileDirOCE = os.path.join ( FileDir, 'OCE' ) 
    349 if not FileDirICE : FileDirICE = os.path.join ( FileDir, 'ICE' ) 
    350 if not os.path.exists ( FileDirOCE ) : os.mkdir ( FileDirOCE ) 
    351 if not os.path.exists ( FileDirICE ) : os.mkdir ( FileDirICE ) 
    352  
    353 echo (' ') 
    354 echo ( f'JobName     : {JobName}'    ) 
    355 echo ( f'Comment     : {Comment}'    ) 
    356 echo ( f'TmpDir      : {TmpDir}'     ) 
    357 echo ( f'FileDir     : {FileDir}'    ) 
    358 echo ( f'FileDirOCE  : {FileDirOCE}' ) 
    359 echo ( f'FileDirICE  : {FileDirICE}' ) 
    360  
    361 echo ( f'\nDealing with {L_EXP}'  ) 
    362  
    363 echo (' ') 
    364 echo ( f'JobName   : {JobName}'   ) 
    365 echo ( f'Comment   : {Comment}'   ) 
    366 echo ( f'TmpDir    : {TmpDir}'    ) 
    367  
    368 echo ( f'\nDealing with {L_EXP}'  ) 
    369  
    370 ## Creates model output directory names 
    371 ## ------------------------------------ 
    372 if Freq == "MO" : FreqDir =  os.path.join ('Output' , 'MO' ) 
    373 if Freq == "SE" : FreqDir =  os.path.join ('Analyse', 'SE' ) 
    374 if dir_ATM_his == None : 
    375     dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir ) 
    376     config['Files']['dir_ATM_his'] = dir_ATM_his 
    377 if SRF :  
    378     if dir_SRF_his == None :  
    379         dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir ) 
    380         config['Files']['dir_SRF_his'] = dir_SRF_his 
    381 if dir_OCE_his == None : 
    382     dir_OCE_his = os.path.join ( R_SAVE, "OCE", FreqDir ) 
    383     config['Files']['dir_OCE_his'] = dir_OCE_his 
    384 if dir_ICE_his == None :  
    385     dir_ICE_his = os.path.join ( R_SAVE, "ICE", FreqDir ) 
    386     config['Files']['dir_ICE_his'] = dir_ICE_his 
    387  
    388 echo ( f'The analysis relies on files from the following model output directories : ' ) 
    389 echo ( f'{dir_ATM_his}' ) 
    390 echo ( f'{dir_OCE_his}' ) 
    391 echo ( f'{dir_ICE_his}' ) 
    392 if SRF :  
    393     echo ( f'{dir_SRF_his}' ) 
    394  
    395 ##-- Creates files names 
    396 if not Period : 
    397     if Freq == 'MO' : Period = f'{DateBegin}_{DateEnd}_1M' 
    398     if Freq == 'SE' : Period = f'SE_{DateBegin}_{DateEnd}_1M' 
    399     config['Files']['Period'] = Period 
    400  
    401 config['Files']['DateBegin'] = DateBegin 
    402 config['Files']['DateBegin'] = DateEnd 
    403  
    404 echo ( f'Period   : {Period}' ) 
    405  
    406 if not FileCommon : 
    407     FileCommon = f'{JobName}_{Period}' 
    408     config['Files']['FileCommon'] = FileCommon 
    409  
    410 if not Title : 
    411     Title = f'{JobName} : {Freq} : {DateBegin} - {DateEnd}' 
    412     config['Files']['Title'] = Title 
    413 echo ('\nOpen history files' ) 
    414 if not file_ATM_his : 
    415     if ATM_HIS == 'latlon' : 
    416         file_ATM_his = os.path.join ( dir_ATM_his, f'{FileCommon}_histmth.nc' ) 
    417     if ATM_HIS == 'ico' : 
    418         file_ATM_his = os.path.join ( dir_ATM_his, f'{FileCommon}_histmth_ico.nc' ) 
    419     config['Files']['file_ATM_his'] = file_ATM_his 
    420 if SRF :  
    421     if not file_SRF_his : 
    422         if ATM_HIS == 'latlon' : 
    423             file_SRF_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history.nc' ) 
    424         if ATM_HIS == 'ico' : 
    425             file_SRF_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history_ico.nc' ) 
    426         config['Files']['file_SRF_his'] = file_SRF_his 
    427  
    428     if Routing == 'SIMPLE' : 
    429         if file_RUN_his == None : 
    430             if ATM_HIS == 'latlon' : 
    431                 file_RUN_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history.nc' ) 
    432             if ATM_HIS == 'ico' : 
    433                 file_RUN_his = os.path.join ( dir_SRF_his, f'{FileCommon}_sechiba_history_ico.nc' ) 
    434             config['Files']['file_RUN_his'] = file_RUN_his 
    435  
    436 echo ( f'{file_ATM_his = }' ) 
    437 if SRF :  
    438     echo ( f'{file_SRF_his = }' ) 
    439     if Routing == 'SIMPLE' : echo ( f'{file_RUN_his = }' ) 
     129 
     130 
    440131         
    441132d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() 
     
    444135    if Routing == 'SECHIBA' : d_RUN_his = d_SRF_his 
    445136    if Routing == 'SIMPLE'  : d_RUN_his = xr.open_dataset ( file_RUN_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() 
    446      
    447 if not file_OCE_his : 
    448     file_OCE_his = os.path.join ( dir_OCE_his, f'{FileCommon}_grid_T.nc' ) 
    449     file_OCE_his = file_OCE_his 
    450 if not file_OCE_sca :     
    451     file_OCE_sca = os.path.join ( dir_OCE_his, f'{FileCommon}_scalar.nc' ) 
    452     config['Files']['file_OCE_sca'] = file_OCE_sca 
    453 if not file_OCE_srf :     
    454     file_OCE_srf = os.path.join ( dir_OCE_his, f'{FileCommon}_sbc.nc' ) 
    455     config['Files']['file_OCE_srf'] = file_OCE_srf 
    456 if not file_ICE_his :  
    457     file_ICE_his = os.path.join ( dir_ICE_his, f'{FileCommon}_icemod.nc' ) 
    458     config['Files']['file_ICE_his'] = file_ICE_his 
    459137 
    460138d_OCE_his = xr.open_dataset ( file_OCE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze() 
     
    486164 
    487165## Write the full configuration 
    488 config_out = open (FullIniFile, 'w') 
    489 config.write (config_out ) 
    490 config_out.close () 
     166## ---------------------------- 
     167params_out = open (FullIniFile, 'w', encoding = 'utf-8') 
     168params = wu.dict2config ( dpar ) 
     169params.write ( params_out ) 
     170params_out.close () 
    491171 
    492172# ATM grid with cell surfaces 
     
    645325# Get mask and surfaces 
    646326sos = d_OCE_his ['sos'][0].squeeze() 
    647 OCE_msk = nemo.lbc_mask ( xr.where ( sos>0, 1., 0.0 ), cd_type = 'T' ) 
     327OCE_msk = nemo.lbc_mask ( xr.where ( sos>0, 1., 0.0 ), cd_type = 'T', nperio=nperio ) 
    648328so = sos = d_OCE_his ['sos'][0].squeeze() 
    649 OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', sval = 0. ) 
     329OCE_msk3 = nemo.lbc_mask ( xr.where ( so>0., 1., 0. ), cd_type = 'T', sval = 0., nperio=nperio ) 
    650330 
    651331# lbc_mask removes the duplicate points (periodicity and north fold) 
    652 OCE_aire = nemo.lbc_mask ( d_OCE_his ['area'] * OCE_msk, cd_type = 'T', sval = 0.0 ) 
     332OCE_aire = nemo.lbc_mask ( d_OCE_his ['area'] * OCE_msk, cd_type = 'T', sval = 0.0, nperio=nperio ) 
    653333ICE_aire = OCE_aire 
    654334 
     
    722402    ATM_wsnow_sic   = rprec (d_ATM_his ['wsnow_sic']) 
    723403    echo ( f'End of ico case ') 
    724  
    725  
    726404     
    727405echo ( 'ATM wprecip_oce' ) 
     
    1023701for kk in SVN.keys(): 
    1024702    print ( SVN[kk] ) 
     703 
     704## Write the full configuration 
     705## ---------------------------- 
     706params_out = open (FullIniFile, 'w', encoding = 'utf-8') 
     707params = wu.dict2config ( dpar ) 
     708params.write ( params_out ) 
     709params_out.close () 
Note: See TracChangeset for help on using the changeset viewer.