-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpc_ds_desc.py
100 lines (82 loc) · 3.04 KB
/
hpc_ds_desc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from enum import Enum
from types import SimpleNamespace
from hpc_ds_types import Point3D, adjust_range, COMPRESSIONS, VOXEL_TYPES, EXTRA_VERSIONS
import json
class HPCDatastoreDescription(object):
"""Datastore metadata object"""
def __init__(self, dimensions=Point3D(1,1,1), timepoints=1, channels=1,
angles=1, voxel_type="uint16",
voxel_resolutions=Point3D(1,1,1),
voxel_unit="um", time_res=1.0, time_unit ="seconds",
channel_res=1.0, channel_unit="channel",
angle_res=1.0, angle_unit="deg", resolution_levels=1,
block_dimensions=Point3D(64,64,64),compression="gzip",
transformations=None,
json_objects=None):
if voxel_type in VOXEL_TYPES:
self.voxelType=voxel_type # Name has to keep JSON compatibility
else:
raise Exception("Voxel type %s not found" % voxel_type)
if json_objects is None:
self.timepoints = timepoints
self.channels = channels
self.angles = angles
#if voxel_unit in VOXEL_UNITS: # No check is really needed
self.voxelUnit=voxel_unit
#else:
# raise Exception("Voxel unit %s not found" % voxel_unit)
if compression in COMPRESSIONS:
self.compression=compression
else:
raise Exception("Compression type %s not found" % compression)
self.dimensions = Point3D.adjust_range(dimensions)
self.voxelResolution = Point3D.adjust_range(voxel_resolutions,
0.0, datatype=float)
self.timepointResolution = {
"value" : adjust_range(time_res, 0, datatype=float),
"unit" : time_unit
}
#TODO: We should really consider unifying s/seconds, um/microns in API
self.channelResolution = {
"value" : channel_res,
"unit" : channel_unit
}
self.angleResolution = {
"value" : angle_res,
"unit" : angle_unit
}
resolution_levels = adjust_range(resolution_levels, 1)
rl_entries = []
for level in range(0, resolution_levels):
level_v = 1 << level;
rl_entries.append({
"resolutions" : Point3D(level_v, level_v, level_v),
"blockDimensions" : Point3D.adjust_range(block_dimensions)
})
self.resolutionLevels = rl_entries
#self.versions = [0]
self.transformations = transformations
else:
self.__dict__ = json_objects
@staticmethod
def load_json(data):
"""Loading of data store description data from JSON to a simple object"""
return json.loads(data, object_hook=lambda d: SimpleNamespace(**d))
def check_version(self, version):
if (versions is not None and version in versions) or (version in EXTRA_VERSIONS):
return True
return False
def from_json(self, data):
"""Importing data store description from JSON representation"""
self.__dict__ = HPCDatastoreDescription.load_json(data).__dict__
def to_json(self):
"""Exporting data store description into JSON representation"""
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=False, indent=2)
def __str__(self):
"""String conversion of internal description to human readable text"""
out_s = ""
for k in self.__dict__:
out_s += "%s: %s\n" % (k,self.__dict__[k])
return out_s