pytroll/pyspectral

Near infrared reflectance calculation does not preserve input dtype

Closed this issue · 0 comments

Code Sample, a minimal, complete, and verifiable piece of code

import dask.config
import dask.array as da
import numpy as np
from satpy.tests.utils import CustomScheduler

from pyspectral.near_infrared_reflectance import Calculator


with dask.config.set(scheduler=CustomScheduler(max_computes=0)):
    calc = Calculator("Meteosat-10", "seviri", 3.9)
    sunz = da.array([80.], dtype=np.float32)
    tb3 = da.array([290.], dtype=np.float32)
    tb4 = da.array([282.], dtype=np.float32)
    res = calc.reflectance_from_tbs(sunz, tb3, tb4)
    assert res.dtype == np.float32

Problem description

If the input data passed to Calculator are as float32, the return value is upcast to float64 by the calculator.

Expected Output

Get the NIR reflectance with the same dtype as the inputs.

Actual Result, Traceback if applicable

Result has dtype=np.float64.

Versions of Python, package at hand and relevant dependencies

Python 3.11, current Pyspectral main, current Satpy main.