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

added packaged grib support #566

Merged
merged 1 commit into from
Jun 25, 2013
Merged

Conversation

cpelley
Copy link

@cpelley cpelley commented Jun 19, 2013

This is an enhancement to support packaged grib files.
Packaged grib files have extra header information, meaning that the signature (magic number) is offset by a specific number of bytes.

This PR adds support by recognising this type of "grib" file for which the grib api can handle.
closes #332

internal ref: WO49559

@ghost ghost assigned bblay Jun 20, 2013
MAGIC_NUMBER_64_BIT = FileElement('64-bit magic number', lambda filename, fh:
# Define magic number offset by a number of bytes (WMO bulletin header)
WMO_OFFSET = 21
MAGIC_NUMBER_32_BIT_OFFSET = FileElement(
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this is WMO bulletin specific, it should probably be called something like, MAGIC_NUMBER_32_BIT_WMO_BULLETIN. Also, the comment would be unnecessary, and the WMO_OFFSET should probably be called something like, WMO_BULLETIN_HEADER_LENGTH.

Copy link
Author

Choose a reason for hiding this comment

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

xp all the way! 😃

@cpelley
Copy link
Author

cpelley commented Jun 20, 2013

thanks for your comments @bblay, let me know when you have finished your review so that I can make the necessary changes.

@cpelley
Copy link
Author

cpelley commented Jun 24, 2013

I would like to prioritize this enhancement as an iris user requires it to progress with their work.

@@ -253,23 +253,26 @@ def __repr__(self):
return 'FileElement(%r, %r)' % (self._name, self._element_getter_fn)


def _read_n(fh, fmt, n):
def _read_n(fh, fmt, n, offset=None):
Copy link
Member

Choose a reason for hiding this comment

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

A default offset of 0 rather than None seems simpler.

Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree. None should mean "don't seek", but 0 or any other number should mean "seek".

@cpelley
Copy link
Author

cpelley commented Jun 24, 2013

I agree with @bblay on this, the offset should be as default where you are in the file (None). This is more generic and does not have an assumed state for the file handler (i.e. we could do anything before getting here with the file handler, since it could contain a multitude of information, in which case we dont want to start at the beginning, it should be relative to the current position). I believe setting to None is more pythonic and also is more in line with the API of the function handler we are passing this argument to.

@esc24
Copy link
Member

esc24 commented Jun 24, 2013

this is more generic and does not have an assumed state for the file handler

I was thinking the offset i.e. the seek() was relative to the current position rather than absolute. Given the way you've used it means it's an absolute position, setting the default value to None makes sense (thanks @bblay - too much cycling has broken me). However, if you want to do this you need to change the if offset: to if offset is not None:, otherwise you can't jump to the start of the file with an offset of 0 - it'll just skip the seek.

@cpelley
Copy link
Author

cpelley commented Jun 25, 2013

ah good spotting thanks @esc24

@cpelley
Copy link
Author

cpelley commented Jun 25, 2013

I made it a dictionary since I can foresee that this list of preset offset variables may grow and grow and offsetting will likely not be limited to just WMO bulletin headers
I can change this back if you disagree, let me know

@bblay
Copy link
Contributor

bblay commented Jun 25, 2013

Please do change this back, many thanks.
It adds unnecessary complication with no clear benefit.

@cpelley
Copy link
Author

cpelley commented Jun 25, 2013

^done

bblay added a commit that referenced this pull request Jun 25, 2013
added packaged grib (wmo bulletin) support
@bblay bblay merged commit b557d02 into SciTools:master Jun 25, 2013
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.

Read GRIB files with WMO bulletin headers
3 participants