config
stringclasses 2
values | traj_id
stringlengths 9
11
| shape
listlengths 3
3
| data
listlengths 30
281
| left_right
listlengths 30
281
| barycenter
listlengths 30
281
|
|---|---|---|---|---|---|
30V_Jan24
|
30V_Tra_0
|
[
160,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[163,192],[160,188],[160,189],[155,186],[156,185],[159,188],[159,187],[158,190],[160,186],[163,188](...TRUNCATED)
| [[50.476285571642535,174.97129306040938],[49.977191063896264,174.5806905171067],[49.98699344297538,1(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_1
|
[
191,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[156,191],[156,191],[154,189],[155,192],[155,191],[154,191],[156,190],[151,193],[153,193],[154,192](...TRUNCATED)
| [[49.43649496493911,174.15463700110718],[49.6688767936665,174.60420583869373],[50.06925956738769,173(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_2
|
[
132,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[159,190],[158,191],[155,189],[155,189],[154,189],[156,190],[153,189],[153,188],[153,188],[153,189](...TRUNCATED)
| [[49.28436521320164,174.60250542038062],[49.276858541132604,174.7015614075973],[49.00424178154825,17(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_3
|
[
229,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[157,191],[159,189],[162,189],[159,189],[155,188],[157,188],[159,189],[157,191],[158,191],[159,187](...TRUNCATED)
| [[49.94763105944286,174.2543320903707],[49.984082831092564,174.6666151547932],[49.869301756726706,17(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_4
|
[
163,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[160,187],[157,190],[159,186],[159,186],[156,187],[162,188],[156,187],[160,191],[159,186],[161,187](...TRUNCATED)
| [[49.57039403620873,173.92486687965922],[49.96663041328851,174.1252224639114],[50.0803721287105,173.(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_5
|
[
196,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[157,193],[159,190],[157,189],[157,187],[159,191],[155,192],[157,189],[156,189],[156,187],[159,188](...TRUNCATED)
| [[49.58776489404238,174.95866653338663],[49.72565424652203,174.72419496059928],[49.98102583514716,17(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_6
|
[
167,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[157,190],[156,191],[154,193],[159,190],[153,190],[157,192],[159,192],[156,194],[156,192],[159,190](...TRUNCATED)
| [[50.03332830643945,174.50831950937516],[49.74698501049753,174.66329769054246],[49.79827798277983,17(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_7
|
[
132,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[156,190],[157,190],[156,188],[159,189],[158,189],[158,192],[159,190],[159,193],[161,191],[157,193](...TRUNCATED)
| [[49.695273571670455,174.14435682840696],[50.04818714663624,173.8628559572592],[49.29290470038756,17(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_8
|
[
207,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[157,190],[157,186],[155,185],[156,189],[159,187],[158,185],[157,191],[159,191],[155,191],[153,188](...TRUNCATED)
| [[49.20890295965847,174.05137429846022],[49.72337572024637,174.42921716669977],[49.571759725861725,1(...TRUNCATED)
|
30V_Jan24
|
30V_Tra_9
|
[
151,
100,
350
] | [[[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,2(...TRUNCATED)
| [[160,192],[159,189],[157,189],[157,189],[158,192],[154,189],[157,190],[157,189],[155,187],[158,191](...TRUNCATED)
| [[49.80816401244737,174.46000366099213],[49.41452529712971,173.9177432235637],[48.900600282485875,17(...TRUNCATED)
|
End of preview. Expand
in Data Studio
Descriptions
Converting script
import pickle
from pathlib import Path
import numpy as np
from datasets import Dataset
DATA_DIR = Path("/path/to/cached/hugging_face/datasets/for/MLDS-NUS/Experimental_Images")
# should end with something like "snapshots/fd299418e9435f8fd98956a3f0a7344d208cc142"
def calc_left_right(data: np.ndarray):
left_rights = []
for im in data:
nonzero_columns = (im != 0).any(axis=-2)
left = nonzero_columns.argmax() if nonzero_columns.any() else -1
# Find the rightmost non-zero column
right = len(nonzero_columns) - 1 - nonzero_columns[::-1].argmax() if nonzero_columns.any() else -1
left_right = np.array([left, right])
left_rights.append(left_right)
left_rights = np.stack(left_rights, axis=0) # shape: (seq_len, 2)
return left_rights
def calc_barycenter(data: np.ndarray) -> np.ndarray:
"""
Calculate the barycenter of the polymer from the snapshot.
Assumes snapshot shape is (100, 500).
"""
xx = np.arange(data.shape[-2]).reshape(-1, 1)
bary_x = (data * xx).sum(axis=(-2, -1)) / data.sum(axis=(-2, -1))
yy = np.arange(data.shape[-1]).reshape(1, -1)
bary_y = (data * yy).sum(axis=(-2, -1)) / data.sum(axis=(-2, -1))
barycenter = np.stack([bary_x, bary_y], axis=-1) # (seq_len, 2)
return barycenter
def gen():
for folder in ["30V_Jan24", "60V_Dec24"]:
with open(DATA_DIR / f"{folder}.pkl", "rb") as f:
data = pickle.load(f)
for k, v in data.items():
frame = np.clip(v, 0, 255).astype(np.uint8) # save memory
left_rights = calc_left_right(255 - frame)
barycenters = calc_barycenter(255 - frame)
yield {
"config": folder,
"traj_id": k,
"shape": list(frame.shape),
"data": frame,
"left_right": left_rights,
"barycenter": barycenters,
}
ds = Dataset.from_generator(gen)
ds = ds.with_format("numpy")
ds.push_to_hub("MLDS-NUS/polymer-dynamics_experimental-data")
# upload by configs
def gen(folder: str):
with open(DATA_DIR / f"{folder}.pkl", "rb") as f:
data = pickle.load(f)
for k, v in data.items():
frame = np.clip(v, 0, 255).astype(np.uint8)
left_rights = calc_left_right(255 - frame)
barycenters = calc_barycenter(255 - frame)
yield {
"config": folder,
"traj_id": k,
"shape": list(frame.shape),
"data": frame,
"left_right": left_rights,
"barycenter": barycenters,
}
for config_name in ["30V_Jan24", "60V_Dec24"]:
ds = Dataset.from_generator(lambda cn=config_name: gen(cn))
ds = ds.with_format("numpy")
ds.push_to_hub(
"MLDS-NUS/polymer-dynamics_experimental-data",
config_name=config_name,
data_dir=f"{config_name}",
)
How to use
Directly loading by datasets is supported now!
from datasets import load_dataset
import numpy as np
hf_dataset_30V = load_dataset("MLDS-NUS/polymer-dynamics_experimental-data", config_name="30V_Jan24")
hf_dataset_60V = load_dataset("MLDS-NUS/polymer-dynamics_experimental-data", config_name="60V_Jan24")
hf_dataset_30V = hf_dataset_30V.with_format("numpy")["train"]
hf_dataset_60V = hf_dataset_60V.with_format("numpy")["train"]
for sample in hf_dataset_30V:
for k, v in sample.items():
if isinstance(v, np.ndarray):
print(f"{k}: {type(v)}, shape={v.shape}, dtype={v.dtype}")
else:
print(f"{k}: {v}")
output:
config: 30V_Jan24
traj_id: 30V_Tra_0
shape: <class 'numpy.ndarray'>, shape=(3,), dtype=int64
data: <class 'numpy.ndarray'>, shape=(160, 100, 350), dtype=int64
left_right: <class 'numpy.ndarray'>, shape=(160, 2), dtype=int64
barycenter: <class 'numpy.ndarray'>, shape=(160, 2), dtype=float32
How to contribute
import numpy as np
from datasets import Dataset
def gen(config_name: str):
for data in your_database_retriever(config_name):
frame = ...
traj_id = ...
shape = ...
left_rights = ...
barycenters = ...
yield {
"config": config_name,
"traj_id": traj_id,
"shape": shape,
"data": data, # a np.ndarray object of shape `shape`
"left_right": left_rights,
"barycenter": barycenters,
}
config_name = ...
ds = Dataset.from_generator(lambda cn=config_name: gen(cn))
ds = ds.with_format("numpy")
ds.push_to_hub(
"MLDS-NUS/polymer-dynamics_experimental-data",
config_name=config_name,
data_dir=f"{config_name}",
)
- Downloads last month
- 34