diff --git a/tests/data/eopf/S01SIWSLC_target.json b/tests/data/eopf/S01SIWSLC_target.json index 7696522..23b6a8b 100644 --- a/tests/data/eopf/S01SIWSLC_target.json +++ b/tests/data/eopf/S01SIWSLC_target.json @@ -3,7 +3,7 @@ "conditions": {}, "conditions/antenna_pattern": { "azimuth_time": [["azimuth_time"], "datetime64[ns]"], - "count": [["count"], "int64"], + "count": [["count"], "int32"], "elevation_angle": [["polarization", "azimuth_time", "count"], "float32"], "incidence_angle": [["polarization", "azimuth_time", "count"], "float32"], "polarization": [["polarization"], " None: assert res.data_dc_rms_error_above_threshold.dtype == bool -@pytest.mark.xfail(IS_32_BIT, reason="int32 instead of int64 on 32bit architectures.") def test_open_coordinate_conversion() -> None: # dims and dtypes from the CPM 3.0 S01SIWGRD mapping expected = { "azimuth_time": [["azimuth_time"], "datetime64[ns]"], - "degree": [["degree"], "int64"], + "degree": [["degree"], "int32"], "gr0": [["azimuth_time"], "float64"], "grsr_coefficients": [["azimuth_time", "degree"], "float64"], "slant_range_time": [["azimuth_time"], "float64"], diff --git a/tests/test_30_eopf_product.py b/tests/test_30_eopf_product.py index 3408a0f..a2d1dab 100644 --- a/tests/test_30_eopf_product.py +++ b/tests/test_30_eopf_product.py @@ -1,7 +1,6 @@ import json import pathlib import shutil -import sys import warnings from typing import Any @@ -11,8 +10,6 @@ from xarray_sentinel import eopf_product, sentinel1 -IS_32_BIT = sys.maxsize == 0x7FFFFFFF - DATA_FOLDER = pathlib.Path(__file__).parent / "data" SLC_IW = ( @@ -315,7 +312,6 @@ def test_open_datatree_groups( assert slc_iw_node_structure.keys() == EXPECTED_SLC_IW_STRUCTURE.keys() -@pytest.mark.xfail(IS_32_BIT, reason="int32 instead of int64 on 32bit architectures.") @pytest.mark.parametrize("group", sorted(EXPECTED_SLC_IW_STRUCTURE)) def test_open_datatree_group_structure( slc_iw_node_structure: dict[str, dict[str, list[Any]]], group: str diff --git a/xarray_sentinel/eopf_sentinel1.py b/xarray_sentinel/eopf_sentinel1.py index 773d021..24001ac 100644 --- a/xarray_sentinel/eopf_sentinel1.py +++ b/xarray_sentinel/eopf_sentinel1.py @@ -60,7 +60,7 @@ def open_antenna_pattern(annotation: dict[str, Any]) -> xr.Dataset: "roll": pattern["roll"], "terrain_height": pattern["terrainHeight"], } - coords = {"count": np.arange(slant_range_time.size)} + coords = {"count": np.arange(slant_range_time.size, dtype=np.int32)} pattern_dataset = xr.Dataset(data_vars=data_vars, coords=coords) azimuth_time = [np.datetime64(pattern["azimuthTime"], "ns")] pattern_datasets.append(pattern_dataset.expand_dims(azimuth_time=azimuth_time)) @@ -132,7 +132,7 @@ def open_doppler_centroid(annotation: dict[str, Any]) -> xr.Dataset: coords = { "azimuth_time": [np.datetime64(e["azimuthTime"], "ns") for e in estimates], # the polynomial powers, not reversed as in EOPF, see quirk 2 in docs/DATATREE.md - "degree": np.arange(data_dc_polynomial[0].size), + "degree": np.arange(data_dc_polynomial[0].size, dtype=np.int32), } return xr.Dataset(data_vars=data_vars, coords=coords) @@ -155,8 +155,8 @@ def open_gcp(annotation: dict[str, Any]) -> xr.Dataset: # the annotated times of the first column, see quirk 1 in docs/DATATREE.md "azimuth_time": grids["azimuth_time_gcp"][:, 0], range_name: range_values, - "line": ("azimuth_time", lines), - "pixel": (range_name, pixels), + "line": ("azimuth_time", np.array(lines, dtype=np.int32)), + "pixel": (range_name, np.array(pixels, dtype=np.int32)), } dims = ("azimuth_time", range_name) data_vars = {name: (dims, grid) for name, grid in grids.items()} @@ -190,7 +190,7 @@ def open_coordinate_conversion(annotation: dict[str, Any]) -> xr.Dataset | None: } coords = { "azimuth_time": [np.datetime64(c["azimuthTime"], "ns") for c in conversions], - "degree": np.arange(srgr_coefficients[0].size), + "degree": np.arange(srgr_coefficients[0].size, dtype=np.int32), } return xr.Dataset(data_vars=data_vars, coords=coords) @@ -235,7 +235,7 @@ def open_range_vectors( The GRD vectors change their pixels at the sub-swath boundaries, which move in azimuth, so the shorter vectors are padded with NaN and pixel -1. """ - pixels = [np.fromstring(v["pixel"]["$"], dtype=int, sep=" ") for v in vectors] + pixels = [np.fromstring(v["pixel"]["$"], dtype=np.int32, sep=" ") for v in vectors] pixel = stack_vectors(pixels, -1) range_name, range_values = range_coordinate(pixel[0], annotation) dims = ("azimuth_time", range_name) @@ -249,7 +249,10 @@ def open_range_vectors( raise ValueError("Unable to organise vectors in a regular line-pixel grid") coords[range_name] = range_values pixel_coordinate = (range_name, pixel[0]) - coords["line"] = ("azimuth_time", [v["line"] for v in vectors]) + coords["line"] = ( + "azimuth_time", + np.array([v["line"] for v in vectors], dtype=np.int32), + ) coords["pixel"] = pixel_coordinate data_vars: dict[str, Any] = {} for name, tag in variables.items(): @@ -302,16 +305,16 @@ def open_noise_azimuth( vectors = vector_list["noiseAzimuthVector"] vector_datasets = [] for vector in vectors: - line = np.fromstring(vector["line"]["$"], dtype=int, sep=" ") + line = np.fromstring(vector["line"]["$"], dtype=np.int32, sep=" ") noise_azimuth_lut = np.fromstring( vector["noiseAzimuthLut"]["$"], dtype=np.float32, sep=" " ) data_vars = { "noise_azimuth_lut": ("line", noise_azimuth_lut), - "first_azimuth_line": vector["firstAzimuthLine"], - "last_azimuth_line": vector["lastAzimuthLine"], - "first_range_sample": vector["firstRangeSample"], - "last_range_sample": vector["lastRangeSample"], + "first_azimuth_line": np.int32(vector["firstAzimuthLine"]), + "last_azimuth_line": np.int32(vector["lastAzimuthLine"]), + "first_range_sample": np.int32(vector["firstRangeSample"]), + "last_range_sample": np.int32(vector["lastRangeSample"]), } vector_dataset = xr.Dataset(data_vars=data_vars, coords={"line": line}) vector_datasets.append(vector_dataset.expand_dims(swath=[vector["swath"]])) diff --git a/xarray_sentinel/sentinel1.py b/xarray_sentinel/sentinel1.py index 9815656..977ce78 100644 --- a/xarray_sentinel/sentinel1.py +++ b/xarray_sentinel/sentinel1.py @@ -92,7 +92,7 @@ def open_calibration_dataset( for vector in calibration_vectors: azimuth_time_list.append(vector["azimuthTime"]) line_list.append(vector["line"]) - pixel = np.fromstring(vector["pixel"]["$"], dtype=int, sep=" ") + pixel = np.fromstring(vector["pixel"]["$"], dtype=np.int32, sep=" ") pixel_list.append(pixel) sigmaNought = np.fromstring( vector["sigmaNought"]["$"], dtype=np.float32, sep=" " @@ -117,7 +117,7 @@ def open_calibration_dataset( "gamma": (("line", "pixel"), gamma_list), "dn": (("line", "pixel"), dn_list), } - coords = {"line": line_list, "pixel": pixel_list[0]} + coords = {"line": np.array(line_list, dtype=np.int32), "pixel": pixel_list[0]} return xr.Dataset(data_vars=data_vars, coords=coords, attrs=attrs) @@ -248,7 +248,7 @@ def open_noise_range_dataset( for vector in noise_vectors: azimuth_time_list.append(vector["azimuthTime"]) line_list.append(vector["line"]) - pixel = np.fromstring(vector["pixel"]["$"], dtype=int, sep=" ") + pixel = np.fromstring(vector["pixel"]["$"], dtype=np.int32, sep=" ") pixel_list.append(pixel) noiseRangeLut = np.fromstring( vector["noiseRangeLut"]["$"], dtype=np.float32, sep=" " @@ -264,7 +264,7 @@ def open_noise_range_dataset( "azimuth_time": ("line", [np.datetime64(dt, "ns") for dt in azimuth_time_list]), "noiseRangeLut": (("line", "pixel"), noiseRangeLut_list), } - coords = {"line": line_list, "pixel": pixel_list[0]} + coords = {"line": np.array(line_list, dtype=np.int32), "pixel": pixel_list[0]} return xr.Dataset(data_vars=data_vars, coords=coords, attrs=attrs) @@ -278,16 +278,16 @@ def open_noise_azimuth_dataset( vector_datasets = [] for vector in noise_vectors: - line = np.fromstring(vector["line"]["$"], dtype=int, sep=" ") + line = np.fromstring(vector["line"]["$"], dtype=np.int32, sep=" ") noise_azimuth_lut = np.fromstring( vector["noiseAzimuthLut"]["$"], dtype=np.float32, sep=" " ) data_vars = { "noiseAzimuthLut": ("line", noise_azimuth_lut), - "firstAzimuthLine": vector["firstAzimuthLine"], - "lastAzimuthLine": vector["lastAzimuthLine"], - "firstRangeSample": vector["firstRangeSample"], - "lastRangeSample": vector["lastRangeSample"], + "firstAzimuthLine": np.int32(vector["firstAzimuthLine"]), + "lastAzimuthLine": np.int32(vector["lastAzimuthLine"]), + "firstRangeSample": np.int32(vector["firstRangeSample"]), + "lastRangeSample": np.int32(vector["lastRangeSample"]), } vector_ds = xr.Dataset(data_vars=data_vars, coords={"line": line}) vector_datasets.append(vector_ds.expand_dims(swath=[vector["swath"]])) @@ -662,8 +662,8 @@ def open_pol_dataset( ] = azimuth_time_burst coords = { - "pixel": np.arange(0, number_of_samples, dtype=int), - "line": np.arange(0, number_of_lines, dtype=int), + "pixel": np.arange(0, number_of_samples, dtype=np.int32), + "line": np.arange(0, number_of_lines, dtype=np.int32), # We don't need top set the "units" as Xarray now detects the best resolution. # See: https://github.com/pydata/xarray/issues/4183#issuecomment-685200043 # and https://github.com/pydata/xarray/pull/4684