10BC0 Add parameter to initialize partially parsed METARs by 1kastner · Pull Request #25 · python-metar/python-metar · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@1kastner
Copy link

Offer a way to convert ParserErrors into warnings when minor information was not understood.

Offer a way to convert ParserErrors into warnings when minor information was not understood.
@1kastner 1kastner changed the title Add parameter to read partially parsed METARs Add parameter to initialize partially parsed METARs May 13, 2017
@1kastner
Copy link
Author

@tomp do you have any plans to merge this?

@tomp
Copy link
Member
tomp commented Jul 11, 2017

I don't think this is helpful, unfortunately. If there are unparsed groups in the METAR code, it's an error. The proper way to handle an error like this in Python is to throw an exception. If you think the generic exception that's currently thrown should be more specific, I'd be open to creating a more specific exception for the case that you want to be able to ignore. One way or the other, the correct way to handle this is for you (the client) to catch my exception, rather than for me to suppress the error.

@tomp tomp closed this Jul 11, 2017
@1kastner
Copy link
Author

Under some circumstances we are only interested in some partial information of the METAR. In my project e.g. I was only interested in cloud cover. I did not care whether the wind was correctly parsed (see e.g. here: https://github.com/tomp/python-metar/issues/26). But your exception handling would have forced me to totally ignore that measurement or alternatively to write my own parser. In the readme you say that some local formats are not supported and as I am not an expert on METARs I was not sure which of these issues were linked to that fact. So I believe that it is not necessary to see it as an error if some details could not be parsed. If those details are not the ones you are currently interested in there might be nothing bad about it.

@akrherz
Copy link
Collaborator
akrherz commented Jul 18, 2017

@tomp this decision makes usage of your library difficult. In general, the exception causes no valid METAR object reference to be created, so one has no option for even partial METAR parsing. My workflow currently is to:

  1. catch the exception
  2. use the denoted invalid METAR groups to do a string substitution on the original METAR to remove those segments
  3. send the METAR back to the Metar() parser again to see what happens

If you were fully confident that your library implements the entire METAR specification (one may argue that such a thing even exists), the this type of disciplined exception raising would be valid IMHO

I think providing the user the option (disabled by default as the PR does) is a good idea and doesn't change your current default behaviour decision.

@1kastner
Copy link
Author
1kastner commented Oct 4, 2017

There are still #26 #27 #28 out there which could benefit from this pull request. For a long time no changes...

@WeatherGod
Copy link
Contributor

Just came across this METAR from aviationweather.gov:

'K9L2 100958Z AUTO 33006KT 10SM CLR M A3007 RMK AO2 SLPNO FZRANO $'

That silly 'M' there is messing up everything for me. In my case, I am loading up all of the metars I have for a given hour into a Pandas Dataframe. I want my dataframe to record that there is a maintence indicator on, and that there are some other things turned off. Right now, I am completely blind to the fact that this station is broken and putting out bad metars in my code.

@WeatherGod
Copy link
Contributor

Also, as a side note, I would suggest modifying this implementation slightly so that a flag is set such as "self.is_valid = False" or something, in addition to emitting the warning.

@1kastner
Copy link
Author

@WeatherGod Feel free to take my changes and adjust them as another PR. The best way to express the idea (which is still a bit vague to me) is to show it.

@WeatherGod
Copy link
Contributor

perhaps I might do that... I have to be careful not to let myself down a rabbit-hole of a bunch of little changes I have been thinking of, particularly to allow for others to easily extend the parsing capabilities by making a subclass, or passing in a list of additional regexs/function tuples.

But the basic idea with what I was saying is that after the object creation, I should be able to check an attribute to know if the metar is completely valid or not. Warnings, while useful, are more intended for logs.

@WeatherGod
Copy link
Contributor

Oh, and for those who might be interested in a possible work-around (I do deeply apologize for the crass language for this package name and its documentation, but it does work): https://pypi.python.org/pypi/fuckit

@1kastner
Copy link
Author

I am curious how you intend to solve it, looking forward to it!

@akrherz
Copy link
Collaborator
akrherz commented Oct 12, 2017

Hi @WeatherGod , the is_valid idea is problematic as this library does not cover the full METAR specification. Currently, it emits exceptions for valid METARs. I hope to engage some other meteorology python dudes at Unidata next week to discuss thoughts on a path forward for a METAR parser, perhaps something embedded within metpy, we shall see :)

@1kastner
Copy link
Author

@akrherz With the current project velocity of this project using metpy is the better way to go I guess.

@WeatherGod
Copy link
Contributor
WeatherGod commented Oct 12, 2017 via email

@akrherz
Copy link
Collaborator
akrherz commented Oct 12, 2017

@WeatherGod GEMPAK has decoded metars for a very long time :)

@WeatherGod
Copy link
Contributor
WeatherGod commented Oct 12, 2017 via email

@WeatherGod
Copy link
Contributor

I created #36 as an initial step.

@WeatherGod
Copy link
Contributor

I also created #37, which is a tiny change that should make it possible for users to modify the set of regexes and handlers to use for parsing. See the example there for some ideas.

@dopplershift
Copy link
dopplershift commented Oct 16, 2017

FYI, my plan is to implement a true parser for METARS, as in true CS parser, rather than abusing regexes for human-coded text: Unidata/MetPy#70

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.

5 participants

0