-
Notifications
You must be signed in to change notification settings - Fork 276
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
Ramses read namelist #2347
Ramses read namelist #2347
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
with open(namelist_file, 'r') as f: | ||
nml = f90nml.read(f) | ||
except ImportError as e: | ||
nml = "An error occurred when reading the namelist: %s" % str(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make this an exception of some type, we might be more easily able to determine if it's the success or not, with an isinstance
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand your comment.
However, the reason I settled for this is that reading namelist.nml
is not required to properly load the simulation, so I was trying to avoid throwing errors at the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NBD, just thought if we had an object we could check if it read correctly without doing a string comparison. I agree about not throwing errors!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still confused ; where do you see a string comparison? Here I am storing the content of the namelist in ds.parameters['namelist']
. If we're missing the f90nml
package, I store the error message instead.
That is probably not the best solution though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant -- let's pretend I wanted to know if the namelist had been parsed. I could do that with an isinstance
or I could check the contents of the string, right? Or is it only going to be an instance of str
if it succeeds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are three cases:
- the file does not exists:
ds.parameters['namelist']
is left unitialized, - the file exists and
f90nml
is missing:ds.parameters['namelist']
then contains the error message as a string, - the file exists and
f90nml
is installed:ds.parameters['namelist']
is a dict-like structure with the content of the namelist.
Any idea to make it better is welcome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So right now if I wanted to see if the namelist was parsed, I wouldn't have a proper way of doing it except checking isinstance(ds.parameters['namelist'], str)
.
Nah, this looks great to me!
…On Fri, Oct 18, 2019 at 10:12 AM Corentin Cadiou ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In yt/frontends/ramses/data_structures.py
<#2347 (comment)>:
> @@ -582,6 +583,21 @@ def read_rhs(f, cast):
if self.num_groups > 0:
self.group_size = rheader['ncpu'] // self.num_groups
+ # Read namelist.txt file (if any)
+ self.read_namelist()
+
+ def read_namelist(self):
+ """Read the namelist.txt file in the output folder, if present"""
+ namelist_file = os.path.join(self.root_folder, 'namelist.txt')
+ if os.path.exists(namelist_file):
+ try:
+ with open(namelist_file, 'r') as f:
+ nml = f90nml.read(f)
+ except ImportError as e:
+ nml = "An error occurred when reading the namelist: %s" % str(e)
There are three cases:
1. the file does not exist and ds.parameters['namelist'] does not
exist,
2. the file exists and f90nml is missing: ds.parameters['namelist']
then contains the error message as a string,
3. the file exists and f90nml is installed: ds.parameters['namelist']
is a dict-like structure with the content of the namelist.
Any idea to make it better is welcome!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2347?email_source=notifications&email_token=AAAVXO56RBKVNN3MKIVS7BLQPHG5RA5CNFSM4JCIGAXKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCIPASPY#discussion_r336541227>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAVXO3S5PTBKPXAAAH4IMTQPHG5RANCNFSM4JCIGAXA>
.
|
The tests fail because the new test assumes |
@Xarthisius what do we need to do to get |
Since it's a python package, all you need to do is add it to |
|
||
output_00080 = "output_00080/info_00080.txt" | ||
@requires_ds(output_00080) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this test uses the f90nml module I think you need the @requires_module()
decorator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha nice mind-meld with @Xarthisius! 😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ready to go to me!
EDIT: Whoops, I didn't read in detail the errors -- I don'tknow what's up, but it looks like a ValueError
is being raised from the new tests. Do we need to update the dataset?
@matthewturk I think we should rather catch the error and display it as a warning to the user. There used to be a bug in RAMSES that would write the configuration file in binary format. I'm working on it. |
@yt-fido test this please. |
The tests seem to fail for unrelated reasons, don't they? |
I'm working on a fix for the 3.6 answer tests on Travis. |
@cphyc if you merge or rebase with master you should get the fix I pushed for the Travis tests. |
@yt-fido test this please |
Also add on-demand facilities for f90nml package
This happens with old version of RAMSES that produced malformed namelist.txt files
The tests were relying on output_00080 for a *correct* namelist. Changed it to a working one (ramses_new_format). The path to namelist.txt was not computed correclty, resulting in a failing test.
54c5a33
to
a528d21
Compare
PR Summary
This adds the automatic loading of the
namelist.txt
file which contains the parameter file RAMSES used to produce the output.This relies on the package
f90nml
being installed (for the tests). If the package is absent,ds.parameters['namelist']
contains an error message.PR Checklist