Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR #3424 on branch yt-4.0.x (implement AthenaDataset._is_valid) #3572

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions yt/frontends/athena/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import weakref

import numpy as np
Expand Down Expand Up @@ -632,12 +633,18 @@ def _parse_parameter_file(self):

@classmethod
def _is_valid(cls, filename, *args, **kwargs):
try:
if "vtk" in filename:
return True
except Exception:
pass
return False
if not filename.endswith(".vtk"):
return False

with open(filename, "rb") as fh:
if not re.match(b"# vtk DataFile Version \\d\\.\\d\n", fh.readline(256)):
return False
if not re.match(
b"(CONSERVED|PRIMITIVE) vars at time= .*, level= \\d, domain= \\d\n",
fh.readline(256),
):
return False
return True

@property
def _skip_cache(self):
Expand Down