r-spatial / stars

Spatiotemporal Arrays, Raster and Vector Data Cubes
https://r-spatial.github.io/stars/
Apache License 2.0
563 stars 94 forks source link

Stars math #718

Closed dominicroye closed 1 month ago

dominicroye commented 1 month ago

I wanted to subtract a single layer with the same extent and resolution from another, but I got the following error dims [product 131072] do not match the length of object when I chose the direction from single_layer - multiple_layer. For +/- it does matter if I say 5-10 or 10-5. So I would expect both directions should work, or? Data example can be downloaded here.

library(stars)

rs <- read_mdim("hur_day_EC-Earth3_historical_r1i1p1f1_gr_19500101-19501231.nc", proxy = T)

rs2 <- adrop(rs[,,,1,1]) |> st_as_stars()
rs <- adrop(rs[,,,1,1:10]) |> st_as_stars()

dif <- rs-rs2 # ok

but

> rs2-rs
Error en NextMethod(): 
  dims [product 131072] do not match the length of object [1310720]
edzer commented 1 month ago

Yes, only the second gets recycled to the dims of the first, not the other way around. I'll look into making the recycling more generic.