Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coPylot IO #112

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added copylot/io/__init__.py
Empty file.
49 changes: 49 additions & 0 deletions copylot/io/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import tensorstore as ts


class Dataset:
def __init__(
self,
path,
nb_slices: int = 16,
nb_view: int = 1,
nb_frames: int = 1,
y_len: int = 2048,
x_len: int = 2048,
):
self.ds = ts.open(
{
"driver": "zarr",
'kvstore': {
'driver': 'file',
'path': path,
},
"key_encoding": ".",
"metadata": {
"shape": [nb_slices, nb_view, nb_frames, y_len, x_len],
"chunks": [128, 1, 128, 128, 128],
"dtype": "<i2",
"order": "C",
"compressor": {
"id": "blosc",
"shuffle": -1,
"clevel": 5,
"cname": "lz4",
},
},
'create': True,
'delete_existing': True,
}
).result()

@property
def shape(self):
return self.ds.shape

# TODO: dtype, channel, etc..

def sync_write(self):
raise NotImplementedError

def async_write(self):
raise NotImplementedError
42 changes: 42 additions & 0 deletions copylot/io/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import tempfile
from os import makedirs
from os.path import exists


def get_home_folder():
"""
Method that returns home folder in the current runtime.

Returns
-------
str

"""
from pathlib import Path

home_folder = f"{Path.home()}"
return home_folder


def get_temp_folder():
"""
Method that creates a new temp folder and returns
the path to the created temp folder.

Returns
-------
str

"""
temp_folder = None

try:
temp_folder = tempfile.gettempdir()
if exists(temp_folder):
raise FileExistsError
else:
makedirs(temp_folder)
except Exception:
pass

return temp_folder
Empty file added copylot/io/test/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions copylot/io/test/test_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from os import access, W_OK
from os.path import exists

from copylot.util import get_temp_folder, get_home_folder


def test_home_folder():
home_folder = get_home_folder()
print(home_folder)
assert exists(home_folder)
assert access(home_folder, W_OK)


def test_temp_folder():
temp_folder = get_temp_folder()
print(temp_folder)
assert exists(temp_folder)
assert access(temp_folder, W_OK)