# Writing Scripts

You can use the built-in script editor to write a script, or you could use another editor (live Visual Studio Code) and copy and paste the code into the Astra Image editor. Please be careful when opening a script from at third party, as Python has the ability to modify your system.

**Example**\
The following example shows the basic flow of using Python with Astra Image. Please note that all image data is normalized (i.e. in the range 0.0 to 1.0). When the image data has been processed in Python, Astra Image expects the result to also be normalized between 0.0 to 1.0.

<mark style="color:orange;">import AstraImage as ai import numpy as np import cv2</mark>

<mark style="color:green;"># Get the image data from Astra Image and put into a numpy array</mark>\ <mark style="color:orange;">data = np.frombuffer(ai.getImageDataFloat(), dtype=np.float32)</mark>

<mark style="color:green;"># You can set the shape of the array if needed.</mark>\ <mark style="color:orange;">data.shape = (ai.getWidth(), ai.getHeight(), 3)</mark>

<mark style="color:green;"># Do something with the data.</mark>\ <mark style="color:orange;">data = (1.0 - data)</mark>

<mark style="color:green;"># Update the image data in Astra Image</mark>\ <mark style="color:orange;">ai.setImageDataFloat(data.tobytes(), ai.getWidth(), ai.getHeight())</mark>

In this example, the image data is retrieved from Astra Image and loaded into a numpy array. In this case, an inverted image is generated with a simple numpy operation:

<mark style="color:orange;">data = (1.0 - data)</mark>

After modifying the image, the data is updated in Astra Image.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://astra-image.gitbook.io/astra-image-6.0/python-scripts/writing-scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
