pytroll / pyorbital

Orbital and astronomy computations in python

Home Page:http://pyorbital.readthedocs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get_observer_look turns xarray.DataArray objects into dask.array objects

gerritholl opened this issue · comments

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

import datetime
import pyorbital.orbital
import xarray

lat = lon = xarray.DataArray([[1,2],[3,4]], dims=("x", "y"))
satlat = satlon = xarray.DataArray([[0]*2]*2, dims=("x", "y"))
times = xarray.DataArray([[datetime.datetime.now()]*2]*2, dims=("x", "y"))
satelevs = xarray.DataArray([[1000]*2]*2, dims=("x", "y"))
groundelevs = xarray.DataArray([[0]*2]*2, dims=("x", "y"))
times = xarray.DataArray([[datetime.datetime.now()]*2]*2, dims=("x", "y"))
(az, elev) = pyorbital.orbital.get_observer_look(satlon, satlat, satelevs,
                    times, lat, lon, groundelevs)
print("azimuth", az)
print("elev", elev)

Problem description

The az azimuth output is of type dask.array. The coordinates and any other metadata stored alongside the arrays in the DataArray are lost. I am not familiar with dask.array.

This is a consequence of the if hasattr(az, 'chunks') block. The else:-block should work fine for xarray.DataArray objects, which also happen to have this attribute.

Expected Output

I would expect both az and elev to be of xarray.DataArray type, such that no information is needlessly lost.

Actual Result, Traceback if applicable

azimuth dask.array<rad2deg, shape=(2, 2), dtype=float64, chunksize=(2, 2)>
elev <xarray.DataArray (x: 2, y: 2)>
array([[79.686688, 69.883718],
       [60.955333, 53.06458 ]])
Dimensions without coordinates: x, y

Versions of Python, package at hand and relevant dependencies

Python 3.7.0, pyorbital 1.3.1, from conda-forge.