Skip to content

Commit f5e24c4

Browse files
committed
add BeFa PP
1 parent 481ee64 commit f5e24c4

11 files changed

+218
-3
lines changed

DESCRIPTION

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Description: Work with data from NASA's ocean colour data, primarily the 'Level-
1111
License: GPL-3
1212
LazyLoad: yes
1313
Depends: dplyr
14-
Imports:
14+
Imports:
1515
geosphere,
1616
progress,
1717
sp,
1818
raster,
1919
rlang,
2020
rhdf5,
21-
tibble
21+
tibble,
22+
Rcpp
2223
Suggests:
2324
testthat,
2425
BiocInstaller,
@@ -28,3 +29,5 @@ NeedsCompilation: no
2829
RoxygenNote: 6.0.1
2930
URL: https://github.com/sosoc/croc
3031
BugReports: https://github.com/sosoc/croc/issues
32+
LinkingTo:
33+
Rcpp

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export(crop_init)
88
export(initbin)
99
export(lonlat2bin)
1010
export(lonlatFromCell)
11+
export(prod_BeFa)
1112
export(read_L3_file)
1213
export(read_binlist)
1314
export(read_compound)
1415
export(read_smi_image)
16+
importFrom(Rcpp,sourceCpp)
1517
importFrom(dplyr,"%>%")
1618
importFrom(dplyr,filter)
1719
importFrom(geosphere,gcIntermediate)
@@ -39,3 +41,4 @@ importFrom(tibble,tibble)
3941
importFrom(utils,download.file)
4042
importFrom(utils,tail)
4143
importMethodsFrom(raster,extent)
44+
useDynLib(croc, .registration = TRUE)

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# croc 0.0.9
22

3+
* Add Behrenfeld-Falkowski production calculation.
4+
35
* updated web links for ocean colour site to https
46

57
* added a c (renamed package) to avoid BioConductor/CRAN clash

R/RcppExports.R

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#' Primary production
5+
#'
6+
#' @export
7+
prod_BeFa <- function(chla, irrad, stemp, daylength) {
8+
.Call(`_croc_prod_BeFa`, chla, irrad, stemp, daylength)
9+
}
10+

R/croc-package.R

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#' @keywords internal
2+
"_PACKAGE"
3+
4+
5+
#' @useDynLib croc, .registration = TRUE
6+
#' @importFrom Rcpp sourceCpp
7+
NULL

man/croc-package.Rd

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prod_BeFa.Rd

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/roc-package.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.o
2+
*.so
3+
*.dll

src/RcppExports.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
2+
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#include <Rcpp.h>
5+
6+
using namespace Rcpp;
7+
8+
// prod_BeFa
9+
NumericVector prod_BeFa(NumericVector chla, NumericVector irrad, NumericVector stemp, NumericVector daylength);
10+
RcppExport SEXP _croc_prod_BeFa(SEXP chlaSEXP, SEXP irradSEXP, SEXP stempSEXP, SEXP daylengthSEXP) {
11+
BEGIN_RCPP
12+
Rcpp::RObject rcpp_result_gen;
13+
Rcpp::RNGScope rcpp_rngScope_gen;
14+
Rcpp::traits::input_parameter< NumericVector >::type chla(chlaSEXP);
15+
Rcpp::traits::input_parameter< NumericVector >::type irrad(irradSEXP);
16+
Rcpp::traits::input_parameter< NumericVector >::type stemp(stempSEXP);
17+
Rcpp::traits::input_parameter< NumericVector >::type daylength(daylengthSEXP);
18+
rcpp_result_gen = Rcpp::wrap(prod_BeFa(chla, irrad, stemp, daylength));
19+
return rcpp_result_gen;
20+
END_RCPP
21+
}
22+
23+
static const R_CallMethodDef CallEntries[] = {
24+
{"_croc_prod_BeFa", (DL_FUNC) &_croc_prod_BeFa, 4},
25+
{NULL, NULL, 0}
26+
};
27+
28+
RcppExport void R_init_croc(DllInfo *dll) {
29+
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
30+
R_useDynamicSymbols(dll, FALSE);
31+
}

src/productivity.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#include <Rcpp.h>
2+
#include <math.h>
3+
4+
using namespace Rcpp;
5+
6+
7+
// copied 2018-04-26 http://www.science.oregonstate.edu/ocean.productivity/vgpm.code.php
8+
double opp_befa( double chl,
9+
double irr,
10+
double sst,
11+
double dayL ) {
12+
/*
13+
!C--------------------------------------------------------------------------*\
14+
15+
!Description: opp_befa - computes daily primary productivity using
16+
the Behrenfeld-Falkowski (BeFa) algorithm. The BeFa
17+
algorithm estimates productivity using surface chl
18+
(mg m-3), surface irradiance (Einsteins m-2 d-1),
19+
sea surface temperature (C), and day length (hours).
20+
Pb_opt is modelled as a polynomial function of SST.
21+
22+
!Input Parameters:
23+
chl Chlorophyll_a surface concentration in milligrams
24+
chlorophyl per cubic meter
25+
irr Photosynthetically available radiation in Einsteins per
26+
day per square meter
27+
sst Sea surface temperature in degrees Centigrade
28+
dayL Length day in decimal hours.
29+
30+
!Output Parameters:
31+
<return> Primary productivity in milligrams Carbon per square meter
32+
per day
33+
34+
!Revision History:
35+
36+
First programmed up by Monica Chen at Rutgers
37+
(1996)
38+
39+
Revised by K. Turpie at NASA
40+
(August 1997)
41+
42+
Maintained by Don Shea at NASA
43+
44+
Now maintained by Robert O'Malley at Oregon State University
45+
(April, 2005 - present)
46+
47+
!References and Credits
48+
49+
Behrenfeld,M.J; Falkowski,P.G.; 1997. Photosynthetic Rates Derived
50+
from Satellite-Based Chlorophyll Concentration. Limnology and
51+
Oceanography, Volume 42, Number 1
52+
53+
!END------------------------------------------------------------------------*\
54+
*/
55+
double chl_tot,
56+
z_eu,
57+
pb_opt,
58+
irrFunc,
59+
npp;
60+
61+
62+
/* Calculate euphotic depth (z_eu) with Morel's Case I model. */
63+
/* Calculate chl_tot from Satellite Surface Chlorophyll Data. */
64+
65+
if (chl < 1.0L)
66+
chl_tot = 38.0L * pow( chl, 0.425L );
67+
else
68+
chl_tot = 40.2L * pow( chl, 0.507L );
69+
70+
71+
z_eu = 200.0L * pow( chl_tot, (-.293L) );
72+
73+
if (z_eu <= 102.0L)
74+
z_eu = 568.2L * pow( chl_tot, (-.746L) );
75+
76+
77+
/* Calculate the Pb_opt from satellite sea surface temperature (sst). */
78+
79+
if (sst < -10.0L)
80+
pb_opt = 0.00L;
81+
else if (sst < -1.0L)
82+
pb_opt = 1.13L;
83+
else if (sst > 28.5L)
84+
pb_opt = 4.00L;
85+
else {
86+
pb_opt = 1.2956 + 2.749e-1*sst + 6.17e-2*pow(sst,2) - 2.05e-2*pow(sst, 3)
87+
+ 2.462e-3*pow(sst,4) - 1.348e-4*pow(sst,5) + 3.4132e-6*pow(sst,6)
88+
- 3.27e-8*pow(sst,7);
89+
}
90+
91+
92+
/* calculate the irradiance function */
93+
94+
irrFunc = 0.66125L * irr / ( irr + 4.1L );
95+
96+
97+
/* Return the primary production calculation. */
98+
99+
npp = pb_opt * chl * dayL * irrFunc * z_eu;
100+
101+
return npp;
102+
}
103+
104+
//' Primary production
105+
//'
106+
//' @export
107+
// [[Rcpp::export]]
108+
NumericVector prod_BeFa(NumericVector chla, NumericVector irrad, NumericVector stemp, NumericVector daylength) {
109+
NumericVector out(chla.length());
110+
for (int i = 0; i < out.length(); i++) {
111+
out[i] = opp_befa(chla[i], irrad[i], stemp[i], daylength[i]);
112+
}
113+
return out;
114+
}

0 commit comments

Comments
 (0)