From a5f13c76e0673cedcc923194f472d91e5bf0d062 Mon Sep 17 00:00:00 2001 From: Reijo Keskitalo Date: Mon, 28 Oct 2024 09:35:48 -0700 Subject: [PATCH 1/2] Fix HEALPix unit conversion at load time --- src/toast/pixels_io_healpix.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/toast/pixels_io_healpix.py b/src/toast/pixels_io_healpix.py index e1c377307..5e0b7c76d 100644 --- a/src/toast/pixels_io_healpix.py +++ b/src/toast/pixels_io_healpix.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015-2021 by the parties listed in the AUTHORS file. +# Copyright (c) 2015-2024 by the parties listed in the AUTHORS file. # All rights reserved. Use of this source code is governed by # a BSD-style license that can be found in the LICENSE file. @@ -77,18 +77,14 @@ def read_healpix_fits(pix, path, nest=True, comm_bytes=10000000): funits = pix.units if funits != pix.units: scale = 1.0 * funits - scale.to(pix.units) - fscale = scale.value + fscale = scale.to_value(pix.units) if nside_map != nside: - errors += "Wrong NSide: {} has {}, expected {}\n" "".format( - path, nside_map, nside - ) + errors += f"Wrong NSide: {path} has {nside_map}, expected {nside}\n" map_nnz = h[1].header["tfields"] if map_nnz != pix.n_value: - errors += "Wrong number of columns: {} has {}, expected {}\n" "".format( - path, map_nnz, pix.n_value - ) + errors += f"Wrong number of columns: {path} has {map_nnz}, " + errors += f"expected {pix.n_value}\n" h.close() if len(errors) != 0: raise RuntimeError(errors) From 4c058c627f1efbc93f0bab904db2965304f40da2 Mon Sep 17 00:00:00 2001 From: Reijo Keskitalo Date: Mon, 28 Oct 2024 15:51:48 -0700 Subject: [PATCH 2/2] Fix another place where unit conversion might have failed --- src/toast/pixels_io_healpix.py | 5 ++--- src/toast/utils.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/toast/pixels_io_healpix.py b/src/toast/pixels_io_healpix.py index 5e0b7c76d..4cca89723 100644 --- a/src/toast/pixels_io_healpix.py +++ b/src/toast/pixels_io_healpix.py @@ -12,7 +12,7 @@ from .io import have_hdf5_parallel from .mpi import MPI, use_mpi from .timing import Timer, function_timer -from .utils import Logger, memreport +from .utils import Logger, memreport, unit_conversion @function_timer @@ -76,8 +76,7 @@ def read_healpix_fits(pix, path, nest=True, comm_bytes=10000000): log.info(msg) funits = pix.units if funits != pix.units: - scale = 1.0 * funits - fscale = scale.to_value(pix.units) + fscale = unit_conversion(funits, pix.units) if nside_map != nside: errors += f"Wrong NSide: {path} has {nside_map}, expected {nside}\n" diff --git a/src/toast/utils.py b/src/toast/utils.py index 225c69326..aab66a869 100644 --- a/src/toast/utils.py +++ b/src/toast/utils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015-2020 by the parties listed in the AUTHORS file. +# Copyright (c) 2015-2024 by the parties listed in the AUTHORS file. # All rights reserved. Use of this source code is governed by # a BSD-style license that can be found in the LICENSE file. @@ -773,8 +773,7 @@ def unit_conversion(source, target): """ scale = 1.0 * source - scale.to(target) - return scale.to(target).value + return scale.to_value(target) class SetDict(UserDict):