Skip to content

Commit

Permalink
Do not throw errors on unknown headers in carpet_grid_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Jun 1, 2021
1 parent 2a4a73f commit 2831c40
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ Movies:

* `grid_var`

#### Bug fixes
- Fixed header recognition for `carpet-grid.asc` (#22)

#### Features

- New methods `get_apparent_horizon` and `get_qlm_horizon` in `HorizonsDir`.
Expand Down
58 changes: 30 additions & 28 deletions kuibit/cactus_grid_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,36 +1406,38 @@ def __init__(self, allfiles, dimension, num_ghost=None):
# These would be matched here, so we will exclude the case in
# which the thorn name is volume_integrals and the var name
# is vacuum or GRMHD.
thorn_name = matched_ascii.group(2)
var_name = matched_ascii.group(3)
if thorn_name == "volume_integrals" and (
var_name in ("GRMHD", "vacuum")
):
continue

# TODO (FEATURE): Avoid reading headers twice
#
# Here we scan the headers, we should not do this work again
# when we deal with the single variables.

# The last group is where compression information is. It
# could be None.
compression_method = matched_ascii.groups()[-1]
opener, opener_mode = OneGridFunctionASCII._decompressor[
compression_method
]
_, column_description = scan_header(
f,
one_file_per_group=True,
extended_format=True,
opener=opener,
opener_mode=opener_mode,
)
for variable_name in column_description.keys():
var_list = self._vars_ascii.setdefault(
variable_name, set()
# Same with the file carpet-grid.asc
#
# To deal with all of these, we wrap everything in a try
# except block, and keep only the variables that do not
# throw errors.
try:
# TODO (FEATURE): Avoid reading headers twice
#
# Here we scan the headers, we should not do this work again
# when we deal with the single variables.

# The last group is where compression information is. It
# could be None.
compression_method = matched_ascii.groups()[-1]
opener, opener_mode = OneGridFunctionASCII._decompressor[
compression_method
]
_, column_description = scan_header(
f,
one_file_per_group=True,
extended_format=True,
opener=opener,
opener_mode=opener_mode,
)
var_list.add(f)
for variable_name in column_description.keys():
var_list = self._vars_ascii.setdefault(
variable_name, set()
)
var_list.add(f)
except RuntimeError:
pass

# What pythonize_name_dict does is to make the various variables
# accessible as attributes, e.g. self.fields.rho
Expand Down

0 comments on commit 2831c40

Please sign in to comment.