-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
3,630 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
# Preface {.unnumbered} | ||
|
||
This is a Quarto book. | ||
|
||
To learn more about Quarto books visit <https://quarto.org/docs/books>. | ||
## Acknowledgement {.unnumbered} | ||
This work has been funded by the German Research Foundation (DFG) through the project NFDI4Earth (DFG project no. 460036893, <https://www.nfdi4earth.de/>) within the German National Research Data Infrastructure (NFDI, <https://www.nfdi.de/>). | ||
|
||
```{r} | ||
1 + 1 | ||
``` | ||
## License {.unnumbered} | ||
This book is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) License (<https://creativecommons.org/licenses/by-nc/4.0/>). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
# Introduction | ||
|
||
This is a book created from markdown and executable code. | ||
This chapter briefly introduces the R programming language and how to install R on different operating systems. Furthermore, we will have a look at the installation of RStudio. Finally, we will learn briefly about Fortran. | ||
|
||
See @knuth84 for additional discussion of literate programming. | ||
The book is designed to cater to individuals with a foundational understanding of programming, irrespective of their familiarity with a specific programming language. | ||
|
||
```{r} | ||
1 + 1 | ||
``` | ||
## R Programming lanaguage | ||
## Installing R | ||
## Installing Rstudio | ||
## Fortran | ||
|
||
@intro2rbook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Accelerate R Packages with Fortran | ||
|
||
This chapter will focus on wrapping the developed routines from the previous chapter in an R package. | ||
|
||
## Brief Introduction to R Packages | ||
|
||
## Developing AquaFortR Package | ||
```{r} | ||
1 + 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
^docs$ | ||
^pkgdown$ | ||
^\.github$ | ||
^data-raw$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(conv2D_f) | ||
export(conv2D_r) | ||
export(xcorr2D_f) | ||
export(xcorr2D_r) | ||
useDynLib(AquaFortR) | ||
useDynLib(AquaFortR, .registration=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
#' @name AquaFortR | ||
#' @useDynLib AquaFortR, .registration=TRUE | ||
## usethis namespace: start | ||
## usethis namespace: end | ||
NULL |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' @title 2D Convolution using Fortran. | ||
#' | ||
#' @description This function calculates the 2D Convolution of two matrices | ||
#' `a` and `b` using compiled Fortran subroutine. | ||
#' | ||
#' @param a A matrix (2D array) of values. | ||
#' @param b A matrix (2D array) of values. | ||
#' @return A matrix representing the 2D cross-correlation of the input matrices. | ||
#' @export | ||
#' @examples | ||
#' a <- matrix(c(1, 2, 3, 4), ncol = 2) | ||
#' b <- matrix(c(5, 6, 7, 8), ncol = 2) | ||
#' conv2D_f(a, b) | ||
#' @author Ahmed Homoudi | ||
#' @useDynLib AquaFortR | ||
#' @export | ||
conv2D_f <- function(a, b) { | ||
stopifnot(length(dim(a))==2 | length(dim(b))==2) | ||
result <- .Call( | ||
c_conv2d_f, | ||
as.integer(dim(a)), | ||
as.double(a), | ||
as.integer(dim(b)), | ||
as.double(b) | ||
) | ||
return(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#' @title 2D Convolution using R. | ||
#' | ||
#' @description This function calculates the 2D Convolution of two matrices | ||
#' `a` and `b` using compiled Fortran subroutine. | ||
#' | ||
#' @param a A matrix (2D array) of values. | ||
#' @param b A matrix (2D array) of values. | ||
#' @return A matrix representing the 2D cross-correlation of the input matrices. | ||
#' @export | ||
#' @examples | ||
#' a <- matrix(c(1, 2, 3, 4), ncol = 2) | ||
#' b <- matrix(c(5, 6, 7, 8), ncol = 2) | ||
#' conv2D_f(a, b) | ||
#' @author Ahmed Homoudi | ||
#' @useDynLib AquaFortR | ||
#' @export | ||
conv2D_r <- function(a, b) { | ||
stopifnot(length(dim(a))==2 | length(dim(b))==2) | ||
# the full convolution matrix | ||
conv_row <- nrow(a) + nrow(b) - 1 | ||
conv_col <- ncol(a) + ncol(b) - 1 | ||
conv <- matrix(1:c(conv_row * conv_col), byrow = FALSE, ncol = conv_col) | ||
|
||
# obtain possible shifts | ||
min_row_shift <- -(nrow(b) - 1) | ||
max_row_shift <- (nrow(a) - 1) | ||
min_col_shift <- -(ncol(b) - 1) | ||
max_col_shift <- (ncol(a) - 1) | ||
|
||
# Padded matrix | ||
rows_padded <- abs(min_row_shift) + nrow(a) + abs(max_row_shift) | ||
cols_padded <- abs(min_col_shift) + ncol(a) + abs(max_col_shift) | ||
# a | ||
padded_a <- matrix(0, nrow = rows_padded, ncol = cols_padded) | ||
padded_a[ | ||
(abs(min_row_shift) + 1):(abs(min_row_shift) + nrow(a)), | ||
(abs(min_col_shift) + 1):(abs(min_col_shift) + ncol(a)) | ||
] <- a | ||
|
||
for (icol in 1:conv_col) { | ||
for (irow in 1:conv_row) { | ||
iconv <- irow + ((icol - 1) * conv_row) | ||
cols <- (icol):(icol + ncol(b) - 1) | ||
rows <- (irow):(irow + nrow(b) - 1) | ||
# b | ||
padded_b <- array(0, dim = c(rows_padded, cols_padded)) | ||
# flip the kernel i.e. b | ||
padded_b[rows, cols] <- b[nrow(b):1, ncol(b):1] | ||
|
||
conv[irow, icol] <- sum(padded_a * padded_b) | ||
} | ||
} | ||
|
||
return(conv) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#' @title Radiosonde data | ||
#' @description radiosonde example data to calculate CAPE. | ||
#' The data measured at Stuttgart radiosonde station on 2021-06-01 12:00 mid day. | ||
#' For more information about about the | ||
#' variables meaning, please refer to this sheet | ||
#' \url{https://opendata.dwd.de/climate_environment/CDC/help/Abkuerzung_Spaltenname_CDC_20180914.xlsx} | ||
#' | ||
#' @format A data frame with 14 columns and 2962 rows | ||
#' @source German Weather Service (DWD). (2024). Radiosondes data set. | ||
#' Climate Data Center (CDC). \url{https://opendata.dwd.de/} | ||
"radiosonde" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#' @title 2D cross-correlation using Fortran. | ||
#' | ||
#' @description This function calculates the 2D cross-correlation of two matrices | ||
#' `a` and `b` using compiled Fortran subroutine. | ||
#' | ||
#' @param a A matrix (2D array) of values. | ||
#' @param b A matrix (2D array) of values. | ||
#' @return A matrix representing the 2D cross-correlation of the input matrices. | ||
#' @export | ||
#' @examples | ||
#' a <- matrix(c(1, 2, 3, 4), ncol = 2) | ||
#' b <- matrix(c(5, 6, 7, 8), ncol = 2) | ||
#' xcorr2D_f(a, b) | ||
#' @author Ahmed Homoudi | ||
#' @useDynLib AquaFortR | ||
#' @export | ||
xcorr2D_f <- function(a, b) { | ||
stopifnot(length(dim(a))==2 | length(dim(b))==2) | ||
result <- .Call( | ||
c_xcorr2d_f, | ||
as.integer(dim(a)), | ||
as.double(a), | ||
as.integer(dim(b)), | ||
as.double(b) | ||
) | ||
return(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' @title 2D cross-correlation using R. | ||
#' | ||
#' @description This function calculates the 2D cross-correlation of two matrices | ||
#' `a` and `b` using compiled Fortran subroutine. | ||
#' | ||
#' @param a A matrix (2D array) of values. | ||
#' @param b A matrix (2D array) of values. | ||
#' @return A matrix representing the 2D cross-correlation of the input matrices. | ||
#' @export | ||
#' @examples | ||
#' a <- matrix(c(1, 2, 3, 4), ncol = 2) | ||
#' b <- matrix(c(5, 6, 7, 8), ncol = 2) | ||
#' xcorr2D_f(a, b) | ||
#' @author Ahmed Homoudi | ||
#' @useDynLib AquaFortR | ||
#' @export | ||
xcorr2D_r <- function(a, b) { | ||
stopifnot(length(dim(a))==2 | length(dim(b))==2) | ||
# the full CC matrix | ||
cc_row <- nrow(a) + nrow(b) - 1 | ||
cc_col <- ncol(a) + ncol(b) - 1 | ||
cc <- matrix(1:c(cc_row * cc_col), byrow = FALSE, ncol = cc_col) | ||
|
||
# obtain possible shifts | ||
min_row_shift <- -(nrow(b) - 1) | ||
max_row_shift <- (nrow(a) - 1) | ||
min_col_shift <- -(ncol(b) - 1) | ||
max_col_shift <- (ncol(a) - 1) | ||
|
||
# Padded matrix | ||
rows_padded <- abs(min_row_shift) + nrow(a) + abs(max_row_shift) | ||
cols_padded <- abs(min_col_shift) + ncol(a) + abs(max_col_shift) | ||
# a | ||
padded_a <- matrix(0, nrow = rows_padded, ncol = cols_padded) | ||
padded_a[ | ||
(abs(min_row_shift) + 1):(abs(min_row_shift) + nrow(a)), | ||
(abs(min_col_shift) + 1):(abs(min_col_shift) + ncol(a)) | ||
] <- a | ||
|
||
for (icol in 1:cc_col) { | ||
for (irow in 1:cc_row) { | ||
icc <- irow + ((icol - 1) * cc_row) | ||
cols <- (icol):(icol + ncol(b) - 1) | ||
rows <- (irow):(irow + nrow(b) - 1) | ||
# b | ||
padded_b <- array(0, dim = c(rows_padded, cols_padded)) | ||
padded_b[rows, cols] <- b | ||
|
||
cc[irow, icol] <- sum(padded_a * padded_b) | ||
} | ||
} | ||
|
||
return(cc) | ||
} |
Oops, something went wrong.