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

Support for Python byte type #4141

Open
kshitij-v-mehta opened this issue Apr 16, 2024 · 0 comments
Open

Support for Python byte type #4141

kshitij-v-mehta opened this issue Apr 16, 2024 · 0 comments

Comments

@kshitij-v-mehta
Copy link

We have a use case with GTC in which we need to store images in a BP file. It would be nice to add a feature that supports Python variables of class bytes (not the same as bytearrays).

As Python bytes are not natively supported, the current approach requires converting an image represented as a bytes array to a numpy uint8 type and writing it to file. Conversely, to read it back, we need to convert the uint8 array to bytes.

The following pseudocode shows a snippet on how this is currently done.

# Perform matplotlib plotting

# Get a bytes object
b = io.BytesIO()

# Write plot to the bytes buffer and return it
plt.savefig(b, format='png')

# Higher level function receives b and converts it into a numpy array.
# Write the numpy array as a uint8 array
dt = np.dtype(np.uint8)
N = len(b)
data = np.frombuffer(b, dtype=dt, count=N, offset=0)
adios_fh.write(varname, data, [N], [0], [N])
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

No branches or pull requests

1 participant