martens73 / ScarFace

ScarFace - seacarb calculations with R Shiny user interface
MIT License
2 stars 0 forks source link

seacarb::carb() and shiny app results differ #23

Closed chrisdane closed 2 years ago

chrisdane commented 2 years ago

Hi

With flag=15, ALK=2200 µmol kg-1 and DIC=2000 µmol kg-1 the shiny app yields

Sample flag S T Patm P pH CO2 fCO2 pCO2 fCO2pot pCO2pot fCO2insitu pCO2insitu HCO3 CO3 DIC ALK OmegaAragonite OmegaCalcite
NA 15.00 35 25 1.00 0 7.87 17.62 620.53 622.52 620.53 622.52 620.53 622.52 1836.73 145.66 2000.00 2200.00 2.31 3.51

When I do it directly in R the result is

library(seacarb)
seacarb::carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25) # flag=15 --> var1 = Talk in mol kg-1; var2 = DIC in mol kg-1
flag S T Patm P pH CO2 fCO2 pCO2 fCO2pot pCO2pot fCO2insitu pCO2insitu HCO3 CO3 DIC ALK OmegaAragonite OmegaCalcite
15 35 25 1 0 7.870532 1.739097e-05 612.5331 614.4945 612.5331 614.4945 612.5331 614.4945 0.001835282 0.0001473273 0.002 0.0022 2.338158 3.547316

I am aware that the shiny app returns different units than the carb() function, e.g. for ALK and DIC.

However, pCO2_app = 622.52 while pCO2_carb = 614.4945. Could you please explain these differences?

Thanks for any help and kind regards, Chris

packageVersion("seacarb")
[1] ‘3.3.0’
martens73 commented 2 years ago

The carb() function of the seacarb package uses the boron concentration of Uppstrom (1974) as default, while the newer reference of Lee et al. (2010) is more widely used in the community. You can test it by selecting Uppstrom (1974) from the dropdown menu in the Additional choices box in ScarFace. Alternatively, apply the Lee et al. (2010) boron concentration in the original carb() function:

carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25, b="l10")

You should then get identical results between seacarb and ScarFace.

chrisdane commented 2 years ago

Thanks a lot for your answer!

carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25, b="l10")$pCO2 equals 622.5467 which is quite similar as the ScarFace value 622.52 but still not equal?

martens73 commented 2 years ago

I can not reproduce this issue. I always get exactly the same numbers, no matter whether I use seacarb or ScarFace. In fact, there is even no way that they can be different as ScarFace is using seacarb, and there are no conversions involved. Please check and compare carefully the parameters set in each program.

chrisdane commented 2 years ago

Screenshot from ScarFace: Screenshot at 2022-01-14 11-36-54 --> pCO2_scarface = 622.52

library(seacarb)
round(seacarb::carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25, b="l10")$pCO2, 2)
[1] 622.55

--> pCO2_seacarb = 622.55

You cant reproduce this?

This is the flag=15 case in ScarFace:

if (!input$pHscale == "NBS") {
    carb(flag=as.numeric(input$pair), var1=input$first/1000000, var2=input$second/1000000, 
         S=input$salc, T=input$tempc, Patm=1, P=input$presc, 
         Pt=input$pho/1000000, Sit=input$sil/1000000, k1k2=input$k1k2, 
         kf="x", ks="d", pHscale=input$pHscale, b=input$b, gas=input$gasm,
         warn="y", eos="eos80", long=1.e20, lat=1.e20)
} else {
    carb(flag=as.numeric(input$pair), var1=input$first/1000000, var2=input$second/1000000, 
         S=input$salc, T=input$tempc, Patm=1, P=input$presc, 
         Pt=input$pho/1000000, Sit=input$sil/1000000, k1k2=input$k1k2, 
         kf="x", ks="d", pHscale="SWS", b=input$b, gas=input$gasm,
         warn="y", eos="eos80", long=1.e20, lat=1.e20)
}

Since by default pHscale = "T", the first case applies and using the same arguments yields

round(seacarb::carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25, 
                    Patm=1, P=0, Pt=0/1e6, Sit=0/1e6, k1k2="x", kf="x", ks="d", 
                    pHscale="T", b="l10", gas="potential", warn="y", 
                    eos="eos80", long=1.e20, lat=1.e20)$pCO2, 2)
[1] 622.55

, i.e. pCO2_seacarb = pCO2_myscarface = 622.55 != pCO2_scarface = 622.52.

What is the seacarb package version used by ScarFace?

chrisdane commented 2 years ago

Yes its the package version:

packageVersion("seacarb")
[1] ‘3.2.16’
round(seacarb::carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25, b="l10")$pCO2, 2)
[1] 622.52

but

packageVersion("seacarb")
[1] ‘3.3.0’
round(seacarb::carb(flag=15, var1=2200/1e6, var2=2000/1e6, S=35, T=25, b="l10")$pCO2, 2)
[1] 622.55

Thanks and cheers, Chris