Last active
February 9, 2024 14:38
-
-
Save canismarko/8d5a1a1850dffa7e532de05449383fac to your computer and use it in GitHub Desktop.
Tiled Pydantic Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
from tiled.adapters.mapping import MapAdapter | |
from tiled.adapters.xarray import DatasetAdapter | |
from tiled.client import Context, from_context | |
from tiled.server.app import build_app | |
# Tiled data to use for testing | |
# Some mocked test data | |
run1 = pd.DataFrame( | |
{ | |
"energy_energy": np.linspace(8300, 8400, num=100), | |
"It_net_counts": np.abs(np.sin(np.linspace(0, 4 * np.pi, num=100))), | |
"I0_net_counts": np.linspace(1, 2, num=100), | |
} | |
).to_xarray() | |
hints = { | |
"energy": {"fields": ["energy_energy", "energy_id_energy_readback"]}, | |
} | |
bluesky_mapping = { | |
"7d1daf1d-60c7-4aa7-a668-d1cd97e5335f": MapAdapter( | |
{ | |
"primary": MapAdapter( | |
{ | |
"data": DatasetAdapter.from_dataset(run1), | |
}, | |
metadata={"descriptors": [{"hints": hints}]}, | |
), | |
}, | |
metadata={ | |
"plan_name": "xafs_scan", | |
"start": { | |
"plan_name": "xafs_scan", | |
"uid": "7d1daf1d-60c7-4aa7-a668-d1cd97e5335f", | |
"hints": {"dimensions": [[["energy_energy"], "primary"]]}, | |
}, | |
}, | |
), | |
} | |
mapping = { | |
"255id_testing": MapAdapter(bluesky_mapping), | |
} | |
tree = MapAdapter(mapping) | |
if __name__ == "__main__": | |
uid = "7d1daf1d-60c7-4aa7-a668-d1cd97e5335f" | |
for idx in range(22): | |
app = build_app(tree) | |
with Context.from_app(app) as context: | |
client = from_context(context) | |
run = client["255id_testing"][uid] | |
# Why does this keep adding specs? | |
data = run['primary']['data'] | |
data.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment