|
1 | 1 | import numpy as np |
2 | 2 |
|
| 3 | +from yt._maintenance.numpy2_compat import COPY_FALSE |
3 | 4 | from yt.funcs import mylog |
4 | 5 | from yt.utilities.io_handler import BaseParticleIOHandler |
5 | 6 | from yt.utilities.on_demand_imports import _requests as requests |
@@ -36,26 +37,35 @@ def _read_particle_coords(self, chunks, ptf): |
36 | 37 | for data_file in self._sorted_chunk_iterator(chunks): |
37 | 38 | for ptype in ptf: |
38 | 39 | s = self._open_stream(data_file, (ptype, "Coordinates")) |
39 | | - c = np.frombuffer(s, dtype="float64") |
40 | | - c.shape = (c.shape[0] / 3.0, 3) |
| 40 | + c_raw = np.frombuffer(s, dtype="float64") |
| 41 | + c = np.reshape( |
| 42 | + c_raw, (c_raw.shape[0] // 3, 3), **COPY_FALSE.get("reshape") |
| 43 | + ) |
41 | 44 | yield ptype, (c[:, 0], c[:, 1], c[:, 2]), 0.0 |
42 | 45 |
|
43 | 46 | def _read_particle_fields(self, chunks, ptf, selector): |
44 | 47 | # Now we have all the sizes, and we can allocate |
45 | 48 | for data_file in self._sorted_chunk_iterator(chunks): |
46 | 49 | for ptype, field_list in sorted(ptf.items()): |
47 | 50 | s = self._open_stream(data_file, (ptype, "Coordinates")) |
48 | | - c = np.frombuffer(s, dtype="float64") |
49 | | - c.shape = (c.shape[0] / 3.0, 3) |
| 51 | + c_raw = np.frombuffer(s, dtype="float64") |
| 52 | + c = np.reshape( |
| 53 | + c_raw, c_raw.shape[0] // 3, 3, **COPY_FALSE.get("reshape") |
| 54 | + ) |
50 | 55 | mask = selector.select_points(c[:, 0], c[:, 1], c[:, 2], 0.0) |
51 | 56 | del c |
| 57 | + del c_raw |
52 | 58 | if mask is None: |
53 | 59 | continue |
54 | 60 | for field in field_list: |
55 | 61 | s = self._open_stream(data_file, (ptype, field)) |
56 | | - c = np.frombuffer(s, dtype="float64") |
| 62 | + c_raw = np.frombuffer(s, dtype="float64") |
57 | 63 | if field in self._vector_fields: |
58 | | - c.shape = (c.shape[0] / 3.0, 3) |
| 64 | + c = np.reshape( |
| 65 | + c_raw, |
| 66 | + (c_raw.shape[0] // 3, 3), |
| 67 | + **COPY_FALSE.get("reshape"), |
| 68 | + ) |
59 | 69 | data = c[mask, ...] |
60 | 70 | yield (ptype, field), data |
61 | 71 |
|
|
0 commit comments