Skip to content

Instantly share code, notes, and snippets.

View oousmane's full-sized avatar
🎯
Focusing

Ousmane Ouedraogo oousmane

🎯
Focusing
View GitHub Profile
@oousmane
oousmane / circular_mean.R
Last active May 10, 2026 00:46
This function streamline computation of of weighted circular mean. Useful for data described by direction and module like wind.
#' Round to a given multiple
#'
#' @param x Numeric scalar or vector.
#' @param to Target multiple. Default: `5`.
#' @param direction Rounding direction: `"nearest"` (default), `"up"`, or
#' `"down"`.
#'
#' @return Numeric vector rounded to the nearest multiple of `to`.
#' @export
#'
@oousmane
oousmane / season_length.R
Last active May 9, 2026 15:32
This piece of code let you compute season length using definition of onset, cessation valid for sahelian region
# set up
pak::pak("YODAdam/ClimSeasonR")
library(tidyverse)
library(ClimSeasonR)
# read and clean daily data for multiple stations
data<-readxl::read_excel("~/Downloads/rain.xls",skip = 2) %>%
janitor::clean_names()
# compute season length, for a set of stations
sudo apt install -y \
# --- tidyverse ---
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
libfontconfig1-dev \
libharfbuzz-dev libfribidi-dev \
libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev \
\
# --- devtools ---
@oousmane
oousmane / brand_logos.r
Created February 14, 2026 23:04
Function to consistently brand ggplot2 object
#' Add a logo to a ggplot panel
#'
#' Places a raster image (logo, stamp, watermark) inside a ggplot panel using
#' [ggplot2::annotation_custom()]. Placement is controlled either by a corner
#' shorthand or by explicit coordinates, and sizing uses absolute [grid::unit()]
#' values for predictable results across plot dimensions.
#'
#' @param p A [ggplot2::ggplot()] object.
#' @param logo A path or URL to an image file, a `magick-image` object, or any
#' object accepted by [magick::image_read()].
@oousmane
oousmane / get_os.R
Created October 28, 2025 07:50
Consistent way to detect os automatically by the creator of geoplumber
get_os <- function(){
sysinf <- Sys.info()
if (!is.null(sysinf)){
os <- sysinf['sysname']
if (os == 'Darwin')
os <- "osx"
} else { ## mystery machine
os <- .Platform$OS.type
if (grepl("^darwin", R.version$os))
os <- "osx"
@oousmane
oousmane / radiative_forcing.r
Created October 22, 2025 22:35
Calculates the radiative forcing in W m-2 based on changes in CO2 concentration #' using the formula from Myrhe et al. (1998).
#' Calculate Radiative Forcing from CO2 Concentration
#'
#' Calculates the radiative forcing in W m-2 based on changes in CO2 concentration
#' using the formula from Myrhe et al. (1998).
#'
#' The radiative forcing is calculated using the equation:
#' \deqn{\Delta F = 5.35 \times \ln(C/C_0)}{ΔF = 5.35 * ln(C/C0)}
#'
#' @param C numeric vector. Current CO2 concentration in ppm.
#' @param C0 numeric. Reference CO2 concentration in ppm. Default is 280 ppm
@oousmane
oousmane / ftp_dir_ls.r
Last active February 14, 2026 23:28
List the files in a FTP (remote) directory/folder
#' List files on an FTP server
#'
#' Connects to a remote FTP directory and returns the list of file names,
#' optionally filtered by a regular expression pattern. This function is
#' the discovery companion to [ftp_download()]: use it to identify which
#' files exist before deciding what to download.
#'
#' @param url A full FTP or FTPS URL pointing to a directory, e.g.
#' `"ftp://data.example.org/climate/daily/"`. Must start with `ftp://`
@oousmane
oousmane / check_functions.R
Last active March 25, 2024 14:28
utils functions for chess
#' Title
#'
#' @param x
#'
#' @return
#' @export
#'
#' @examples
is_integer <- function(x){
@oousmane
oousmane / get_sunrisesunset.r
Created November 5, 2023 19:12
Get sunrise and sunset time for any location and date from sunsetsunrise.io API
#' Get sunrise and sunset time for any location and date from sunsetsunrise.io API
#'
#' @param lon longitude in decimal degree of the location
#' @param lat latitude in decimal degree of the location
#' @param date a date string in 'yyy-mm-dd' format.
#'
#' @return a tibble with sunset/sunrise time, day length, location timezone and date
#' @export
#'
#' @examples
Default atmospheric CO2 concentration from 1902 to 2099 (updated 01/08/2022)
Year CO2 (ppm by volume)
============================
1902 297.4
1905 298.2
1912 300.7
1915 301.3
1924 304.5
1926 305.0
1929 305.2