Skip to content

Commit

Permalink
add show_vars for tab() - this could make plot1d mirror the way we do…
Browse files Browse the repository at this point in the history
… plot1d
  • Loading branch information
teuben committed Aug 25, 2023
1 parent 08d9cfc commit debcaf6
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions athena_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def error_dat(filename, **kwargs):


# Read .tab files and return dict.
def tab(filename):
def tab(filename, show_vars=False):

# Parse header
data_dict = {}
Expand All @@ -45,8 +45,6 @@ def tab(filename):
attributes = re.search(r'time=(\S+)\s+cycle=(\S+)', line)
line = data_file.readline()
headings = line.split()[1:]
data_dict['time'] = float(attributes.group(1))
data_dict['cycle'] = int(attributes.group(2))
headings = headings[1:]

# Go through lines
Expand Down Expand Up @@ -76,11 +74,17 @@ def tab(filename):
data_array = np.transpose(np.reshape(data_array, array_shape),
array_transpose)



# Finalize data
for n, heading in enumerate(headings):
if check_nan_flag:
check_nan(data_array[n, ...])
data_dict[heading] = data_array[n, ...]
if show_vars:
return list(data_dict.keys())
data_dict['time'] = float(attributes.group(1))
data_dict['cycle'] = int(attributes.group(2))
return data_dict


Expand Down Expand Up @@ -199,7 +203,7 @@ def bin(filename, show_vars=False, **kwargs):
num_variables_base = len(variable_names_base)
if show_vars:
return variable_names_base
print("variable_names_base: ", variable_names_base)
# print("variable_names_base: ", variable_names_base)

if True:
variable_name = kwargs['variable']
Expand Down Expand Up @@ -332,7 +336,7 @@ def bin(filename, show_vars=False, **kwargs):
# Extract quantity without derivation
quantity = quantities[variable_name]

print("PJT",num_blocks_used,quantity.shape)
# print("PJT",num_blocks_used,quantity.shape)

if kwargs['output_file'] == None:
if num_blocks_used == 1:
Expand Down Expand Up @@ -437,7 +441,12 @@ class AthenaError(RuntimeError):
kwargs['output_file'] = 'show'
# kwargs['output_file'] = None

print(bin(sys.argv[1],True))

d = bin(sys.argv[1],False,**kwargs)
print('data',d)
if False:
print(bin(sys.argv[1],True))
d = bin(sys.argv[1],False,**kwargs)
print('data',d)
else:
print(tab(sys.argv[1],True))
d = tab(sys.argv[1],False)
print('data',d)

0 comments on commit debcaf6

Please sign in to comment.