Skip to content

Commit ebbf2f1

Browse files
committed
Add an example to float coercing
1 parent 3e2de6c commit ebbf2f1

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

doc/source/dev_guide/custom_reader.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ better idea.
508508

509509
.. note::
510510
Be careful about the data types of the datasets your reader is returning.
511-
It is easy to let the data being coerced into double precision floats. At the
511+
It is easy to let the data be coerced into double precision floats (`np.float64`). At the
512512
moment, satellite instruments are rarely measuring in a resolution greater
513513
than what can be encoded in 16 bits. As such, to preserve processing power,
514514
please consider carefully what data type you should scale or calibrate your
@@ -518,6 +518,13 @@ better idea.
518518
significant bits (mantissa) and can thus represent 16 bit integers exactly,
519519
as well as keeping the memory footprint half of a double precision float.
520520

521+
One commonly used method in readers is :meth:`xarray.DataArray.where` (to
522+
mask invalid data) which can be coercing the data to `np.float64`. To ensure
523+
for example that integer data is coerced to `np.float32` when
524+
:meth:`xarray.DataArray.where` is used, you can do::
525+
526+
my_float_dataarray = my_int_dataarray.where(some_condition, np.float32(np.nan))
527+
521528
One way of implementing a file handler is shown below:
522529

523530
.. code:: python

0 commit comments

Comments
 (0)