Skip to content

Commit 05655c4

Browse files
authored
Precise conversions (#99)
* More specific conversion. * More precise conversions.
1 parent 9f3b12d commit 05655c4

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

examples/SWIFTGalaxy_Colibre_QuickStart.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
" fig = plt.figure(fignum, figsize=(10, 3))\n",
254254
" sp1, sp2, sp3 = [fig.add_subplot(1, 3, i) for i in range(1, 4)]\n",
255255
" sp1.imshow(\n",
256-
" matplotlib.colors.LogNorm()(gas_map.to_value(u.solMass / u.kpc**2).T),\n",
256+
" matplotlib.colors.LogNorm()(gas_map.to_physical_value(u.solMass / u.kpc**2).T),\n",
257257
" cmap=\"viridis\",\n",
258258
" extent=disc_region,\n",
259259
" origin=\"lower\",\n",
@@ -271,7 +271,7 @@
271271
" transform=sp1.transAxes,\n",
272272
" )\n",
273273
" sp2.imshow(\n",
274-
" matplotlib.colors.LogNorm()(dm_map.to_value(u.solMass / u.kpc**2).T),\n",
274+
" matplotlib.colors.LogNorm()(dm_map.to_physical_value(u.solMass / u.kpc**2).T),\n",
275275
" cmap=\"inferno\",\n",
276276
" extent=halo_region,\n",
277277
" origin=\"lower\",\n",
@@ -294,7 +294,7 @@
294294
" transform=sp2.transAxes,\n",
295295
" )\n",
296296
" sp3.imshow(\n",
297-
" matplotlib.colors.LogNorm()(star_map.to_value(u.solMass / u.kpc**2).T),\n",
297+
" matplotlib.colors.LogNorm()(star_map.to_physical_value(u.solMass / u.kpc**2).T),\n",
298298
" cmap=\"magma\",\n",
299299
" extent=disc_region,\n",
300300
" origin=\"lower\",\n",
@@ -424,7 +424,7 @@
424424
"from scipy.spatial.transform import Rotation\n",
425425
"\n",
426426
"Lstars = sg.halo_catalogue.exclusive_sphere_10kpc.angular_momentum_stars.squeeze()\n",
427-
"zhat = (Lstars / np.sqrt(np.sum(Lstars**2))).to_value(\n",
427+
"zhat = (Lstars / np.sqrt(np.sum(Lstars**2))).to_physical_value(\n",
428428
" u.dimensionless\n",
429429
") # we'll align L with the z-axis\n",
430430
"arb = (\n",
@@ -467,8 +467,8 @@
467467
],
468468
"source": [
469469
"plt.plot(\n",
470-
" sg.stars.spherical_velocities.r.to_value(u.km / u.s),\n",
471-
" sg.stars.spherical_velocities.phi.to_value(u.km / u.s),\n",
470+
" sg.stars.spherical_velocities.r.to_physical_value(u.km / u.s),\n",
471+
" sg.stars.spherical_velocities.phi.to_physical_value(u.km / u.s),\n",
472472
" \",k\",\n",
473473
" rasterized=True,\n",
474474
")\n",

swiftgalaxy/halo_catalogues.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,11 @@ def lazy_mask() -> NDArray:
847847
"""
848848
mask = getattr(
849849
sg, group_name
850-
)._particle_dataset.group_nr_bound.to_value(
850+
)._particle_dataset.group_nr_bound.to_physical_value(
851851
u.dimensionless
852-
) == self.input_halos.halo_catalogue_index.to_value(u.dimensionless)
852+
) == self.input_halos.halo_catalogue_index.to_physical_value(
853+
u.dimensionless
854+
)
853855
if mask_loaded:
854856
# mask the group_nr_bound array that we loaded
855857
getattr(sg, group_name)._particle_dataset._group_nr_bound = getattr(

swiftgalaxy/iterator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def _eval_sparse_optimized_solution(self) -> None:
308308
)
309309
// sm.cell_size[np.newaxis, :, np.newaxis]
310310
)
311-
.to_value(u.dimensionless)
311+
.to_comoving_value(u.dimensionless)
312312
.astype(int)
313313
)
314314
unique_region_indices, inv = np.unique(
@@ -377,14 +377,14 @@ def _eval_dense_optimized_solution(self) -> None:
377377
# in the same grid location
378378
grid_element_dim = (
379379
np.max(target_sizes // sm.cell_size[np.newaxis], axis=0)
380-
.to_value(u.dimensionless)
380+
.to_comoving_value(u.dimensionless)
381381
.astype(int)
382382
+ 1
383383
)
384384
# If the grid doesn't fully cover the box need to add one more grid cell to
385385
# cover "too much".
386386
target_grid_offsets, target_grid_indices = np.modf(
387-
(target_centres / (grid_element_dim * sm.cell_size)).to_value(
387+
(target_centres / (grid_element_dim * sm.cell_size)).to_comoving_value(
388388
u.dimensionless
389389
)
390390
)
@@ -425,7 +425,7 @@ def _eval_dense_optimized_solution(self) -> None:
425425
np.prod(
426426
np.ceil(
427427
np.diff(unique_regions, axis=2).squeeze(axis=2) / sm.cell_size
428-
).to_value(u.dimensionless),
428+
).to_comoving_value(u.dimensionless),
429429
axis=1,
430430
)
431431
)
@@ -435,7 +435,7 @@ def _eval_dense_optimized_solution(self) -> None:
435435
np.prod(
436436
np.ceil(
437437
np.diff(unique_regions, axis=2).squeeze(axis=2) / sm.cell_size
438-
).to_value(u.dimensionless)
438+
).to_comoving_value(u.dimensionless)
439439
+ 1,
440440
axis=1,
441441
)

0 commit comments

Comments
 (0)