-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUniversalLoader2.py
112 lines (69 loc) · 2.43 KB
/
UniversalLoader2.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
101
102
103
104
105
106
107
108
109
110
111
112
import dm3_lib as dm3
import numpy as np
from matplotlib import pyplot as plt
def tif_extract(filepath):
"""
TIFs are assumed to be images unless stated in the session
Inputs:
filepath: string, location of data on drive
Outputs:
profile_data: array,
"""
raise NotImplementedError
# Due to the lack of a universal schema for metatags at the current time
# we leave it to the user to proscribe the relevant calibrations
return image_data
def dm3_extract(filepath):
"""
DM3 data is assumed to be an image unless stated in the session
Inputs:
filepath: string, location of data on drive
Outputs:
image_data: array,
"""
# Read in the data as a numpy array
raise NotImplementedError
# Due to the lack of a universal schema for metatags at the current time
# we leave it to the user to proscribe the relevant calibrations
return image_data
def csv_extract(filepath):
"""
Data is expected to be a profile in rows or columns with no headers.
Singular profiles are expected to be in pixels unless a scale bar is explicitly supplied
Inputs:
filepath: string, location of data on drive
Outputs:
profile_data: array,
"""
csv_file = np.genfromtxt(open(filepath, "r"), delimiter=",")
profile_data = csv_file
# Orients columnar data into rows if necessary
print(profile_data.shape)
if len(profile_data.shape) != 1:
if profile_data.shape[0] > profile_data.shape[1]:
profile_data = profile_data.T
print(profile_data.shape)
# Due to the lack of a universal schema for metatags at the current time
# we leave it to the user to proscribe the relevant calibrations
return profile_data[1,:],profile_data[0,:]
def txt_extract(filepath):
"""
Data is expected to be a profile in rows or columns with no headers.
Singular profiles are expected to be in pixels unless a scale bar is explicitly supplied
Inputs:
filepath: string, location of data on drive
Outputs:
profile_data: array,
"""
# Read in the data as a numpy array
text_file = np.genfromtxt(open(filepath, "r"), delimiter="\t")
profile_data = text_file
# Orients columnar data into rows if necessary
print(profile_data.shape)
if len(profile_data.shape) != 1:
if profile_data.shape[0] > profile_data.shape[1]:
profile_data = profile_data.T
print(profile_data.shape)
# Due to the lack of a universal schema for metatags at the current time
# we leave it to the user to proscribe the relevant calibrations
return profile_data