|
14 | 14 | from typing import TYPE_CHECKING, Any, Literal |
15 | 15 |
|
16 | 16 | import numpy |
17 | | -from tqdm.auto import trange |
| 17 | +from tqdm.auto import tqdm |
18 | 18 |
|
19 | 19 | import qcodes |
20 | 20 | from qcodes.dataset.data_set_protocol import ( |
@@ -246,7 +246,8 @@ def __init__( |
246 | 246 | #: In memory representation of the data in the dataset. |
247 | 247 | self._cache: DataSetCacheWithDBBackend = DataSetCacheWithDBBackend(self) |
248 | 248 | self._results: list[dict[str, VALUE]] = [] |
249 | | - self._in_memory_cache = in_memory_cache |
| 249 | + self._in_memory_cache: bool = in_memory_cache |
| 250 | + self._max_num_files_export = 100 |
250 | 251 | self._export_limit = 1000 |
251 | 252 |
|
252 | 253 | if run_id is not None: |
@@ -1484,6 +1485,21 @@ def _set_export_info(self, export_info: ExportInfo) -> None: |
1484 | 1485 |
|
1485 | 1486 | def _export_as_netcdf(self, path: Path, file_name: str) -> Path: |
1486 | 1487 | """Export data as netcdf to a given path with file prefix""" |
| 1488 | + |
| 1489 | + def generate_steps(num_rows, max_num_steps) -> list[tuple[int, int]]: |
| 1490 | + if max_num_steps >= num_rows: |
| 1491 | + return [(i + 1, i + 1) for i in range(num_rows)] |
| 1492 | + |
| 1493 | + step_size, remainder = divmod(num_rows, max_num_steps) |
| 1494 | + limits = [ |
| 1495 | + (i * step_size + 1, (i + 1) * step_size) for i in range(max_num_steps) |
| 1496 | + ] |
| 1497 | + |
| 1498 | + if remainder > 0: |
| 1499 | + limits[-1] = (limits[-1][0], (step_size) * max_num_steps + remainder) |
| 1500 | + |
| 1501 | + return limits |
| 1502 | + |
1487 | 1503 | import xarray as xr |
1488 | 1504 |
|
1489 | 1505 | file_path = path / file_name |
@@ -1514,12 +1530,16 @@ def _export_as_netcdf(self, path: Path, file_name: str) -> Path: |
1514 | 1530 | "temp_dir": temp_dir, |
1515 | 1531 | }, |
1516 | 1532 | ) |
1517 | | - num_files = len(self) |
| 1533 | + num_rows = len(self) |
| 1534 | + steps = generate_steps(num_rows, self._max_num_files_export) |
| 1535 | + num_files = len(steps) |
1518 | 1536 | num_digits = len(str(num_files)) |
1519 | 1537 | file_name_template = f"ds_{{:0{num_digits}d}}.nc" |
1520 | | - for i in trange(num_files, desc="Writing individual files"): |
| 1538 | + for i, (start, stop) in tqdm( |
| 1539 | + enumerate(steps), total=num_files, desc="Writing individual files" |
| 1540 | + ): |
1521 | 1541 | xarray_to_h5netcdf_with_complex_numbers( |
1522 | | - self.to_xarray_dataset(start=i + 1, end=i + 1), |
| 1542 | + self.to_xarray_dataset(start=start, end=stop), |
1523 | 1543 | temp_path / file_name_template.format(i), |
1524 | 1544 | ) |
1525 | 1545 | files = tuple(temp_path.glob("*.nc")) |
|
0 commit comments