Skip to content

Commit 5ef672e

Browse files
committed
FEAT: Post processor improvements! Including:
- NetCDF/hdf5 python packages are optional. matplotlib is still mandatory though - Look in pwd & pwd/UA/output (lets you postproc from run/) - Add arg to set path to output files
1 parent 3f3fa44 commit 5ef672e

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

srcPython/postAether.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010
import matplotlib.cm as cm
11-
from netCDF4 import Dataset
12-
from h5py import File
1311
import argparse
1412
import os
1513
import json
@@ -36,6 +34,9 @@ def parse_args():
3634
parser.add_argument('-oned', \
3735
help='strip 1d files of ghostcells and store in one file', \
3836
action="store_true")
37+
parser.add_argument('-dir', default=None, type=str,
38+
help="Directory to find Aether files in. Will look in current"
39+
" directory & $PWD/UA/output/")
3940

4041
args = parser.parse_args()
4142

@@ -544,6 +545,13 @@ def get_base_files():
544545
IsFound, item = if_unique(ensembleFiles, fileInfo['ensembleFile'])
545546
if (IsFound):
546547
filesInfo[i]['ensembleMembers'] = ensembleCounter[item]
548+
549+
if len(filesInfo) == 0:
550+
try:
551+
os.chdir("UA/output")
552+
get_base_files()
553+
except:
554+
print("No input files found!!")
547555

548556
return filesInfo
549557

@@ -948,18 +956,33 @@ def write_and_plot_data(dataToWrite,
948956
# main code
949957
#----------------------------------------------------------------------------
950958

951-
if __name__ == '__main__': # main code block
959+
def main(args):
952960

953-
args = parse_args()
954961
isVerbose = args.v
962+
963+
if args.dir:
964+
if isVerbose:
965+
print("changing directory to: ", args.dir)
966+
os.chdir(args.dir)
955967

956968
filesInfo = get_base_files()
969+
970+
if len(filesInfo) == 0:
971+
return
957972

958973
iVar = 3
959974
iAlt = args.alt
960975

961976
output_netcdf = False if args.hdf5 else True
962-
977+
978+
if filesInfo[0]['isNetCDF']:
979+
try:
980+
from netCDF4 import Dataset
981+
from h5py import File
982+
except InputError:
983+
raise InputError(
984+
"Attempting to postprocess NetCDF files, but NetCDF is not installed for Python")
985+
963986
for iFile, fileInfo in enumerate(filesInfo):
964987
coreFile = fileInfo['coreFile']
965988
isNetCDF = fileInfo['isNetCDF']
@@ -1004,4 +1027,12 @@ def write_and_plot_data(dataToWrite,
10041027
if (isVerbose):
10051028
print(' ', command)
10061029
os.system(command)
1007-
1030+
1031+
# call main:
1032+
if __name__ == '__main__':
1033+
1034+
args = parse_args()
1035+
1036+
# This allows code to cleanly exit on error
1037+
main(args)
1038+

0 commit comments

Comments
 (0)