pyresample
pyresample copied to clipboard
YAML area configuration does not allow to specify the dtype and dtype is ignored in equality comparisons
Today I learned that an areadefinition has a dtype attribute. This seems to be not very well documented and not very well supported, but it's relevant. It is used at least in get_lonlats()
, which is used in resampling, so changing the dtype can have considerable memory implications and make the difference between having enough RAM or not.
Code Sample, a minimal, complete, and verifiable piece of code
import pyresample
ar = pyresample.AreaDefinition(
"area_id", "descr", "proj_id", 4326, 100, 100,
[-100, -100, 100, 100], dtype="float32")
s = ar.dump()
print(s)
ar2 = pyresample.area_config.load_area_from_string(s)
print("equals?", ar == ar2)
print("dtypes", ar.dtype, ar2.dtype)
s2 = """area_id:
description: descr
projection:
EPSG: 4326
shape:
height: 100
width: 100
area_extent:
lower_left_xy: [-100, -100]
upper_right_xy: [100, 100]
dtype: float32
"""
ar3 = pyresample.area_config.load_area_from_string(s2)
print(ar3.dtype)
Problem description
Executing the code reveals several problems:
-
ar.dump()
does not output the dtype -
ar
andar2
are considered equal despite having different dtypes -
ar3
, loaded from a string that does encode the dtype, getsfloat64
despite the YAML definition statingfloat32
.
It does not appear to be possible to specify the dtype in the YAML configuration (nor in pyresample.create_area_def()
).
Expected Output
area_id:
description: descr
projection:
EPSG: 4326
shape:
height: 100
width: 100
area_extent:
lower_left_xy: [-100, -100]
upper_right_xy: [100, 100]
dtype: float32
equals? True
dtypes float32 <class 'numpy.float32'>
<class 'numpy.float32'>
Actual Result, Traceback if applicable
area_id:
description: descr
projection:
EPSG: 4326
shape:
height: 100
width: 100
area_extent:
lower_left_xy: [-100, -100]
upper_right_xy: [100, 100]
equals? True
dtypes float32 <class 'numpy.float64'>
/data/gholl/checkouts/pyresample/pyresample/area_config.py:91: UserWarning: Unused/unexpected area definition parameter(s) for area_id: params={'dtype': 'float32'}
area_list = parse_area_file(area_file_name, *regions)
<class 'numpy.float64'>
Versions of Python, package at hand and relevant dependencies
pyresample main (v1.28.2-2-g711f354)