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

Python3 grib fixes #1774

Closed
wants to merge 2 commits into from
Closed

Python3 grib fixes #1774

wants to merge 2 commits into from

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Sep 7, 2015

A couple of small fixes for GRIB parsing. Probably a more permanent fix should be put in GRIB itself, but I was lazy and some stuff was not making sense so I wasn't sure of the best fix anyway.

GRIB does not handle integral types correctly on Python 3.
For some reason, the file seems to read in 4K chunks, even if I disable
buffering. So simply re-seek to the location of the end of the message
after reading one.
@QuLogic QuLogic mentioned this pull request Sep 7, 2015
14 tasks
@rhattersley
Copy link
Member

These both seem like genuine bugs. Have you raised them upstream?

@rhattersley
Copy link
Member

Do you know what the performance impact is of the extra seeks?

@ajdawson
Copy link
Member

ajdawson commented Sep 9, 2015

I don't think ECMWF support gribapi on Python 3 anyway do they?

Are you using the SciTools conda package for gribapi on Python 3? It looks like that applies a patch for Python 3 compatibility, so could that be a potential location of Python 3 problems too?

@QuLogic
Copy link
Member Author

QuLogic commented Sep 9, 2015

I'm aware of the patch; I wrote it. 😉 I put the changes in here because it's easier to iterate than rebuilding the conda package, and I'd like some advice (though I probably should have explained that earlier.)

For grib_set_array, the GRIB code checks for instances of int, which fails on Python 3 because NumPy arrays are no longer subclasses of int but of numbers.Integral. Shouldn't be too troublesome to fix.

For the seeking though, I really have no idea what's causing it. Whenever GRIB reads something, no matter the size, the file pointer always advances by 4K. I thought maybe Python 3's file had some buffering, but I can't find any way to disable it (or what I tried didn't work.) Admittedly, I'd say the file->FILE* conversion for Python 3 GRIB is a bit of a hack, but so long as the API is constrained to those types, it'll have to do.

@ajdawson
Copy link
Member

My concern is that this fix will go in for compatibility against a patched gribapi version, and will remain in our code base even if/when Python 3 is actually supported by gribapi.

@QuLogic
Copy link
Member Author

QuLogic commented Sep 10, 2015

I can update the patched GRIB for the first commit easily (though it doesn't really hurt to be more explicit there.) However, I was really hoping someone might be able to come up with a better workaround or fix for the second commit's issue.

@rhattersley
Copy link
Member

Could we just leave GRIB unsupported in Python 3 for now? (e.g. Skip the relevant tests, perhaps add a warning when using it?)

@ajdawson
Copy link
Member

The first commit I have no issue with, it is more the second one. I'm tempted to say that we should leave GRIB support out of the Python 3 version initially until this has been thought through some more and we come up with a good solution (although it pains me to say that as I mostly work with GRIB data...).

@QuLogic
Copy link
Member Author

QuLogic commented Sep 11, 2015

We could leave GRIB unsupported, but it would require added the relevant skips, so I'm against it on account of laziness 😉.

To go forward though, the best method is either for GRIB to provide an open/close function to get the FILE* from C code (and stop allowing Python's file), or to add some wrapper for I/O for C->Python APIs.

@QuLogic QuLogic modified the milestone: v1.9 Sep 12, 2015
@rhattersley
Copy link
Member

NB. I'm experimenting with making GRIB an optional dependency - it's something I've wanted to do for a long time.

@ocefpaf
Copy link
Member

ocefpaf commented Sep 18, 2015

NB. I'm experimenting with making GRIB an optional dependency - it's something I've wanted to do for a long time.

Huge 👍

@rhattersley
Copy link
Member

NB. I'm experimenting with making GRIB an optional dependency - it's something I've wanted to do for a long time.

See #1789.

@rhattersley
Copy link
Member

And it's done! Thanks to #1789 GRIB is now officially optional. 😀

@rhattersley
Copy link
Member

Chatting with @marqh offline he pointed out that the current gribapi from ECMWF is effectively deprecated now they are putting their effort into ecCodes.

That adds weight to the argument that we drop GRIB support from Python 3. We can add it later via ecCodes.

@QuLogic
Copy link
Member Author

QuLogic commented Sep 22, 2015

If I read their description correctly, the ecCodes API should be the same as GRIB-API, so it might have issues with Python 3 as well. If anyone's got any sway there, you should see if they're testing that out too...

@marqh
Copy link
Member

marqh commented Sep 23, 2015

I'm aiming to get some time to get Iris to move over to ecCodes.

If claims are to be believed, it will be a simple piece of work to deliver once I get started; we shall see.

I will use this work to investigate with ECMWF the limitations on Python version and raise issues with them. Hopefully we'll get things moving there.

If we can hit v1.9 by making GRIB py3 optional (or already have done) then that's a fine solution from my point of view

@rhattersley
Copy link
Member

So... what do we want to do? Close this PR and remove the Py3 builds from conda (and conda-recipes-scitools)?

@marqh
Copy link
Member

marqh commented Sep 24, 2015

So... what do we want to do? Close this PR and remove the Py3 builds from conda (and conda-recipes-scitools)?

that sounds like a sensible approach to me

@ajdawson
Copy link
Member

So... what do we want to do? Close this PR and remove the Py3 builds from conda (and conda-recipes-scitools)?

I think so, although we might want to keep the first commit from this PR to save it from having to be rediscovered at a later time when Python 3 support is available for gribapi.

We also need to add a note to the what's new entry for Python 3 support stating that GRIB is not supported in Iris on Python 3.

@marqh marqh mentioned this pull request Oct 12, 2015
@marqh
Copy link
Member

marqh commented Oct 12, 2015

I've pushed up a PR on Iris to add a what's new entry, indicating that GRIB is unsupported for Python 3

Is that enough to close this PR, or to take it out of the 1.9 milestone?
what's the better approach?

I think so, although we might want to keep the first commit from this PR to save it from having to be rediscovered at a later time when Python 3 support is available for gribapi.

I think we can push this information into an issue, would that be all right?

Do we need to pull things out of conda-recipes? I thought we could leave them in there; GRIB is an optional dependency now, so I'd have thought this would be all right

cheers
mark

np.array(np.round(lon_values), dtype=np.int64))
gribapi.grib_set_array(grib, 'latitudes',
np.array(np.round(lat_values), dtype=np.int64))
gribapi.grib_set_long_array(grib, 'longitudes',
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be incorporated into Iris?

Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be incorporated into Iris?

my belief: not until Python3 is adopted

@marqh marqh mentioned this pull request Oct 14, 2015
@marqh
Copy link
Member

marqh commented Oct 14, 2015

#1806 is now merged

please may I suggest that we close this PR and move details to #1807 for ongoing management

This will then be out of scope for the v1.9 milestone

many thanks
marqh

@marqh
Copy link
Member

marqh commented Oct 14, 2015

@QuLogic does this sound all right to you?

@QuLogic
Copy link
Member Author

QuLogic commented Oct 14, 2015

Sounds good to me.

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.

6 participants