So I’m trying to convert some data from a pandas dataframe into a CZML file. Short version of a dataframe, it’s like a table - structured data. My dataframe looks like:
Row index | Source and Type | Epoch | x | y | z | t_delta | e |
---|---|---|---|---|---|---|---|
0 | SLR - Reference | 2023-07-01 01:39:00+00:00 | 2.538802e+06 | -3.614576e+06 | 5.507524e+06 | 0.0 | 2023-07-01T01:39:00Z |
1 | SLR - Reference | 2023-07-01 01:42:00+00:00 | 1.652305e+06 | -2.889726e+06 | 6.222747e+06 | 180.0 | 2023-07-01T01:42:00Z |
2 | SLR - Reference | 2023-07-01 01:45:00+00:00 | 7.055082e+05 | -2.059419e+06 | 6.710274e+06 | 360.0 | 2023-07-01T01:45:00Z |
3 | SLR - Reference | 2023-07-01 01:48:00+00:00 | -2.670395e+05 | -1.153940e+06 | 6.952200e+06 | 540.0 | 2023-07-01T01:48:00Z |
4 | SLR - Reference | 2023-07-01 01:51:00+00:00 | -1.229828e+06 | -2.063241e+05 | 6.939552e+06 | 720.0 | 2023-07-01T01:51:00Z |
So Row index is merely row index, Source and Type is just source of data, Epoch is a timestamp object of time, x, y, z are my position, t_delta is my difference in time in seconds, and e is a string representation of epoch. I can call a column of the table and perform operations on it by running a command like df[‘Epoch’]
The coordinates are in kilometers and I can convert them to meters with running df_tst[['x', 'y', 'z']] = df_tst[['x', 'y', 'z']] * 1000
.
So to show my code, I am basically creating a dictionary from the elements of the dataframe:
d_czml = [
{
"id":"document",
"name":"simple",
"version":"1.0",
"clock":{
"interval":f"{df_tst['e'].iloc[0]}/{df_tst['e'].iloc[-1]}",
"currentTime":df_tst['e'].iloc[0],
"multiplier":60,
"range":"LOOP_STOP",
"step":"SYSTEM_CLOCK_MULTIPLIER"
}
}, {
"id":"Satellites",
"name":"Satellites",
"position": {
"interpolationAlgorithm": "LAGRANGE",
"interpolationDegree": 5,
"referenceFrame": "INERTIAL",
"cartesian": df_tst[['e', 'x', 'y', 'z']].to_numpy().ravel().tolist()
}
}
]
with open(data_dir / 'test_czml.czml', 'w') as f:
f.write(json.dumps(d_czml))
The f"{df_tst['e'].iloc[0]}/{df_tst['e'].iloc[-1]}"
creates a formatted string containing the first [0] element and the last [-1] epoch string e
elements element.
The df_tst[['e', 'x', 'y', 'z']].to_numpy().ravel().tolist()
creates a numpy array from the string epoch, x, y, and z. The ravel converts it to a 1D array, and tolist converts it to a list.
Lastly the the data is written in json to a file called ‘test_czml.czml’ at the data_dir (a python pathlib.Path object).
The resulting raw file looks like:
[{"id": "document", "name": "simple", "version": "1.0", "clock": {"interval": "2023-07-01T01:39:00Z/2023-07-01T01:51:00Z", "currentTime": "2023-07-01T01:39:00Z", "multiplier": 60, "range": "LOOP_STOP", "step": "SYSTEM_CLOCK_MULTIPLIER"}}, {"id": "Satellites", "name": "Satellites", "position": {"interpolationAlgorithm": "LAGRANGE", "interpolationDegree": 5, "referenceFrame": "INERTIAL", "cartesian": ["2023-07-01T01:39:00Z", 2538.80175795354, -3614.57594511061, 5507.52360176926, "2023-07-01T01:42:00Z", 1652.30508359447, -2889.72556218045, 6222.74718975222, "2023-07-01T01:45:00Z", 705.508225186085, -2059.4191635614, 6710.27405051915, "2023-07-01T01:48:00Z", -267.039490128933, -1153.94044132787, 6952.20021290686, "2023-07-01T01:51:00Z", -1229.82808332692, -206.324144329006, 6939.55202392579]}}]
Prettyfied:
[{
"id": "document",
"name": "simple",
"version": "1.0",
"clock": {
"interval": "2023-07-01T01:39:00Z/2023-07-01T01:51:00Z",
"currentTime": "2023-07-01T01:39:00Z",
"multiplier": 60,
"range": "LOOP_STOP",
"step": "SYSTEM_CLOCK_MULTIPLIER"
}
}, {
"id": "Satellites",
"name": "Satellites",
"position": {
"interpolationAlgorithm": "LAGRANGE",
"interpolationDegree": 5,
"referenceFrame": "INERTIAL",
"cartesian": [
"2023-07-01T01:39:00Z", 2538.80175795354, -3614.57594511061, 5507.52360176926,
"2023-07-01T01:42:00Z", 1652.30508359447, -2889.72556218045, 6222.74718975222,
"2023-07-01T01:45:00Z", 705.508225186085, -2059.4191635614, 6710.27405051915,
"2023-07-01T01:48:00Z", -267.039490128933, -1153.94044132787, 6952.20021290686,
"2023-07-01T01:51:00Z", -1229.82808332692, -206.324144329006, 6939.55202392579
]
}
}]
However nothing is rendering. CZML files do work as I have managed to get the satellite example working locally. I have been trying to work through the wiki files but I am still having trouble getting my head around the correct structure.
Right now I’d just like to get something rendered, can anyone spot something I’ve potentially missed?