jdkloe / pybufr-ecmwf

a python module that allows reading and writing BUFR formatted files, where BUFR stands for Binary Universal Form for the Representation of meteorological data.
Other
29 stars 12 forks source link

bfr.bufr_obj.print_sections_012() - return values #6

Closed jintaglee closed 8 years ago

jintaglee commented 8 years ago

Hello,

I am not sure whether this is the right place to ask a question. Please point me to the right place if this is not an appropriate use of 'Issues'.

I have started using pybufr-ecmwf. I would like to print out sections 0, 1 and 2 of a Bufr message using "bfr.bufr_obj.print_sections_012()". However the method doesn't seem to return anything. I've tried other similar methods but without any success. Can you please advise me how I can assign the printed return values from "bfr.bufr_obj.print_sections_012()" to a variable?

Thank you.

Regards,

Jin

jdkloe commented 8 years ago

thanks for your interest in this module, and sure this is the proper place to ask questions, report issues and ask for additional features. You are right, there is no ready made function to get a copy of the same items printed by bfr.bufr_obj.print_sections_012(). But this data is available after decoding a bufr message in the list variables: bfr.bufr_obj.ksup bfr.bufr_obj.ksec0 bfr.bufr_obj.ksec1 bfr.bufr_obj.ksec2 but you need to know the definition of these arrays before you can use them. These can be found in the ECMWF documentation (a link to the bufr_user_guide.pdf document is available here: https://software.ecmwf.int/wiki/display/BUFR/BUFRDC+Home) I could add some code to the module to provide this data in an easier way, maybe as a dictionary of key:value pairs. Please let me know if that would be useful for you, or if you have other ideas.

jintaglee commented 8 years ago

If sections 0, 1, 2 and 3 are provided in an easier way - key:value pairs as you suggest - that will be great!

jdkloe commented 8 years ago

I added a method called get_header_info that returns a dictionary holding the header data. The script example_programs/example_for_using_bufrinterface_ecmwf_for_decoding.py contains an example how this could be used. Is this what you had in mind? If it is more convenient, I could also add shorter aliases for some of the very long keys.

jintaglee commented 8 years ago

Thank you very much for the new method! Much appreciated.

I tried to do an install after a successful build but the install is generating an error,

creating /apps/python/2.7.6/lib/python2.7/site-packages/pybufr_ecmwf error: could not create '/apps/python/2.7.6/lib/python2.7/site-packages/pybufr_ecmwf': Read-only file system

Most likely the install is trying to install the module under a general area which I don't have a write permission to. I am not a sysadmin so I don't have enough privilege but I would like the module to be installed under a directory which is not under my home directory so that my colleagues can use the module. Would it be possible for the install to be changed to enable an installation location which is supplied by the user?

Sorry for this request but I think the suggested change will make it easier for multiple users to use one copy of a module installation rather than multiple users having to install their own copies.

jdkloe commented 8 years ago

sure, the default "python setup.py install" will try to use the system directories. If you do not have sudo/root permission, you can use: "python setup.py install --user" to install in your own account, or "python setup.py install --prefix=/some/dir/" to install in some other location that can be used by others (i.e. some network disk that you can write to and others can read). In this second case you need either to provide the PYTHONPATH environment setting to signal where python should find the module, or use a .pth file. A .pth file can be placed in any location that python will look for to find modules, i.e. in $HOME/.local/lib/python2.7/site-packages/ or in /usr/lib/python2.7/site-packages// (but then again for this second option you will need to ask your system admin to do this for you).

If the --prefix does not work as intended, this would be a bug. Please report that as a new issue if this would be the case for you.

jintaglee commented 8 years ago

Thank you for pointing out the option, '--prefix'. It works fine. Now I've successfully installed the pybufr-ecmwf package in a general location where we have write-access.

One minor comment: the reason why I thought there were only 2 ways of installing the package was because "INSTALL.txt" said,

1) Download and install the latest tarball: -visit https://code.google.com/p/pybufr-ecmwf/ and download the latest software version -unpack the software: tar zxvf pybufr-ecmwf-$VERSION.tar.gz -cd pybufr-ecmwf-$VERSION -python setup.py build -[local install:] python setup.py install --user -[system wide install:] python setup.py install

Perhaps it will help people like me who are unfamiliar with building/installing Python packages to add the third method of installation using '--prefix'.

Thank you very much for writing pybufr-ecmwf and making it available to others. I think it is a very useful tool which will benefit the meteorological community who deal with Bufr files. I look forward to getting familiarised with the package and seeing it develop further.

jdkloe commented 8 years ago

Well thank you as well for pointing this out. Clearly I need to spend some more time to tidy the documentation. That will be my next priority.