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

Refactor g2clib cython #171

Merged
merged 13 commits into from
Feb 18, 2025
Merged

Refactor g2clib cython #171

merged 13 commits into from
Feb 18, 2025

Conversation

EricEngle-NOAA
Copy link
Collaborator

No description provided.

Function _toarray() rewritten to remove loop and use memcpy
instead; removal of deprecated Python C API PyObject_AsWriteBuffer()

Function unpack7() heavily modified to test handling arguments
in a less clunky way, especially input numpy arrays. These new
approaches will trickle into other functions.
unpack7() - clean up of commented code

grib2_create() - refactored
Rearranged order of GRIB2 creation functions.  Refactored
grib2_local() and grib2_end().
Refactored grib2_addgrid() which includes some minor changes to
_grib2io.py when defining _deflist.
Refactored grib2_addfield() and some associated minor changes to
_grib2io.py
Remove function definitions from Python.h that are no longer
needed.
Refactored unpack1() and unpack7(). These funcitons no longer pass
grbpos and np.empty into the Cython functions.

We are able to pass np.empty() return directly into _toarray()
from unpack*() functions.
Refactored unpack[3,4,5,6]() functions and associated changes to
_grib2io.py.
Clean up of now unused functions defined in Python.h

In np.empty calls, changed string dtype to real numpy dtype.
Mainly docblock updates, but some minor code changes and variable
renaming for consistency.  Some minor changes to _grib2io.py.
@EricEngle-NOAA EricEngle-NOAA self-assigned this Feb 18, 2025
@EricEngle-NOAA EricEngle-NOAA linked an issue Feb 18, 2025 that may be closed by this pull request
@EricEngle-NOAA EricEngle-NOAA marked this pull request as ready for review February 18, 2025 03:24
@EricEngle-NOAA EricEngle-NOAA merged commit d43b66d into master Feb 18, 2025
@john970
Copy link

john970 commented Feb 19, 2025

I pulled this commit to test with 3.13, and with several model types (NDFD, NBM, MRMS) I saw the following in the REPL:

import grib2io as g2io
g = g2io.open('nbm_reference_file.grb2')
g[0]
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    g[0]
    ~^^^
  File "/opt/miniconda3/envs/otto313/lib/python3.13/site-packages/grib2io/_grib2io.py", line 859, in __repr__
    for k,v in self.attrs_by_section(sect,values=True).items():
               ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/otto313/lib/python3.13/site-packages/grib2io/_grib2io.py", line 916, in attrs_by_section
    attrs = templates._section_attrs[sect]+\
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
            self.__class__.__mro__[_find_class_index(sect)]._attrs
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: can only concatenate list (not "method") to list

I don't think this is actually supposed to work with 3.13 yet, but thought I'd share anyways in case it is useful.
Things like g[0].validDate do work.

@EricEngle-NOAA
Copy link
Collaborator Author

@john970 Look familiar 😄 ... I am now actively working on Python 3.13 and have an issue for it #172

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.

Refactor g2clib Cython
2 participants