Skip to content

Instantly share code, notes, and snippets.

@ihnorton
Created July 30, 2019 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihnorton/9cb65817c4bfa0846eb8fb013a484cac to your computer and use it in GitHub Desktop.
Save ihnorton/9cb65817c4bfa0846eb8fb013a484cac to your computer and use it in GitHub Desktop.
Forum post 99 example
#%%
import tiledb
import numpy as np
import os
#%%
number_of_streamlines = 190
max_line_length = 180
#%%
current_points_MA = np.array([(-24.42347 , 9.71168 , 55.68498 ),
(-24.702614, 9.554029 , 55.33545 ),
(-24.996378, 9.345692 , 55.02647 ),
(-25.277544, 9.1398945 , 54.705322),
(-25.54551 , 8.932631 , 54.37486 ),
(-25.768175, 8.732276 , 54.010162),
(-25.908112, 8.598939 , 53.579025),
(-25.973198, 8.54236 , 53.111088),
(-26.003119, 8.514971 , 52.635143),
(-26.029522, 8.490222 , 52.158764),
(-26.051535, 8.469237 , 51.681812),
(-26.072304, 8.4494915 , 51.204765),
(-26.093727, 8.429146 , 50.72789 ),
(-26.117014, 8.407098 , 50.251354),
(-26.143465, 8.382201 , 49.775368),
(-26.174398, 8.353237 , 49.30016 ),
(-26.210732, 8.319152 , 48.82599 ),
(-26.252628, 8.279227 , 48.35303 ),
(-26.29912 , 8.233187 , 47.881306),
(-26.348297, 8.181389 , 47.410603),
(-26.398415, 8.124311 , 46.940666),
(-26.448315, 8.066681 , 46.470646),
(-26.49668 , 8.007075 , 46.00058 ),
(-26.541199, 7.9418354 , 45.530804),
(-26.579256, 7.8693175 , 45.0614 ),
(-26.607166, 7.7890153 , 44.592335),
(-26.561144, 7.6790276 , 44.1287 ),
(-26.446619, 7.5537877 , 43.67744 ),
(-26.28518 , 7.409782 , 43.243004),
(-26.095098, 7.2423067 , 42.82592 ),
(-25.896486, 7.066001 , 42.41535 ),
(-25.688393, 6.8869576 , 42.00967 ),
(-25.47125 , 6.710155 , 41.607018),
(-25.250254, 6.5352135 , 41.205433),
(-25.029028, 6.360362 , 40.804024),
(-24.817612, 6.181912 , 40.399803),
(-24.613834, 6.000414 , 39.9937 ),
(-24.420778, 5.8142943 , 39.58528 ),
(-24.256405, 5.6141644 , 39.172512),
(-24.109741, 5.402663 , 38.759262),
(-23.996386, 5.1699753 , 38.347355),
(-23.905586, 4.920069 , 37.93953 ),
(-23.850676, 4.64224 , 37.542053),
(-23.813694, 4.3481536 , 37.152687),
(-23.79459 , 4.0371847 , 36.77322 ),
(-23.794044, 3.7112298 , 36.403862),
(-23.814959, 3.3662107 , 36.049618),
(-23.87903 , 2.9847753 , 35.733368),
(-23.960941, 2.5891223 , 35.435596),
(-24.049429, 2.184674 , 35.14897 ),
(-24.145554, 1.7751309 , 34.87026 ),
(-24.26284 , 1.3581793 , 34.60877 ),
(-24.391994, 0.94499743, 34.347473),
(-24.532162, 0.5335869 , 34.08916 ),
(-24.675556, 0.13690415, 33.813778),
(-24.809614, -0.24497059, 33.516922),
(-24.954828, -0.6214233 , 33.219257),
(-25.108805, -0.9933749 , 32.921024),
(-25.279896, -1.3587152 , 32.625057),
(-25.45801 , -1.7177614 , 32.326687),
(-25.647968, -2.069852 , 32.028553),
(-25.847132, -2.4146836 , 31.72927 ),
(-26.067636, -2.7446563 , 31.430677),
(-26.29919 , -3.0688238 , 31.135096),
(-26.564793, -3.3801181 , 30.85646 ),
(-26.841331, -3.6879923 , 30.585619),
(-27.144878, -3.9871974 , 30.336334),
(-27.46906 , -4.2791867 , 30.10709 ),
(-27.807821, -4.564138 , 29.89287 ),
(-28.169004, -4.838772 , 29.706997),
(-28.568245, -5.092034 , 29.58708 ),
(-28.985075, -5.3296556 , 29.514252),
(-29.415369, -5.546986 , 29.492323),
(-29.855707, -5.73555 , 29.522627),
(-30.300894, -5.8902817 , 29.602703),
(-30.745026, -6.0110135 , 29.72819 ),
(-31.18271 , -6.0991945 , 29.89565 ),
(-31.608778, -6.1563487 , 30.103262),
(-32.018295, -6.1858363 , 30.348906),
(-32.408813, -6.195413 , 30.62717 ),
(-32.78839 , -6.199328 , 30.921398),
(-33.152332, -6.2001233 , 31.235786),
(-33.497074, -6.201151 , 31.57208 ),
(-33.83315 , -6.205498 , 31.917807),
(-34.152596, -6.2179255 , 32.27947 ),
(-34.456974, -6.240189 , 32.654175),
(-34.74735 , -6.273346 , 33.03988 ),
(-35.0121 , -6.3322864 , 33.441284),
(-35.256844, -6.4068365 , 33.85393 ),
(-35.462177, -6.5167027 , 34.281693),
(-35.60888 , -6.6804495 , 34.719463),
(-35.697155, -6.8936415 , 35.15581 ),
(-35.74831 , -7.1311193 , 35.588596),
(-35.767185, -7.380773 , 36.019543),
(-35.771233, -7.6304984 , 36.451744),
(-35.761852, -7.8766747 , 36.886402),
(-35.740414, -8.117681 , 37.32371 ),
(-35.707985, -8.353055 , 37.763348),
(-35.656143, -8.578135 , 38.20616 ),
(-35.586906, -8.795145 , 38.64998 ),
(-35.500607, -9.005947 , 39.092915),
(-35.405025, -9.214488 , 39.534145),
(-35.29837 , -9.42142 , 39.972576),
(-35.178963, -9.627391 , 40.406975),
(-35.04611 , -9.833067 , 40.83625 ),
(-34.900608, -10.039137 , 41.25977 ),
(-34.745003, -10.246509 , 41.677628),
(-34.583206, -10.4564905 , 42.090576),
(-34.419834, -10.670725 , 42.49981 ),
(-34.25907 , -10.890774 , 42.906433),
(-34.1048 , -11.117712 , 43.31155 ),
(-33.960274, -11.3512745 , 43.716457),
(-33.82792 , -11.589977 , 44.12254 ),
(-33.708576, -11.83188 , 44.53075 ),
(-33.601723, -12.075419 , 44.941406),
(-33.5058 , -12.319913 , 45.354122),
(-33.418278, -12.5654335 , 45.76799 ),
(-33.33596 , -12.812519 , 46.1818 ),
(-33.25809 , -13.064574 , 46.593456),
(-33.181736, -13.322189 , 47.001797),
(-33.105602, -13.585256 , 47.406456),
(-33.029095, -13.853087 , 47.807594),
(-32.95191 , -14.124648 , 48.205704),
(-32.87414 , -14.398879 , 48.601444)],
dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
current_points = np.array([[-24.42347 , 9.71168 , 55.68498 ],
[-24.702614 , 9.554029 , 55.33545 ],
[-24.996378 , 9.345692 , 55.02647 ],
[-25.277544 , 9.1398945 , 54.705322 ],
[-25.54551 , 8.932631 , 54.37486 ],
[-25.768175 , 8.732276 , 54.010162 ],
[-25.908112 , 8.598939 , 53.579025 ],
[-25.973198 , 8.54236 , 53.111088 ],
[-26.003119 , 8.514971 , 52.635143 ],
[-26.029522 , 8.490222 , 52.158764 ],
[-26.051535 , 8.469237 , 51.681812 ],
[-26.072304 , 8.4494915 , 51.204765 ],
[-26.093727 , 8.429146 , 50.72789 ],
[-26.117014 , 8.407098 , 50.251354 ],
[-26.143465 , 8.382201 , 49.775368 ],
[-26.174398 , 8.353237 , 49.30016 ],
[-26.210732 , 8.319152 , 48.82599 ],
[-26.252628 , 8.279227 , 48.35303 ],
[-26.29912 , 8.233187 , 47.881306 ],
[-26.348297 , 8.181389 , 47.410603 ],
[-26.398415 , 8.124311 , 46.940666 ],
[-26.448315 , 8.066681 , 46.470646 ],
[-26.49668 , 8.007075 , 46.00058 ],
[-26.541199 , 7.9418354 , 45.530804 ],
[-26.579256 , 7.8693175 , 45.0614 ],
[-26.607166 , 7.7890153 , 44.592335 ],
[-26.561144 , 7.6790276 , 44.1287 ],
[-26.446619 , 7.5537877 , 43.67744 ],
[-26.28518 , 7.409782 , 43.243004 ],
[-26.095098 , 7.2423067 , 42.82592 ],
[-25.896486 , 7.066001 , 42.41535 ],
[-25.688393 , 6.8869576 , 42.00967 ],
[-25.47125 , 6.710155 , 41.607018 ],
[-25.250254 , 6.5352135 , 41.205433 ],
[-25.029028 , 6.360362 , 40.804024 ],
[-24.817612 , 6.181912 , 40.399803 ],
[-24.613834 , 6.000414 , 39.9937 ],
[-24.420778 , 5.8142943 , 39.58528 ],
[-24.256405 , 5.6141644 , 39.172512 ],
[-24.109741 , 5.402663 , 38.759262 ],
[-23.996386 , 5.1699753 , 38.347355 ],
[-23.905586 , 4.920069 , 37.93953 ],
[-23.850676 , 4.64224 , 37.542053 ],
[-23.813694 , 4.3481536 , 37.152687 ],
[-23.79459 , 4.0371847 , 36.77322 ],
[-23.794044 , 3.7112298 , 36.403862 ],
[-23.814959 , 3.3662107 , 36.049618 ],
[-23.87903 , 2.9847753 , 35.733368 ],
[-23.960941 , 2.5891223 , 35.435596 ],
[-24.049429 , 2.184674 , 35.14897 ],
[-24.145554 , 1.7751309 , 34.87026 ],
[-24.26284 , 1.3581793 , 34.60877 ],
[-24.391994 , 0.94499743, 34.347473 ],
[-24.532162 , 0.5335869 , 34.08916 ],
[-24.675556 , 0.13690415, 33.813778 ],
[-24.809614 , -0.24497059, 33.516922 ],
[-24.954828 , -0.6214233 , 33.219257 ],
[-25.108805 , -0.9933749 , 32.921024 ],
[-25.279896 , -1.3587152 , 32.625057 ],
[-25.45801 , -1.7177614 , 32.326687 ],
[-25.647968 , -2.069852 , 32.028553 ],
[-25.847132 , -2.4146836 , 31.72927 ],
[-26.067636 , -2.7446563 , 31.430677 ],
[-26.29919 , -3.0688238 , 31.135096 ],
[-26.564793 , -3.3801181 , 30.85646 ],
[-26.841331 , -3.6879923 , 30.585619 ],
[-27.144878 , -3.9871974 , 30.336334 ],
[-27.46906 , -4.2791867 , 30.10709 ],
[-27.807821 , -4.564138 , 29.89287 ],
[-28.169004 , -4.838772 , 29.706997 ],
[-28.568245 , -5.092034 , 29.58708 ],
[-28.985075 , -5.3296556 , 29.514252 ],
[-29.415369 , -5.546986 , 29.492323 ],
[-29.855707 , -5.73555 , 29.522627 ],
[-30.300894 , -5.8902817 , 29.602703 ],
[-30.745026 , -6.0110135 , 29.72819 ],
[-31.18271 , -6.0991945 , 29.89565 ],
[-31.608778 , -6.1563487 , 30.103262 ],
[-32.018295 , -6.1858363 , 30.348906 ],
[-32.408813 , -6.195413 , 30.62717 ],
[-32.78839 , -6.199328 , 30.921398 ],
[-33.152332 , -6.2001233 , 31.235786 ],
[-33.497074 , -6.201151 , 31.57208 ],
[-33.83315 , -6.205498 , 31.917807 ],
[-34.152596 , -6.2179255 , 32.27947 ],
[-34.456974 , -6.240189 , 32.654175 ],
[-34.74735 , -6.273346 , 33.03988 ],
[-35.0121 , -6.3322864 , 33.441284 ],
[-35.256844 , -6.4068365 , 33.85393 ],
[-35.462177 , -6.5167027 , 34.281693 ],
[-35.60888 , -6.6804495 , 34.719463 ],
[-35.697155 , -6.8936415 , 35.15581 ],
[-35.74831 , -7.1311193 , 35.588596 ],
[-35.767185 , -7.380773 , 36.019543 ],
[-35.771233 , -7.6304984 , 36.451744 ],
[-35.761852 , -7.8766747 , 36.886402 ],
[-35.740414 , -8.117681 , 37.32371 ],
[-35.707985 , -8.353055 , 37.763348 ],
[-35.656143 , -8.578135 , 38.20616 ],
[-35.586906 , -8.795145 , 38.64998 ],
[-35.500607 , -9.005947 , 39.092915 ],
[-35.405025 , -9.214488 , 39.534145 ],
[-35.29837 , -9.42142 , 39.972576 ],
[-35.178963 , -9.627391 , 40.406975 ],
[-35.04611 , -9.833067 , 40.83625 ],
[-34.900608 , -10.039137 , 41.25977 ],
[-34.745003 , -10.246509 , 41.677628 ],
[-34.583206 , -10.4564905 , 42.090576 ],
[-34.419834 , -10.670725 , 42.49981 ],
[-34.25907 , -10.890774 , 42.906433 ],
[-34.1048 , -11.117712 , 43.31155 ],
[-33.960274 , -11.3512745 , 43.716457 ],
[-33.82792 , -11.589977 , 44.12254 ],
[-33.708576 , -11.83188 , 44.53075 ],
[-33.601723 , -12.075419 , 44.941406 ],
[-33.5058 , -12.319913 , 45.354122 ],
[-33.418278 , -12.5654335 , 45.76799 ],
[-33.33596 , -12.812519 , 46.1818 ],
[-33.25809 , -13.064574 , 46.593456 ],
[-33.181736 , -13.322189 , 47.001797 ],
[-33.105602 , -13.585256 , 47.406456 ],
[-33.029095 , -13.853087 , 47.807594 ],
[-32.95191 , -14.124648 , 48.205704 ],
[-32.87414 , -14.398879 , 48.601444 ]], dtype=np.float32)
line_index = 124
#%%
array_name = "trk_new_separate_xyz"
ctx = tiledb.Ctx()
dom = tiledb.Domain(tiledb.Dim(name="fibers", domain=(0,number_of_streamlines-1), tile=4, dtype=np.uint32),
tiledb.Dim(name="points", domain=(0,max_line_length-1), tile=4, dtype=np.uint32)
)
schema = tiledb.ArraySchema(domain=dom, sparse=True,
attrs=[tiledb.Attr(name="coordinates", dtype=np.dtype([("", np.float32),
("", np.float32),
("", np.float32)]))])
if os.path.isdir(array_name):
tiledb.remove(array_name)
tiledb.SparseArray.create(array_name, schema)
#%%
I, J = np.repeat(line_index-1, line_index), list(range(current_points.shape[0]))
#%%
with tiledb.SparseArray(array_name, mode='w') as A:
print(A)
A[I, J] = current_points
#%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment