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

Check if experiment_id attribute is present in current dataset when being processed by PrePARE #644

Merged
merged 2 commits into from
Jan 24, 2022

Conversation

mauzey1
Copy link
Collaborator

@mauzey1 mauzey1 commented Jan 21, 2022

Fixes #643

Copy link
Contributor

@durack1 durack1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mauzey1 thanks for catching this - @matthew-mizielinski are there any other obvious tweaks you suggest?

Copy link
Collaborator

@piotr-florek-mohc piotr-florek-mohc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@piotr-florek-mohc
Copy link
Collaborator

Just a quick note, this fix doesn't appear to resolve the whole issue raised in #643 entirely (at least it didn't do it for me), as there are other problems with the netCDF file, which cmor to fail because of weird characters appearing in the log file. The quick fix, as commented by @matthew.mizielinski, is to provide encoding parameter to the PrePARE.py script.

diff --git a/LibCV/PrePARE/PrePARE.py b/LibCV/PrePARE/PrePARE.py
index 6fcd570..97f1c9e 100755
--- a/LibCV/PrePARE/PrePARE.py
+++ b/LibCV/PrePARE/PrePARE.py
@@ -931,7 +931,7 @@ def main():
         remove_ansi = re.compile(r'\x1b\[[0-?]*[ -/]*[@-~]')
         for logfile in set(logfiles):
             if not os.stat(logfile).st_size == 0:
-                with open(logfile, 'r') as f:
+                with open(logfile, 'r', encoding='utf8', errors='ignore') as f:
                     log_text = f.read()
                     if args.no_text_color:
                         log_text = remove_ansi.sub('', log_text)
@@ -955,7 +955,7 @@ def main():
             logfile, rc = process(source)
             errors += rc
             if not os.stat(logfile).st_size == 0:
-                with open(logfile, 'r') as f:
+                with open(logfile, 'r', encoding='utf8', errors='ignore') as f:
                     log_text = f.read()
                     if args.no_text_color:
                         log_text = remove_ansi.sub('', log_text)

@mauzey1
Copy link
Collaborator Author

mauzey1 commented Jan 24, 2022

@piotr-florek-mohc

Okay, I have added the suggested changes to PrePARE. I would still like to keep finding bugs in CMOR_CV code similar to the ones I have found, but this will at least reduce the chances of PrePARE crashing when processing erroneous NetCDF files.

@durack1
Copy link
Contributor

durack1 commented Jan 24, 2022

@mauzey1 @piotr-florek-mohc (and @matthew-mizielinski) thanks for this tweak!

@mauzey1
Copy link
Collaborator Author

mauzey1 commented Jan 24, 2022

The MacOS Python 3.9 check failed due to a server error with conda. The last change committed would not have affected the tests anyway. I will merge this now.

@mauzey1 mauzey1 merged commit ea62700 into master Jan 24, 2022
@mauzey1 mauzey1 deleted the 643_prepare_unicode_error branch January 24, 2022 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PrePARE UnicodeDecodeError when scanning dummy NO_ATTRIBUTES.nc netCDF file
3 participants