Skip to content

Commit

Permalink
Merge pull request #3071 from DongchenZ/develop
Browse files Browse the repository at this point in the history
Change from g to kg for SIPNET IC.process
  • Loading branch information
mdietze committed Dec 21, 2022
2 parents 8335ea5 + ab5a366 commit ab55731
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions models/sipnet/R/write.configs.SIPNET.R
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
IC.nc <- ncdf4::nc_open(IC.path) #for additional variables specific to SIPNET
## plantWoodInit gC/m2
if ("wood" %in% names(IC.pools)) {
param[which(param[, 1] == "plantWoodInit"), 2] <- PEcAn.utils::ud_convert(IC.pools$wood, "g m-2", "g m-2")
param[which(param[, 1] == "plantWoodInit"), 2] <- PEcAn.utils::ud_convert(IC.pools$wood, "kg m-2", "g m-2")
}
## laiInit m2/m2
lai <- IC.pools$LAI
Expand All @@ -520,7 +520,7 @@ write.config.SIPNET <- function(defaults, trait.values, settings, run.id, inputs
}
## soilInit gC/m2
if ("soil" %in% names(IC.pools)) {
param[which(param[, 1] == "soilInit"), 2] <- PEcAn.utils::ud_convert(sum(IC.pools$soil), 'g m-2', 'g m-2') # BETY: kgC m-2
param[which(param[, 1] == "soilInit"), 2] <- PEcAn.utils::ud_convert(sum(IC.pools$soil), 'kg m-2', 'g m-2') # BETY: kgC m-2
}
## soilWFracInit fraction
soilWFrac <- try(ncdf4::ncvar_get(IC.nc,"SoilMoistFrac"),silent = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions modules/data.land/R/cohort2pool.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ cohort2pool <- function(dat, allom_param = NULL, dbh_name="DBH") {
return(AGB)
}
}
#calculate total herbaceous biomass, already in gC
#calculate total herbaceous biomass, already in kgC
tot_herb <- sum(dat[[1]][,"dryMass"])/(herb_plot*herb_num)

#Calculate AGB
Expand All @@ -83,12 +83,12 @@ cohort2pool <- function(dat, allom_param = NULL, dbh_name="DBH") {
tot_leaf <- sum(leaf,na.rm = TRUE)

#Divide by plot area, divide by 2 to convert from kg to kgC
leaf_biomass = ((tot_leaf/(total_area))/2 + tot_herb/1000)*1000#convert from kg to g
leaf_biomass = ((tot_leaf/(total_area))/2 + tot_herb)#in kg

if(tot_biomass == 0){
AGB <- leaf_biomass
}else{
AGB <- ((tot_biomass/(total_area))/2 + tot_herb/1000)*1000#in gram
AGB <- ((tot_biomass/(total_area))/2 + tot_herb)#in kg
}
wood_biomass = AGB - leaf_biomass

Expand Down
6 changes: 4 additions & 2 deletions modules/data.land/R/extract_NEON_veg.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extract_NEON_veg <- function(lon, lat, start_date, end_date, store_dir, neonsite
filter.herb$year <- format(as.Date(filter.herb$collectDate.y, format="%Y-%m-%d"),"%Y")
#Rename NEON column names to match pecan functions
colnames(filter.herb) <- c("site_name", "plot", "Subplot", "plotType", "clipArea", "dryMass", "date", "year")
filter.herb$dryMass <- PEcAn.utils::ud_convert(filter.herb$dryMass, 'g m-2', 'kg m-2')#convert from g to kg.
filter.herb <- Grab_First_Measurements_of_Each_Plot(filter.herb)
}

Expand Down Expand Up @@ -162,8 +163,9 @@ extract_NEON_veg <- function(lon, lat, start_date, end_date, store_dir, neonsite
#calculate soil carbon
joined.soil$bulkDensity <- bulkDensity

#convert from g/cm2 to g/m2, note that we have to divide by 100 because of percentage
joined.soil$SoilCarbon <- (joined.soil$organicCPercent * joined.soil$bulkDensity)*30*100
#here we multiply bulkdensity (in kg/m3) with soil depth (in m) to calculate the soil biomass (in kg/m2) at the top 30 cm depth of soil.
#note that we have to divide by 100 because of percentage for the organicCPercent variable.
joined.soil$SoilCarbon <- joined.soil$organicCPercent/100 * PEcAn.utils::ud_convert(joined.soil$bulkDensity, "g cm-3", "kg m-3") * PEcAn.utils::ud_convert(30, "cm", "m")
}
}
}
Expand Down

0 comments on commit ab55731

Please sign in to comment.