blissdata-mosca 2.0.4__tar.gz → 2.0.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: blissdata-mosca
3
- Version: 2.0.4
4
- Requires-Python: <3.13,>=3.10
3
+ Version: 2.0.7
4
+ Requires-Python: >=3.10
5
5
  Requires-Dist: blissdata
6
6
  Requires-Dist: h5py
7
- Requires-Dist: mosca-client
7
+ Requires-Dist: mosca-client>=2.0.7
8
8
  Requires-Dist: numpy
@@ -3,14 +3,14 @@ mosca = "blissdata_mosca"
3
3
 
4
4
  [project]
5
5
  name = "blissdata-mosca"
6
- requires-python = ">=3.10,<3.13"
7
- version = "2.0.4"
6
+ requires-python = ">=3.10"
7
+ version = "2.0.7"
8
8
 
9
9
  dependencies = [
10
10
  "numpy",
11
11
  "h5py",
12
12
  "blissdata",
13
- "mosca_client"
13
+ "mosca_client>=2.0.7"
14
14
  ]
15
15
 
16
16
  [build-system]
@@ -24,6 +24,14 @@ version = { workspace = true }
24
24
  [tool.pixi.package.build]
25
25
  backend = { name = "pixi-build-python", version = "0.*" }
26
26
 
27
+ [tool.pixi.package.build.config]
28
+ # run dependencies are mapped from [project.dependencies]
29
+ ignore-pypi-mapping = false
30
+
31
+ [tool.pixi.package.run-dependencies]
32
+ # local packages, not in the pypi->conda mapping
33
+ mosca-client = ">=2.0.7"
34
+
27
35
  [tool.pixi.package.host-dependencies]
28
36
  hatchling = "==1.26.3"
29
37
 
@@ -15,7 +15,7 @@ from blissdata.exceptions import (
15
15
  EmptyViewException,
16
16
  )
17
17
 
18
- from mosca_client.tango.mosca import Reader as MoscaReader
18
+ from mosca_client.tango.readers import FileReader, MixedReader
19
19
 
20
20
 
21
21
  PROTOCOL_VERSION = 1
@@ -63,10 +63,37 @@ class MoscaStream(BaseStream):
63
63
  self._data_index = info["data_index"]
64
64
  self._detector = info["detector"]
65
65
 
66
- self._reader = MoscaReader(
67
- event_stream.info["mosca_info"]["server_url"],
68
- acq_id=event_stream.info["mosca_info"]["acq_id"]
69
- )
66
+ self._file_reader = None
67
+ self._mixed_reader = None
68
+
69
+ @property
70
+ def reader(self):
71
+ mosca_info = self.info["mosca_info"]
72
+ # if mosca_info["saving_enabled"]:
73
+ # return self.file_reader
74
+ return self.mixed_reader
75
+
76
+ @property
77
+ def file_reader(self):
78
+ if self._file_reader is None:
79
+ mosca_info = self.info["mosca_info"]
80
+ self._file_reader = FileReader(mosca_info["file_path"],
81
+ mosca_info["file_prefix"],
82
+ mosca_info["data_path"],
83
+ mosca_info["enabled_detectors"],
84
+ self.shape[0],
85
+ mosca_info["points_per_file"])
86
+ return self._file_reader
87
+
88
+ @property
89
+ def mixed_reader(self):
90
+ if self._mixed_reader is None:
91
+ mosca_info = self.info["mosca_info"]
92
+ self._mixed_reader = MixedReader(
93
+ mosca_info["server_url"],
94
+ mosca_info["acq_id"],
95
+ saving_directory=mosca_info["file_path"])
96
+ return self._mixed_reader
70
97
 
71
98
  @property
72
99
  def kind(self):
@@ -108,11 +135,13 @@ class MoscaStream(BaseStream):
108
135
 
109
136
  if saving:
110
137
  saving_keys = {
111
- "file_path",
138
+ "file_path", # local directory (seen by bliss/blisswriter)
112
139
  "data_path",
113
140
  "file_format",
114
141
  "file_prefix",
115
142
  "points_per_file",
143
+ "saving_enabled",
144
+ "enabled_detectors"
116
145
  }
117
146
  missing_keys = saving_keys - saving.keys()
118
147
  extra_keys = saving.keys() - saving_keys
@@ -134,7 +163,7 @@ class MoscaStream(BaseStream):
134
163
  return "mosca"
135
164
 
136
165
  def __len__(self):
137
- return self._reader.n_available_points
166
+ return self.mixed_reader.n_available_points
138
167
 
139
168
  def __getitem__(self, key):
140
169
  if self._last_read_index == -1:
@@ -163,77 +192,18 @@ class MoscaStream(BaseStream):
163
192
  self._last_saved_index = last_event["last_saved_index"]
164
193
 
165
194
  def _read(self, start, stop):
166
- if stop - 1 <= self._last_saved_index:
167
- data = self._get_from_files(start, stop)
168
- elif start < self._last_saved_index:
169
- file_data = self._get_from_files(start, self._last_saved_index + 1)
170
- server_data = self._reader.read_spectra(self._last_saved_index + 1, stop)[self.data_index]
171
- data = np.concatenate((file_data, server_data), axis=0)
172
- else:
173
- data = self._reader.read_spectra(start, stop)[self.data_index]
174
- return data
175
-
176
- def _get_from_files(self, start, stop):
177
- n_points = stop - start
178
-
179
- data = np.zeros((n_points, self.shape[-1]), self.dtype)
180
-
181
- assert start < stop
182
- data_path = f"{self._data_path}/spectra"
183
-
184
- filenames, dset_idx = self._idx_to_files(start, stop)
185
-
186
- data_idx = np.add.accumulate(np.diff(dset_idx, axis=1)[:, 0])
187
- data_idx = np.concatenate(([0], data_idx))
188
-
189
- for f_idx, filename in enumerate(filenames):
190
- dset_0, dset_1 = dset_idx[f_idx]
191
- data_0, data_1 = data_idx[f_idx:f_idx + 2]
192
- with h5py.File(filename, "r") as h5f:
193
- data[data_0:data_1, :] = h5f[data_path][self.data_index, dset_0:dset_1, :]
194
-
195
+ data = self.reader.read_spectra(start,
196
+ stop,
197
+ read_detectors=[self._detector])
198
+ data = data.squeeze(axis=0)
195
199
  return data
196
200
 
197
- def _idx_to_files(self, start, stop):
198
- """ Given a range of points [start .. stop[, returns
199
- a list of files containing those points,
200
- along with the indices of those points within the files.
201
-
202
- Returns three objects:
203
- - ordered list of N file names
204
- - ordered list of N 2-tuples, dataset indices range within each file """
205
-
206
- assert start < stop
207
- assert start >= 0
208
-
209
- ppf = self._points_per_file
210
- basename = os.path.join(self._file_path, f"{self._file_prefix}spectra_")
211
-
212
- # file indices, points interval within the returned data
213
- file_idx, data_idx = np.unique(np.arange(start, stop) // ppf,
214
- return_index=True)
215
- filenames = [f"{basename}{f_idx:04d}.h5" for f_idx in file_idx]
216
-
217
- n_points = stop - start
218
- dset_idx = np.zeros((len(filenames), 2), dtype=int)
219
-
220
- def _last(n):
221
- if n >= ppf:
222
- return ppf
223
- return n
224
-
225
- dset_idx[0][:] = [start % ppf, _last((start % ppf) + n_points)]
226
- for i, idx in enumerate(data_idx[1:], start=1):
227
- dset_idx[i][:] = [0, _last(n_points - idx)]
228
-
229
- return filenames, dset_idx
230
-
231
201
  def get_references(self, start, stop):
232
202
  if self._last_read_index == -1:
233
203
  self._update()
234
204
 
235
205
  data_path = f"{self._data_path}/spectra_{self._detector:02d}"
236
- files, dset_idx = self._idx_to_files(start, stop)
206
+ files, dset_idx = self.file_reader.get_files(start, stop)
237
207
 
238
208
  references = [SpectraReference(file, data_path, idx)
239
209
  for file, indices in zip(files, dset_idx)
@@ -248,10 +218,8 @@ class MoscaStream(BaseStream):
248
218
  return True
249
219
 
250
220
  def _build_view_from_events(self, index, events, last_only):
251
- # print("===> EVENT", index, events, last_only)
252
221
  lri = events.data[-1]["last_read_index"]
253
222
  lsi = events.data[-1]["last_saved_index"]
254
- # n_spec = len(self)
255
223
  if lri < index:
256
224
  raise EmptyViewException
257
225
 
@@ -264,11 +232,14 @@ class MoscaStream(BaseStream):
264
232
  return MoscaView(self, start, lri + 1)
265
233
 
266
234
  def get_last_live_spectra(self):
267
- print("R1", self.data_index)
268
235
  if self._last_read_index == -1:
269
236
  self._update()
270
237
  index = self._last_read_index
271
- data = self._reader.read_spectra(index, self._last_read_index + 1)[self.data_index, 0]
238
+ # force reading from the server
239
+ data = self.mixed_reader.reader.read_spectra(index,
240
+ index + 1,
241
+ read_detectors=[self._detector])
242
+ data = data.squeeze(axis=(0, 1))
272
243
  return SpectraData(array=data, frame_id=index)
273
244
 
274
245