U ­âgÖã@sDdd„Zdd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„ZdS)cCs| ¡}|dkrd}nd}|S)zÊ isTrue(str_in) - function to translate shell variables to python logical variables input: str_in - string (should be like 'YES', 'TRUE', etc.) returns: status (logical True or False) )ZYESz.TRUE.TF)Úupper)Zstr_inÚstatus©rú7/lfs/h1/ops/prod/packages/gfs.v16.3.23/ush/gsi_utils.pyÚisTrues rcCshddl}|j |¡sd|j |¡s.| ||¡n"t|dƒ| |¡| ||¡td|d|ƒdS)z¯ link_file(from_file, to_file) - function to check if a path exists, and if not, make a symlink input: from_file - string path to_file - string path éNz exists, unlinking.zln -s ú )ÚosÚpathÚexistsÚislinkÚsymlinkÚprintÚunlink)Ú from_fileÚto_filerrrrÚ link_files     rcCs,ddl}| ||¡td|d|ƒdS)Nrzcp r)ÚshutilÚcopyr )rrrrrrÚ copy_file$s rcCs"ddl}| |¡td|ƒdS)Nrz mkdir -p )rÚmakedirsr )Z directoryrrrrÚmake_dir)s rcCsxt|dƒ}| ¡D]X\}}| d|d¡| ¡D]*\}}| dt|ƒdt|ƒd¡q4| d¡q| ¡dS)aw write_nml(nml_dict, nml_file) - function to write out namelist dictionary nml_dict to file nml_file input: nml_dict - dictionary of dictionaries first dictionary is &nml, second is nmlvar='value' NOTE: this shoudl be an OrderedDict or else it might fail nml_file - string path to write namelist file to Úwú&Ú z z = z/ N)ÚopenÚitemsÚwriteÚstrÚclose)Znml_dictZnml_fileZnfileZnmlZnmlvarsÚvarÚvalrrrÚ write_nml.s $ r!cCsŠz ddl}Wn<tk rHtdƒtdƒtdƒtdƒtdƒYnX| |¡}i}|j ¡D]}tt|j|ƒƒ||<qb| ¡|S)aY get_ncdims(ncfile) - function to return dictionary of netCDF file dimensions and their lengths input: ncfile - string to path to netCDF file output: ncdims - dictionary where key is the name of a dimension and the value is the length of that dimension ex: ncdims['pfull'] = 127 rNú Python Error!úanetCDF4 Python module not available. Do you have the proper Python available in your environment?úFHera: module use -a /contrib/modulefiles && module load anaconda/2.3.0úDell: module load python/3.6.3r) ÚnetCDF4Ú ImportErrorr ÚDatasetZ dimensionsÚkeysÚintÚlenr)ÚncfileÚncÚncfÚncdimsÚdrrrÚ get_ncdims@s   r1c Csjddl}ddddœ}i}dD]H}|j|||g|j|jd}| ¡\}}t| d¡d  ¡ƒ|||<q|S) a— get_nemsdims(nemsfile,nemsexe) - function to return dictionary of NEMSIO file dimensions for use input: nemsfile - string to path nemsio file nemsexe - string to path nemsio_get executable output: nemsdims - dictionary where key is the name of a dimension and the value is the length of that dimension ex: nemsdims['pfull'] = 127 rNZgrid_xtZgrid_ytZpfull)ZdimxZdimyZdimz)ÚstdoutÚstderrréÿÿÿÿ)Ú subprocessÚPopenÚPIPEZSTDOUTZ communicater*ÚsplitÚrstrip) ZnemsfileZnemsexer5r/ZnemsdimsZdimÚoutr2r3rrrÚ get_nemsdimsYs ý  r;c CsÖz ddl}Wn<tk rHtdƒtdƒtdƒtdƒtdƒYnXddl}ddl}| |¡}|dj}| d ¡d }| d d |¡}|dd …}|j  |d¡}t |ddƒ} ||j | d} |  ¡|| | fS)zý get_timeinfo(ncfile) - function to return datetime objects of initialized time and valid time input: ncfile - string to path to netCDF file returns: inittime, validtime - datetime objects nfhour - integer forecast hour rNr"r#r$r%rÚtimezsince éz[^0-9]Úé z%Y%m%d%H)Zhours) r&r'r ZdatetimeÚrer(Zunitsr8ÚsubÚstrptimer*Z timedeltar) r,r-Zdtr@r.Z time_unitsZdate_strZinitstrZinittimeZnfhourZ validtimerrrÚ get_timeinfoos(    rCN)rrrrr!r1r;rCrrrrÚs