Skip to content

Data

Data

Data(uri: str = '', nbytes: int = 0, dtype: list = None)

Data represents a block of raw binary data, with an optional structure. This data is built using the provided uri that may either point to an external file, or be a data URI that encodes the binary data directly in the JSON file. When an uri is provided, data will is fetched just in time and stored locally. If no uri has been provided, an empty data is created ex-nihilo, just in time. Data can be modified and is tracked for any modification.

Example
from gsp.core.data import Data
data = Data(nbytes=512, dtype=[("color", 1, "u4")])
1. COMMAND
     - METHOD: "core.Data" (str)
     - COMMAND_ID: 1 (int)
     - TIMESTAMP: 2024-08-21T12:52:32.671017 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - NBYTES: 512 (int)
     - DTYPE: [('color', 1, 'u4')] (list)
     - URI:  (str)

{
  "jsonrpc": "2.0",
  "commands": [
    {
      "method": "core.Data",
      "id": 1,
      "timestamp": 1724237552.671017,
      "parameters": {
        "id": 1,
        "nbytes": 512,
        "dtype": [
          [
            "color",
            1,
            "u4"
          ]
        ],
        "uri": ""
      }
    }
  ]
}

Data represents a block of raw binary data, with an optional structure.

Parameters:

Name Type Description Default
uri str

Uniform Resource Identifier from where to fetch data.

''
nbytes int

Number of bytes in the data. This is used to create data ex-nihilo if no uri has been provided. If a dtype is provided, the nbytes is discarded in favor of the size of the provided structure.

0
dtype list

Description of the internal structure of the data as a list of (name (str), type (str), count (int)) items.

with:

Type Kind
i[1,2,4] signed integer (8,16, 32 bits)
u[1,2,4] unsigned integer (8,16, 32 bits)
f[2,4,8] float (16, 32, 64 bits)
m timedelta (64 bits)
M datetime (64 bits)
U[n] unicode string (n x 16 bits)
None

set_data

set_data(offset: int, data: bytes)

Update data content at given offset with new data.

Example
1
2
3
4
5
6
import numpy as np
from gsp.core.data import Data

nbytes = 2*np.float32(0).nbytes
data = Data(nbytes=nbytes, dtype=["f4"])
data.set_data(0, bytes(nbytes))
1. COMMAND
     - METHOD: "core.Data" (str)
     - COMMAND_ID: 1 (int)
     - TIMESTAMP: 2024-08-21T12:52:32.818035 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - NBYTES: 8 (int)
     - DTYPE: ['f4'] (list)
     - URI:  (str)

2. COMMAND
     - METHOD: "Data/set_data" (str)
     - COMMAND_ID: 2 (int)
     - TIMESTAMP: 2024-08-21T12:52:32.818075 (datetime)
   PARAMETERS
     - OBJECT_ID: 1 (int)
     - OFFSET: 0 (int)
     - DATA: b'\x00\x00\x00\x00\x00\x00\x00\x00' (bytes)

{
  "jsonrpc": "2.0",
  "commands": [
    {
      "method": "core.Data",
      "id": 1,
      "timestamp": 1724237552.818035,
      "parameters": {
        "id": 1,
        "nbytes": 8,
        "dtype": [
          "f4"
        ],
        "uri": ""
      }
    },
    {
      "method": "Data/set_data",
      "id": 2,
      "timestamp": 1724237552.818075,
      "parameters": {
        "id": 1,
        "offset": 0,
        "data": "AAAAAAAAAAA="
      }
    }
  ]
}

Parameters:

Name Type Description Default
offset int

Offset in bytes where to start update

required
data bytes

Content to update with.

required