-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Refactor DS9 parser #130
Refactor DS9 parser #130
Conversation
regions/io/read_ds9.py
Outdated
reg = line.LinePixelRegion(coord_list[0], coord_list[1]) | ||
else: | ||
raise DS9RegionParserError("No central coordinate") | ||
elif region_type == 'annnulus': |
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.
-1 n
Alright, with this I guess we can read all the regions we want to support for now. The coverage in https://github.com/joleroi/regions/blob/ds9_parser/dev/regions_pyregion_comparison.csv is still not super-high, but that's because the files are full of We should, however, raise a Warning if e.g. an annulus or an ellipse with several radii is read, I will add this to this PR. |
@cdeil Note that the incapability to read |
Update: I refactored the DS9 parser to (hopefully) make it more readable. See the docstrings for a description. |
Ready for review |
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 left two minor inline comments.
How good are the warning and error messages when parsing errors or warnings occur?
Do you give a line number?
(recently I've been using yamllint, and there with the line numbers it's a pleasure to find the issues in the input files: https://github.com/adrienverge/yamllint#screenshot).
regions/io/ds9/core.py
Outdated
else: | ||
raise DS9RegionParserError("No central coordinate") | ||
|
||
reg.visual = {key: self.meta[key] for key in self.meta.keys() if key in viz_keywords} |
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.
Can we use OrderedDict everywhere instead of dict and preserve order?
In my experience this helps with readability for users, and also testing / debugging for developers.
We can't achieve round-tripping, but order helps a bit, no?
regions/io/ds9/read.py
Outdated
|
||
|
||
regex_meta = re.compile("([a-zA-Z]+)(=)([^= ]+) ?") | ||
"""Regular expression to extract meta attributes""" |
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.
Add blank linkes to make it clearer which comment is for which variable?
@joleroi - Can you please rebase this PR and get this in? |
@astrofrog This is the expected behaviour isn't it?
This PR is ready to be merged. There should be a follow-up PR, to update the DS9 Writer to also go via |
@joleroi - yes that behavior looks correct, thanks! |
@joleroi - there is a minor failure due to PEP8 stuff: https://travis-ci.org/astropy/regions/jobs/233214729 Otherwise I'm happy with this refactoring. In future once we implement other serializations, we might want to see if we can refactor to share some code between different serializations, but for now this looks good to me. |
Now that, again, it's too late, I tried to use this and immediately encountered a failure:
result:
This case worked before, so we need to fix it and add a regression test. |
Also, now that I understand what's going on a bit better, I'm not a fan of the |
I'll have a look
I don't think there is a killer argument for one of both approaches, so if others also think it should be changed back to a functional approach I am happy with it. UPDATE: In any case we could add a function that runs the class based API behind the scenes |
No opinion on functional vs class-based code organisation from me. I do think the intermediate representation as Shape / ShapeList is nice. It could make sense to use it in the writer also, no? I did open up the current files in PyCharm and it points out a few issues:
I'm not opening a PR because then we would probably start editing the same lines. Let me know if you want me to open a PR or if one of you can address these. |
fixed in #135 |
👍 |
I'm fine with having functions that wrap the class-based approach. My issue is probably just one of aesthetics; I don't like things that work like:
because it's changing state; I feel the state change should be run at |
I (personally, with my limited experience) don't like it if I initialize a class and immediately get an error (e.g. if parsing failed), so I usually follow this 'init - run' pattern. That said, if other also want to do stuff on |
I lean the other way; I would much prefer to have the class fail on initialization if it's going to fail; what good is a |
I just had a look at the new parsing code for the first time ... here's some feedback:
I don't have time to help with regions development this week. |
I'll do a follow up PR tomorrow or next week. |
This builds on #128 and #129
Let's iterate on those first and then discuss this.
This PR:
add the line and circular annulus regions to the DS9 parsers. This should improve the coverage to a satisfying level. The parser will be restructured in a follow-up PR.