Quantcast
Viewing latest article 7
Browse Latest Browse All 10

Rain – Evapotranspiration = mm Water

“Eeee-VAP-oooo-TRANS-PURR-ation,” I savor the word as I release it into our conversation. I’m still at the party with Marsha and Bob. We’re trying to determine why anyone (such as me) would want to use R on their Raspberry Pi.

Image may be NSFW.
Clik here to view.
Photo by Tima Miroshnichenko

“Big word,” says Bob. “What’s it mean?”

“Water evaporation from the earth and transpiration from plants,” I respond. “It’s a sum of the water escaping from my irrigation system. Look it up on Wikipedia.”

Image may be NSFW.
Clik here to view.

Marsha interrupts grumpy Bob; “So – That means, um…desired amount of water – rainfall + evapotranspiration equals the amount of water your irrigation system needs to supply.”

“Precisely,” I agree. “Until I found out about evapotranspiration, I was unsure how to account for temperature. I knew hot days would require more water because of increased evaporation; but was stumped how to translate temperature into increased inches of necessary water.”

“Never heard of it,” says Bob.

“Me neither,” I agree. “Evapotranspiration is handy, but doesn’t show up in all weather forecasts. Open-Meteo makes it available.”

“Say you’ve got seven days worth of this miracle number,” says Bob. “What does the R code look like?”

“I’m so glad you asked,” I reply. I’ve been using my tablet for a snack plate, so I wipe off the cheese dip and open up the github repository showing my irrigation code.

“Remember, I’m using a matrix named “waterByZone” to store a year’s worth of rainfall. I use the day of the year to point to today’s values.”

> yearDay <- as.POSIXlt(Sys.Date())$yday + 1
> yearDay
86

“I use a call to open-meteo to retrieve the values for rainfall and evapotranspiration. That’s all put together by a few calculations with the waterByZone information.”

# get the sum of rainfall for yesterday, today, and tomorrow
recentRainfall <- sum(waterByZone["rainfall", (yearDay - 1):(yearDay + 1)])
# get the sum of evapotranspiration for three days
recentEVOTRP <- sum(waterByZone["evapotranspiration", (yearDay - 1):(yearDay + 1)])
# neededInFront is amount of rain needed today
neededRain <- waterByZone["neededInFront", yearDay] - recentRainfall + recentEVOTRP
# needed rain is never less than zero, so check that limit
waterByZone["wateredInFront", yearDay] <- ifelse(neededRain <= 0, 0, neededRain)

If I had nothing else to do, I would rewrite this as:

  • C or C++
  • Python
  • An R pipeline using |> instead of %>% (I’m focused on Base R wherever possible)

…but I’ll leave that to you, intrepid readers.

What do you think?

MNR

The post Rain – Evapotranspiration = mm Water appeared first on Mark Niemann-Ross.


Viewing latest article 7
Browse Latest Browse All 10

Trending Articles