×
INDI Library v1.8.1 Released (09 Sep 2019)

Monthly maintenance release INDI v1.8.1

Python and INDI: from BLOBS to numpy.array

1 week 1 day ago
andreaconsole
Fresh Boarder
Fresh Boarder
Posts: 5
More
Topic Author
Python and INDI: from BLOBS to numpy.array #45594
Hi everyone,
I'm developing a Python program based on INDI for EAA (Electronically Assisted Astronomy). The interface with INDI is based on this tutorial : indilib.org/develop/tutorials/151-time-l...ith-indi-python.html
My problem is that I don't know how to convert the BLOB bytes I get to numpy.array to allow further processing. Can anybody help me?

<code>
# get image data
img = bp.getblobdata()
# write image data to BytesIO buffer
import io
blobfile = io.BytesIO(img)
# open a file and save buffer to disk
with open("frame.fit", "wb") as f:
f.write(blobfile.getvalue())
</code>

Please Log in or Create an account to join the conversation.

1 week 20 hours ago
mikefulb
Expert Boarder
Expert Boarder
Posts: 95
Karma: 2
More
Python and INDI: from BLOBS to numpy.array #45603
This is a quick and dirty example that should work.

import astropy.io.fits as pyfits
blob = blobEvent
fits=blob.getblobdata()
blobfile = BytesIO(fits)
hdulist = pyfits.open(blobfile)
image_data =hdulist[0].data

image_data will now be a 2D numpy array with the first index being 'Y' and the second 'X' in the traditional sense of indexing images.

You can do:

image_data = numpy.transpose(image_data)

to flip it around to X first then Y.

This example assumes the data is in the primary HDU header which I think is always the case for INDI generated FITS representations of an image in memory.

You can read more starting here:

docs.astropy.org/en/stable/io/fits/usage/headers.html

Please Log in or Create an account to join the conversation.

1 week 17 hours ago
andreaconsole
Fresh Boarder
Fresh Boarder
Posts: 5
More
Topic Author
Python and INDI: from BLOBS to numpy.array #45608
It works like a charm, thank you!

Please Log in or Create an account to join the conversation.

1 week 16 hours ago
mikefulb
Expert Boarder
Expert Boarder
Posts: 95
Karma: 2
More
Python and INDI: from BLOBS to numpy.array #45611
Great - I've written a large amount of code for INDI using Python so let me know if I can be any help.

Please Log in or Create an account to join the conversation.

Time to create page: 0.398 seconds