Get started

library(calculeflux)

calcule flux


date_debut_calcul<-"2007-01-01"%>%as.Date()
date_fin_calcul<-"2007-12-31"%>%as.Date()
  
datafile <- system.file("nitrates.csv", package = "calculeflux")
nitrates <- read.csv2(datafile, encoding = "UTF-8")
nitrates$DatePrel<-nitrates$DatePrel%>%as.Date()

datafile <- system.file("debit.csv", package = "calculeflux")
debit <- read.csv2(datafile, encoding = "UTF-8")
debit$date_obs_elab<-debit$date_obs_elab%>%as.Date()

calcule_flux(
  nitrates,
  col_dates_anal = "DatePrel",
  col_analyses = "RsAna",
  debit,
  methode = "M6",
  date_debut_calcul=date_debut_calcul,
  date_fin_calcul=date_fin_calcul
)
#> [1] 86453022

methodes<-c("M1", "M2", "M3", "M4", "M5", "M6", "M9")

tmp<-lapply(methodes,
function(x){calcule_flux(
  nitrates,
  col_dates_anal = "DatePrel",
  col_analyses = "RsAna",
  debit,
  methode = x,
  date_debut_calcul=date_debut_calcul,
  date_fin_calcul=date_fin_calcul
)}
)


tmp<-unlist(tmp)
tmp<-data.frame(methode=methodes, flux=tmp/1000)

library(ggplot2)

ggplot2::ggplot(tmp, ggplot2::aes(methode, flux)) + 
  ggplot2::geom_bar(stat="identity") + ggplot2::ylab("Flux en kg NO3/an")


# calcul du flux annuel méthode M6

calcul_flux_annuel<-function(annee)
{
  calcule_flux(
  nitrates,
  col_dates_anal = "DatePrel",
  col_analyses = "RsAna",
  debit,
  methode = "M6",
  date_debut_calcul=paste0(annee,"-10-01")%>%as.Date(),
  date_fin_calcul=paste0((annee+1),"-10-01")%>%as.Date()
)
 
}

annees<-seq(2002,2021)
tmp<-lapply(annees, calcul_flux_annuel)

tmp<-unlist(tmp)
flux_vilaine_bdhydro<-data.frame(annee_hydro=paste0(annees, " - ", annees+1), flux=tmp/1000)


ggplot2::ggplot(flux_vilaine_bdhydro, ggplot2::aes(annee_hydro, flux)) +
  ggplot2::geom_bar(stat="identity") +
  ggplot2::ylab("flux (t NO3/an)") + 
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust=0.5)) +
  ggplot2::ggtitle("Flux de nitrates calcul\u00e9s sur la Vilaine \u00e0 Rieux",
          subtitle="NO3 station 04216000 / station hydrom\u00e9trique J930061101")



# calcul du flux bimensuels pour chaque année


library(zoo)
#> 
#> Attachement du package : 'zoo'
#> Les objets suivants sont masqués depuis 'package:base':
#> 
#>     as.Date, as.Date.numeric
DateSeq_fin_mois <- function(st, en, freq) {
  st <- as.Date(as.yearmon(st)) 
  en <- as.Date(as.yearmon(en)) 
  as.Date(as.yearmon(seq(st, en, by = paste(as.character(12/freq), "months"))), frac = 1)

}

DateSeq_debut_mois <- function(st, en, freq) {
  st <- as.Date(as.yearmon(st))
  en <- as.Date(as.yearmon(en)) 
  as.Date(as.yearmon(seq(st, en, by = paste(as.character(12/freq), "months"))), frac = 0)

}

# # dates de chaque fin de mois
# DateSeq_fin_mois(as.Date("2002-01-01"),as.Date("2022-09-30"),12)

# dates de debut de mois, un mois sur 2
dates_debut_mois<-DateSeq_debut_mois(as.Date("2002-10-01"),as.Date("2022-08-01"),6)

# dates des fins de mois 1 mois sur 2
dates_fin_mois<-DateSeq_fin_mois(as.Date("2002-11-30"),as.Date("2022-09-30"),6)

# mois periode 
mois_periode<-paste0(format(dates_debut_mois, "%b"),"-",format(dates_fin_mois, "%b"))
mois_periode<-mois_periode%>%factor(levels=unique(mois_periode))

# annnee hydro
an_hydro_periode<-ifelse(format(dates_debut_mois, "%m")%>%as.numeric()>=10,
                         format(dates_debut_mois, "%Y")%>%as.numeric(),
                         format(dates_debut_mois, "%Y")%>%as.numeric()-1)

an_hydro_periode<-paste0(an_hydro_periode, " - ", an_hydro_periode+1)

periodes<-data.frame(debut=dates_debut_mois,
                     fin=dates_fin_mois,
                     mois_periode=mois_periode,
                     an_hydro_periode=an_hydro_periode)


tmp<-lapply(seq(1,nrow(periodes)),
function(x){
  calcule_flux(
  nitrates,
  col_dates_anal = "DatePrel",
  col_analyses = "RsAna",
  debit,
  methode = "M6",
  date_debut_calcul=periodes$debut[x],
  date_fin_calcul=periodes$fin[x]
)
  }
)


flux<-unlist(tmp)
resultats<-cbind(periodes, flux)



ggplot2::ggplot(resultats, ggplot2::aes(mois_periode, flux)) +
  ggplot2::geom_bar(stat="identity") +
  ggplot2::ylab("Flux en kg NO3/an") + 
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust=0.5)) +
  ggplot2::facet_wrap(an_hydro_periode~.)+
  ggplot2::ggtitle("Flux de nitrates calcul\u00e9s sur la Vilaine \u00e0 Rieux",
          subtitle="NO3 station 04216000 / station hydrom\u00e9trique J930061101")
#> Warning: Removed 1 rows containing missing values (`position_stack()`).

calcule_hydraulicite


date_debut_calcul<-"2022-09-15"%>%as.Date()
date_fin_calcul<-"2022-09-30"%>%as.Date()

datafile <- system.file("debit.csv", package = "calculeflux")
debit <- read.csv2(datafile, encoding = "UTF-8")
debit$date_obs_elab<-debit$date_obs_elab%>%as.Date()


calcule_hydraulicite(debit,
                     col_dates_debit="date_obs_elab",
                     col_debits="resultat_obs_elab",
                     date_debut_calcul,
                     date_fin_calcul)
#> [1] 0.7300643

# example 2

datafile <- system.file("debit.csv", package = "calculeflux")
debit <- read.csv2(datafile, encoding = "UTF-8")
debit$date_obs_elab<-debit$date_obs_elab%>%as.Date()

date_debut_calcul=paste0(seq(2002,2021),"-10-01")%>%as.Date
date_fin_calcul=paste0(seq(2003,2022),"-09-30")%>%as.Date

annees_hydro<-data.frame(date_debut_calcul=date_debut_calcul, 
                         date_fin_calcul=date_fin_calcul,
                         nom=paste0(seq(2002,2021),
                                    "-",
                                    seq(2003,2022)))



tmp<-lapply(seq(2002:2021),
function(x){calcule_hydraulicite(debit,
                     date_debut_calcul=annees_hydro$date_debut_calcul[x],
                     date_fin_calcul=annees_hydro$date_fin_calcul[x])
  }
)


tmp<-unlist(tmp)
tmp<-data.frame(annee=annees_hydro$nom, hydraulicite=tmp)


library(ggplot2)

ggplot2::ggplot(tmp, ggplot2::aes(annee, hydraulicite)) +
  ggplot2::geom_bar(stat="identity") +
  ggplot2::ylab("hydraulicite") + 
  ggplot2::geom_hline(yintercept=1)+
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust=0.5)) +
  ggplot2::ggtitle("Hydraulicit\u00e9 sur la Vilaine \u00e0 Rieux",
          subtitle="station hydrom\u00e9trique J930061101")

importe_debit_dates_dispo

importe_debit_dates_dispo()
#>              name start_date   end_date
#> 1          agrhys 1993-03-13 2019-09-15
#> 2  archives_dreal 1960-01-31 2022-10-31
#> 3         hub_eau 2020-11-24 2023-01-25

importe_debit

test_debit<-importe_debit(X=381425.6, 
                          Y=6755598, 
                          date_debut=as.Date("2010-01-01"), 
                          date_fin = as.Date("2010-01-17"))
#CALCUL DU FLUX DE NITRATE SUR LE SEMNON
datafile <- system.file("donnees_nitrate_semnon.csv", package = "calculeflux")
nitrates_semnon <- read.csv2(datafile, 
                             encoding = "UTF-8",
                             colClasses=c("factor",
                                          "character",
                                          "numeric"),
                             dec=",")
#date mini et maxi
nitrates_semnon$DatePrel<-as.POSIXct(nitrates_semnon$DatePrel, format="%d/%m/%Y %H:%M")
summary(nitrates_semnon$DatePrel)
#>                       Min.                    1st Qu. 
#> "2010-01-06 09:35:00.0000" "2013-01-14 09:00:00.0000" 
#>                     Median                       Mean 
#> "2016-04-26 23:27:30.0000" "2016-06-01 04:32:09.8630" 
#>                    3rd Qu.                       Max. 
#> "2019-12-31 21:48:45.0000" "2022-12-07 13:20:00.0000"


# import des débits sur le Semnon à Eancé
debit_semnon<-importe_debit(X=381425.6, 
                          Y=6755598, 
                          date_debut=as.Date("2010-10-01"), 
                          date_fin = as.Date("2022-09-30"))



# calcul du flux annuel sur la période
calcul_flux_annuel<-function(annee)
{
  calcule_flux(
  analyses=nitrates_semnon,
  col_dates_anal = "DatePrel",
  col_analyses = "RsAna",
  debit=debit_semnon,
  methode = "M6",
  date_debut_calcul=paste0(annee,"-10-01")%>%as.Date(),
  date_fin_calcul=paste0((annee+1),"-10-01")%>%as.Date()
)
 
}



annees<-seq(2011,2021)
tmp<-lapply(annees, calcul_flux_annuel)
tmp<-unlist(tmp)
rslt_semnon<-data.frame(annee_hydro=paste0(annees, " - ", annees+1), flux=tmp/1000)


ggplot2::ggplot(rslt_semnon, ggplot2::aes(annee_hydro, flux)) +
  ggplot2::geom_bar(stat="identity") +
  ggplot2::ylab("flux (t NO3/an)") + 
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust=0.5)) +
  ggplot2::ggtitle("Flux de nitrates calcul\u00e9s sur le Semnon \u00e0 Eanc\u00e9",
          subtitle="NO3 station 04211950 / d\u00e9bits 
          estim\u00e9s \u00e0 l\'aide de l\'API SIMFEN / GEOSAS")




##############################

#CALCUL DU FLUX DE NITRATE SUR LA VILAINE AVEC SIMFEN
datafile <- system.file("nitrates.csv", package = "calculeflux")
nitrates <- read.csv2(datafile, encoding = "UTF-8")


#date mini et maxi
nitrates$DatePrel<-nitrates$DatePrel%>%as.Date()
summary(nitrates$DatePrel)
#>         Min.      1st Qu.       Median         Mean      3rd Qu.         Max. 
#> "1971-01-12" "1993-03-06" "2004-07-17" "2002-10-11" "2013-03-19" "2022-06-01"


# import des débits sur la Vilaine au niveau de la station hydro
debit_vilaine<-importe_debit(X=314920, 
                          Y=6732475, 
                          date_debut=as.Date("2010-10-01"), 
                          date_fin = as.Date("2022-09-30"))



# calcul du flux annuel sur la période
calcul_flux_annuel<-function(annee)
{
  calcule_flux(
  analyses=nitrates,
  col_dates_anal = "DatePrel",
  col_analyses = "RsAna",
  debit=debit_vilaine,
  methode = "M6",
  date_debut_calcul=paste0(annee,"-10-01")%>%as.Date(),
  date_fin_calcul=paste0((annee+1),"-10-01")%>%as.Date()
)
 
}



annees<-seq(2010,2021)
tmp<-lapply(annees, calcul_flux_annuel)

tmp<-unlist(tmp)
flux_vilaine_simfen<-data.frame(annee_hydro=paste0(annees, " - ", annees+1), flux=tmp/1000)


ggplot2::ggplot(flux_vilaine_simfen, ggplot2::aes(annee_hydro, flux)) +
  ggplot2::geom_bar(stat="identity") +
  ggplot2::ylab("flux (t NO3/an)") + 
  ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust=0.5)) +
  ggplot2::ggtitle("Flux de nitrates calcul\u00e9s sur la Vilaine \u00e0 Rieux",
          subtitle="NO3 station 04216000 / d\u00e9bits 
          estim\u00e9s \u00e0 l\'aide de l\'API SIMFEN / GEOSAS")

importe_BV_amont

# Pt en Bretagne
shp<-importe_BV_amont(X=381425.6,
                      Y=6755598)
#> Reading layer `OGRGeoJSON' from data source 
#>   `{
#> "type": "FeatureCollection",
#> "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::2154" } },
#> "features": [
#> { "type": "Feature", "properties": { "gml_id": "1", "code": 1, "surface_ha": 5979.5 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 381386.208787999989, 6755607.010373 ], [ 381361.432366, 6755632.195604 ], [ 381462.1733, 6755731.3012899998575 ], [ 381462.99092599999858, 6755831.22460599988699 ], [ 381413.438076, 6755881.59508 ], [ 381414.255698, 6755981.51840799953789 ], [ 381389.479269, 6756006.70364599954337 ], [ 381339.517601, 6756007.112455 ], [ 381289.964739, 6756057.4829299999401 ], [ 381240.003069999977, 6756057.89173499960452 ], [ 381215.22663599997759, 6756083.076972 ], [ 381215.63543899997603, 6756133.038642 ], [ 381166.082567, 6756183.409117 ], [ 381166.90016899997136, 6756283.332468 ], [ 381217.27065, 6756332.8853439996019 ], [ 381218.497057, 6756482.770391 ], [ 381268.867548, 6756532.3232739996165 ], [ 381269.276352, 6756582.284962 ], [ 381319.646848, 6756631.837848 ], [ 381320.055654, 6756681.79954 ], [ 381471.16717299999436, 6756830.45820199977607 ], [ 381471.57598399999551, 6756880.41990199964494 ], [ 381496.76124199997867, 6756905.196347 ], [ 381696.608056, 6756903.56108199991286 ], [ 381721.79331799998181, 6756928.337523 ], [ 381672.240433, 6756978.708048 ], [ 381722.610961, 6757028.2609339999035 ], [ 381724.24624399997992, 6757228.10778 ], [ 381674.69334599998547, 6757278.47831599973142 ], [ 381676.73743899998954, 6757528.28692699968815 ], [ 381701.922712, 6757553.063381 ], [ 381751.884442, 6757552.65456099994481 ], [ 381777.069717, 6757577.431014 ], [ 381778.296183, 6757727.316211 ], [ 381728.743267, 6757777.686768 ], [ 381731.605004, 6758127.418974 ], [ 381807.16086499998346, 6758201.748371 ], [ 381857.1226199999801, 6758201.339548 ], [ 381882.3079099999741, 6758226.11601199954748 ], [ 381885.98733199998969, 6758675.77188399992883 ], [ 381588.669567, 6758977.995462 ], [ 381689.410769, 6759077.101405 ], [ 381689.81958399998257, 6759127.063194 ], [ 381740.190193, 6759176.61616799980402 ], [ 381741.82546299998648, 6759376.4633499998599 ], [ 381667.49598399997922, 6759452.01927599962801 ], [ 381567.572377, 6759452.83690099976957 ], [ 381542.7958799999906, 6759478.022207 ], [ 381518.019382, 6759503.20751299988478 ], [ 381418.09577199997148, 6759504.02512599993497 ], [ 381393.31927199999336, 6759529.210431 ], [ 381394.5456819999963, 6759679.095854 ], [ 381444.916298, 6759728.648861 ], [ 381446.96032299997751, 6759978.4579499997199 ], [ 381497.33095299999695, 6760028.010967 ], [ 381501.41901499999221, 6760527.62931099999696 ], [ 381451.865974, 6760577.99996099993587 ], [ 381452.683581, 6760677.923657 ], [ 381503.054238, 6760727.476703 ], [ 381503.463043, 6760777.438555999659 ], [ 381453.90999199997168, 6760827.809216 ], [ 381455.13640199997462, 6760977.69479199964553 ], [ 381430.35987099999329, 6761002.88012399990112 ], [ 381330.4361439999775, 6761003.69772499985993 ], [ 381256.106542, 6761079.253716 ], [ 381257.332927, 6761229.139321 ], [ 381207.77984799997648, 6761279.509987 ], [ 381208.59743299998809, 6761379.433737 ], [ 381159.044346, 6761429.804406 ], [ 381159.45313699997496, 6761479.76628599967808 ], [ 381260.19449, 6761578.872467 ], [ 381285.3798299999908, 6761603.649012 ], [ 381435.265491, 6761602.42261699959636 ], [ 381536.006876, 6761701.528787 ], [ 381635.930659, 6761700.71117299981415 ], [ 381686.30136099999072, 6761750.264254 ], [ 381836.187042, 6761749.037813 ], [ 381886.557754, 6761798.590889 ], [ 381986.48154599999543, 6761797.77324699983001 ], [ 382085.58768499997677, 6761697.031812 ], [ 382135.549577, 6761696.62298499979079 ], [ 382333.761799999978, 6761495.14010499976575 ], [ 382433.6855699999724, 6761494.322428 ], [ 382483.238612, 6761443.9517029998824 ], [ 382932.8955619999906, 6761440.27204 ], [ 382983.266308, 6761489.825062 ], [ 383183.11385099997278, 6761488.18959799967706 ], [ 383334.226136, 6761636.848643 ], [ 383683.95938299997943, 6761633.98646599985659 ], [ 383733.512384, 6761583.615685 ], [ 383783.47427499998594, 6761583.20679299999028 ], [ 383956.90974299999652, 6761406.909051 ], [ 384031.239214, 6761331.35287499986589 ], [ 384131.162977, 6761330.53506499994546 ], [ 384180.7159499999834, 6761280.164277 ], [ 384230.67782899999293, 6761279.755366 ], [ 384280.23079599998891, 6761229.384576 ], [ 384330.1926739999908, 6761228.97566199954599 ], [ 384454.075068, 6761103.04868 ], [ 384453.257227, 6761003.1249399995431 ], [ 384478.03370099997846, 6760977.93954499997199 ], [ 384677.88117499998771, 6760976.3038429999724 ], [ 384728.251975, 6761025.856781 ], [ 384778.213846, 6761025.4478489998728 ], [ 384877.31971399998292, 6760924.70624299999326 ], [ 385227.052785, 6760921.8436329998076 ], [ 385478.90692699997453, 6761169.60821199975908 ], [ 385503.68338499998208, 6761144.422793 ], [ 385503.274424, 6761094.460919 ], [ 385452.9035889999941, 6761044.908006 ], [ 385452.4946299999719, 6760994.94613599963486 ], [ 385351.752976, 6760895.840316 ], [ 385225.825932, 6760771.958042 ], [ 385175.86407, 6760772.3669919995591 ], [ 385075.122456, 6760673.2611699998379 ], [ 385049.93705499998759, 6760648.48471499979496 ], [ 385048.710221, 6760498.59915699996054 ], [ 384998.339427, 6760449.046253 ], [ 384997.52154099999461, 6760349.122561 ], [ 385047.074441, 6760298.751774 ], [ 385045.4386599999852, 6760098.904423 ], [ 385144.544432, 6759998.16286399960518 ], [ 385169.320872, 6759972.977474 ], [ 385268.426624, 6759872.235914 ], [ 385318.38845099997707, 6759871.82695799972862 ], [ 385392.717751, 6759796.270785 ], [ 385392.30879199999617, 6759746.30896299984306 ], [ 385540.967361, 6759595.19662099983543 ], [ 385714.402314, 6759418.89888599980623 ], [ 385764.364123, 6759418.48991199955344 ], [ 385789.1405399999931, 6759393.304521 ], [ 385738.76975799998036, 6759343.751689 ], [ 385737.9518099999987, 6759243.82808099966496 ], [ 385687.58103499998106, 6759194.2752539999783 ], [ 385685.127199999988, 6758894.504491 ], [ 385634.75644, 6758844.95167599990964 ], [ 385634.34746899997117, 6758794.989891 ], [ 385558.7913399999961, 6758720.660671 ], [ 384959.24996099999407, 6758725.568148 ], [ 384631.840327, 6758403.47472199983895 ], [ 384629.38673199998448, 6758103.704156 ], [ 384604.20138799998676, 6758078.927745 ], [ 384554.23963299999014, 6758079.33667599968612 ], [ 384428.31293199997162, 6757955.454617 ], [ 384427.90400699997554, 6757905.49286899995059 ], [ 384576.56245799997123, 6757754.38085099961609 ], [ 384575.335663, 6757604.495636 ], [ 384524.964997, 6757554.94283199962229 ], [ 384524.556067, 6757504.9811 ], [ 384423.814751, 6757405.875497 ], [ 384373.444098, 6757356.322696 ], [ 384372.21732499997597, 6757206.437529 ], [ 384271.476043, 6757107.33193899970502 ], [ 384270.2492809999967, 6756957.44680199958384 ], [ 384295.02567499998258, 6756932.261486 ], [ 384344.98738499998581, 6756931.85256399959326 ], [ 384394.54016899998533, 6756881.481931 ], [ 384494.463585, 6756880.664075 ], [ 384519.239973, 6756855.47875699959695 ], [ 384544.016361, 6756830.29343799967319 ], [ 384643.939774, 6756829.4755699997768 ], [ 384693.492542, 6756779.104929 ], [ 384793.415951, 6756778.287049 ], [ 384842.968712, 6756727.91640399955213 ], [ 385042.815523, 6756726.28061299957335 ], [ 385092.368273, 6756675.9099599998444 ], [ 385142.32997399999294, 6756675.501005 ], [ 385191.88271799997892, 6756625.13034899998456 ], [ 385241.844417, 6756624.72139099985361 ], [ 385291.397155, 6756574.35073299985379 ], [ 385391.32055, 6756573.532805 ], [ 385440.873281, 6756523.162143 ], [ 385490.834976, 6756522.7531749997288 ], [ 385515.6113389999955, 6756497.567842 ], [ 385540.387701, 6756472.3825099999085 ], [ 385840.157866, 6756469.92864499986172 ], [ 385889.71057499997551, 6756419.557969 ], [ 386039.59565299999667, 6756418.331004 ], [ 386089.14835299999686, 6756367.96032099984586 ], [ 386538.803574, 6756364.279302 ], [ 386588.35625299997628, 6756313.90860099997371 ], [ 386688.279633, 6756313.090571 ], [ 386737.83230399998138, 6756262.719866 ], [ 386787.7939919999917, 6756262.31084599997848 ], [ 386837.346657, 6756211.940138 ], [ 386887.308344, 6756211.53111399989575 ], [ 386986.413659, 6756110.789694 ], [ 387036.3753409999772, 6756110.380664 ], [ 387085.927991, 6756060.009952 ], [ 387185.85135299997637, 6756059.191882 ], [ 387235.403995, 6756008.821166 ], [ 387285.365674, 6756008.412126 ], [ 387334.91831099998672, 6755958.041407 ], [ 387634.688375, 6755955.587115 ], [ 387684.240996, 6755905.216384 ], [ 387984.0110519999871, 6755902.7620099997148 ], [ 388084.752548, 6756001.867224 ], [ 388134.7142289999756, 6756001.45815099962056 ], [ 388185.084985, 6756051.0107559999451 ], [ 388209.861287, 6756025.82537799980491 ], [ 388209.452211, 6755975.863698 ], [ 388333.33370499999728, 6755849.9368099998683 ], [ 388383.29538, 6755849.527727 ], [ 388482.40055399999255, 6755748.78621099982411 ], [ 388507.176845, 6755723.600832 ], [ 388556.729424, 6755673.23007399961352 ], [ 388556.32033299998147, 6755623.26840799953789 ], [ 388304.466595, 6755375.505539 ], [ 388303.648432, 6755275.58223299961537 ], [ 388253.277699999977, 6755226.02966399956495 ], [ 388252.45954, 6755126.10637 ], [ 388302.012104, 6755075.73564399965107 ], [ 388298.739445, 6754676.0425599999726 ], [ 388273.5540899999905, 6754651.266288 ], [ 388173.630834, 6754652.084448 ], [ 388098.07478099997388, 6754577.755625 ], [ 388095.211253, 6754228.024309 ], [ 388144.7637869999744, 6754177.65362299978733 ], [ 388143.1274759999942, 6753977.807207 ], [ 388092.756799, 6753928.25468499958515 ], [ 388042.386126, 6753878.70216399990022 ], [ 388040.340754, 6753628.894208 ], [ 388089.893265, 6753578.523547 ], [ 388089.48418799997307, 6753528.56196399964392 ], [ 388188.589194, 6753427.82064499985427 ], [ 388188.18011299998034, 6753377.859067 ], [ 388262.508855, 6753302.303081 ], [ 388412.3935799999745, 6753301.0758199999109 ], [ 388461.946063, 6753250.70515699964017 ], [ 388561.8692099999753, 6753249.886969 ], [ 388586.64544799999567, 6753224.701635 ], [ 388586.23635199997807, 6753174.740065 ], [ 388685.341292, 6753073.99873199965805 ], [ 388833.998672, 6752922.88673099968582 ], [ 388833.18045799998799, 6752822.963615 ], [ 388882.73290699999779, 6752772.59295199997723 ], [ 388907.509129, 6752747.4076199997216 ], [ 388957.47068399999989, 6752746.998509 ], [ 389056.57556099997601, 6752646.257178 ], [ 389256.421764, 6752644.620698 ], [ 389281.19797699997434, 6752619.43536099977791 ], [ 389280.788852, 6752569.47381199989468 ], [ 389355.11748299997998, 6752493.91780399996787 ], [ 389405.079028, 6752493.508674999699 ], [ 389454.63144199998351, 6752443.13800099957734 ], [ 389554.554529, 6752442.319733 ], [ 389604.10693499998888, 6752391.94905399996787 ], [ 389654.06847599998582, 6752391.539915 ], [ 389703.62087599997176, 6752341.169234 ], [ 389803.543956, 6752340.35094599984586 ], [ 389853.09634899999946, 6752289.98026099987328 ], [ 390002.98096399998758, 6752288.75280799996108 ], [ 390176.414287, 6752112.455388 ], [ 390176.00512599997455, 6752062.493858 ], [ 390250.333675, 6751986.93782399967313 ], [ 390300.295202, 6751986.528659 ], [ 390399.39991699997336, 6751885.787274 ], [ 390449.36144, 6751885.378103 ], [ 390474.137615, 6751860.19275599997491 ], [ 390523.689963, 6751809.822061 ], [ 390523.28078799997456, 6751759.8605429995805 ], [ 390572.8331299999845, 6751709.489849999547 ], [ 390571.196421, 6751509.643802 ], [ 390620.74875099997735, 6751459.273117 ], [ 390618.293673, 6751159.50411599967629 ], [ 390567.923, 6751109.951801 ], [ 390565.05875299999025, 6750760.22140299994498 ], [ 390539.87342399999034, 6750735.44525299966335 ], [ 389890.374207, 6750740.76439699996263 ], [ 389840.003579, 6750691.212073 ], [ 389540.234727, 6750693.6669399999082 ], [ 389490.682388, 6750744.037552 ], [ 389440.72091099998215, 6750744.446688 ], [ 389391.168566, 6750794.81729899998754 ], [ 389191.32265099999495, 6750796.45381299965084 ], [ 389141.7702949999948, 6750846.824416 ], [ 388592.194014, 6750851.324648 ], [ 388542.64163399999961, 6750901.695228 ], [ 388392.757189, 6750902.922516 ], [ 388342.38661699998192, 6750853.3701299997047 ], [ 388292.834227, 6750903.74069899972528 ], [ 388043.02682199998526, 6750905.78612199984491 ], [ 387993.47441899997648, 6750956.156681 ], [ 387793.628489, 6750957.792976 ], [ 387744.07607399998233, 6751008.163528 ], [ 387694.11459, 6751008.572594 ], [ 387644.56216899998253, 6751058.94314299989492 ], [ 387394.75474, 6751060.98843799997121 ], [ 387345.20230599999195, 6751111.358977 ], [ 386795.62594699999318, 6751115.858431 ], [ 386746.07348899997305, 6751166.22894699964672 ], [ 386696.11200099997222, 6751166.63797399960458 ], [ 386645.741488, 6751117.08551399968565 ], [ 386445.895542, 6751118.721597 ], [ 386396.343071, 6751169.092098 ], [ 386346.381583, 6751169.501112 ], [ 386296.829105, 6751219.871612 ], [ 386196.90612599998713, 6751220.6896299999207 ], [ 386146.535631, 6751171.137148 ], [ 385946.689681, 6751172.77315299957991 ], [ 385897.13718899997184, 6751223.143636 ], [ 385697.29123199998867, 6751224.779601 ], [ 385647.738728, 6751275.150077 ], [ 384998.239354, 6751280.466721 ], [ 384948.686822, 6751330.83717 ], [ 384848.763838, 6751331.655082 ], [ 384799.211299, 6751382.025526 ], [ 384749.249805, 6751382.43447699956596 ], [ 384698.87936399999307, 6751332.881935 ], [ 384349.14892599999439, 6751335.744524 ], [ 384299.596368, 6751386.11494799982756 ], [ 384199.673382, 6751386.9328089999035 ], [ 384100.56824599998072, 6751487.673649 ], [ 384050.6067499999772, 6751488.082572 ], [ 383976.2778849999886, 6751563.63819899968803 ], [ 383976.68680399999721, 6751613.5996979996562 ], [ 383951.91051299998071, 6751638.784907 ], [ 383901.9490109999897, 6751639.19382499996573 ], [ 383703.7386369999731, 6751840.67549199983478 ], [ 383603.815619, 6751841.49330499954522 ], [ 383554.263012, 6751891.863718 ], [ 383304.455457, 6751893.90820499975234 ], [ 383254.90283699997235, 6751944.2786069996655 ], [ 383105.01829899998847, 6751945.5052699996158 ], [ 383055.46567, 6751995.87566599994898 ], [ 382955.542641, 6751996.693427 ], [ 382905.990004, 6752047.06381899956614 ], [ 382806.066972, 6752047.88156799972057 ], [ 382756.514327, 6752098.25195599999279 ], [ 382656.591292, 6752099.069694 ], [ 382607.03863899997668, 6752149.440077 ], [ 382257.30800499999896, 6752152.30208299960941 ], [ 382206.93763699999545, 6752102.749416 ], [ 381957.130054, 6752104.793638 ], [ 381907.57737499999348, 6752155.163993 ], [ 381807.65433799999, 6752155.981664 ], [ 381758.10165099997539, 6752206.35201499983668 ], [ 381158.56341599998996, 6752211.257852 ], [ 381133.78706, 6752236.44301499985158 ], [ 381134.19586699997308, 6752286.404535 ], [ 381084.64315, 6752336.774863 ], [ 381135.01348, 6752386.32758099958301 ], [ 381136.648707, 6752586.173696 ], [ 381111.872343, 6752611.35886599961668 ], [ 381011.949273, 6752612.176473 ], [ 380860.83828299999004, 6752463.51827799994498 ], [ 380835.65312099998118, 6752438.74191199988127 ], [ 380835.24432599998545, 6752388.780387 ], [ 380784.874008, 6752339.22765799984336 ], [ 380784.46521499997471, 6752289.26613599993289 ], [ 380708.909747, 6752214.93704599980265 ], [ 380659.35701699997298, 6752265.307354 ], [ 380359.587896, 6752267.760049 ], [ 380310.035151, 6752318.1303449999541 ], [ 380260.07362899999134, 6752318.539118 ], [ 380184.51819199998863, 6752244.209997 ], [ 380159.333049, 6752219.433623 ], [ 380059.410014, 6752220.25115699972957 ], [ 380034.22487299999921, 6752195.474781 ], [ 380033.816109, 6752145.513267 ], [ 379983.44583199999761, 6752095.9605179997161 ], [ 379982.62830799998483, 6751996.037499 ], [ 379881.887774, 6751896.9320099996403 ], [ 379856.7026429999969, 6751872.1556369997561 ], [ 379756.77963599999202, 6751872.97314899973571 ], [ 379707.226884, 6751923.34340499993414 ], [ 379407.45785499998601, 6751925.795881 ], [ 379357.90508799999952, 6751976.166125 ], [ 379307.94358199997805, 6751976.57486199960113 ], [ 379233.614422, 6752052.13022399973124 ], [ 379235.658086, 6752301.9377899998799 ], [ 379336.39859699999215, 6752401.0433599995449 ], [ 379336.807333, 6752451.00488299969584 ], [ 379387.177596, 6752500.557671 ], [ 379387.586335, 6752550.519198 ], [ 379338.03354199999012, 6752600.889464 ], [ 379338.442278, 6752650.850995 ], [ 379388.812548, 6752700.403791 ], [ 379392.08244899997953, 6753100.096125 ], [ 379342.529633, 6753150.466411 ], [ 379343.34710399998585, 6753250.389518 ], [ 379244.24145299999509, 6753351.130098 ], [ 379245.4676459999755, 6753501.01478399988264 ], [ 379195.91480799997225, 6753551.38508 ], [ 379199.59336399997119, 6754001.0392599999905 ], [ 379249.96367899997858, 6754050.592117 ], [ 379253.64224499999546, 6754500.24647399969399 ], [ 379204.08936699997867, 6754550.61680699978024 ], [ 379229.274534, 6754575.39324599970132 ], [ 379329.1977499999921, 6754574.575786 ], [ 379428.303495, 6754473.83510699961334 ], [ 379478.265099, 6754473.4263699995354 ], [ 379579.00579199998174, 6754572.53210099972785 ], [ 379678.929009, 6754571.71461299993098 ], [ 379728.48187, 6754521.3442599996924 ], [ 379828.405084, 6754520.5267599998042 ], [ 379877.95793799997773, 6754470.1564029995352 ], [ 380127.765964, 6754468.11260899994522 ], [ 380177.31880399998045, 6754417.7422409998253 ], [ 380277.24201099999482, 6754416.92470599990338 ], [ 380376.347672, 6754316.18396199960262 ], [ 380426.30927199998405, 6754315.77518699970096 ], [ 380753.716796, 6754637.86854299996048 ], [ 380754.125583, 6754687.83015699964017 ], [ 380905.236809, 6754836.488637 ], [ 380955.60722499998519, 6754886.041464 ], [ 380957.242405, 6755085.887969 ], [ 381007.612833, 6755135.440804 ], [ 381008.021629, 6755185.40243699960411 ], [ 381108.762501, 6755284.5081129996106 ], [ 381209.503387, 6755383.6137889996171 ], [ 381234.688612, 6755408.390208 ], [ 381284.65025599999353, 6755407.981402 ], [ 381360.20593699999154, 6755482.31065599992871 ], [ 381360.61474699998507, 6755532.272304 ], [ 381410.98520799999824, 6755581.82514199987054 ], [ 381386.208787999989, 6755607.010373 ], [ 381386.208787999989, 6755607.010373 ] ] ] ] } }
#> ]
#> }
#> ' 
#>   using driver `GeoJSON'
#> Simple feature collection with 1 feature and 3 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 379195.9 ymin: 6750691 xmax: 390620.7 ymax: 6761799
#> Projected CRS: RGF93 v1 / Lambert-93

# Pt hors Bretagne
# shp<-importe_BV_amont(X=336599,
#                       Y=6674450)

plot(sf::st_geometry(shp))

calcule_flux_annuels

   

datafile <- system.file("nitrates.csv", package = "calculeflux")
nitrates <- read.csv2(datafile, encoding = "UTF-8")
nitrates$DatePrel<-nitrates$DatePrel%>%as.Date()


datafile <- system.file("debit.csv", package = "calculeflux")
debit <- read.csv2(datafile, encoding = "UTF-8")
debit$date_obs_elab<-debit$date_obs_elab%>%as.Date()

annees=c(2010,2014)
 mois_debut<-9
  


calcule_flux_annuels(annees=c(2010,2021),
                     mois_debut=10,
                     analyses0=nitrates,
                     debit0=debit
                     )
#> # A tibble: 12 × 6
#>    annee_hydro N_RsAna N_Qjm       flux hydraulicity flux_pond
#>    <fct>         <int> <int>      <dbl>        <dbl>     <dbl>
#>  1 2010-2011        24   365  48949199.        0.720 67938515.
#>  2 2011-2012        24   366  23352921.        0.470 49637870.
#>  3 2012-2013        24   365  73309935.        1.10  66684513.
#>  4 2013-2014        24   365 119527786.        2.08  57415581.
#>  5 2014-2015        24   362  57391672.        1.03  55496868.
#>  6 2015-2016        23   366  57005713.        1.02  55656556.
#>  7 2016-2017        24   365  16815337.        0.325 51747199.
#>  8 2017-2018        24   365  69876098.        1.06  66135180.
#>  9 2018-2019        24   365  40510472.        0.653 62026745.
#> 10 2019-2020        18   366 120861620.        1.98  61056233.
#> 11 2020-2021        26   365  69455391.        1.23  56336759.
#> 12 2021-2022        19   355  44437050.        0.662 67159350.