@@ -134,21 +134,19 @@ model2netcdf.SIPNET <- function(outdir, sitelat, sitelon, start_date, end_date,
134134 bounds <- round(bounds ,4 )
135135
136136 # # Setup outputs for netCDF file in appropriate units
137- output <- list (
138- " GPP" = (sub.sipnet.output $ gpp * 0.001 ) / timestep.s , # GPP in kgC/m2/s
139- " NPP" = (sub.sipnet.output $ gpp * 0.001 ) / timestep.s - ((sub.sipnet.output $ rAboveground *
140- 0.001 ) / timestep.s + (sub.sipnet.output $ rRoot * 0.001 ) / timestep.s ), # NPP in kgC/m2/s. Post SIPNET calculation
141- " TotalResp" = (sub.sipnet.output $ rtot * 0.001 ) / timestep.s , # Total Respiration in kgC/m2/s
142- " AutoResp" = (sub.sipnet.output $ rAboveground * 0.001 ) / timestep.s + (sub.sipnet.output $ rRoot *
143- 0.001 ) / timestep.s , # Autotrophic Respiration in kgC/m2/s
144- " HeteroResp" = ((sub.sipnet.output $ rSoil - sub.sipnet.output $ rRoot ) * 0.001 ) / timestep.s , # Heterotrophic Respiration in kgC/m2/s
145- " SoilResp" = (sub.sipnet.output $ rSoil * 0.001 ) / timestep.s , # Soil Respiration in kgC/m2/s
146- " NEE" = (sub.sipnet.output $ nee * 0.001 ) / timestep.s , # NEE in kgC/m2/s
147- " AbvGrndWood" = (sub.sipnet.output $ plantWoodC * 0.001 ), # Above ground wood kgC/m2
148- " leaf_carbon_content" = (sub.sipnet.output $ plantLeafC * 0.001 ), # Leaf C kgC/m2
149- " TotLivBiom" = (sub.sipnet.output $ plantWoodC * 0.001 ) + (sub.sipnet.output $ plantLeafC * 0.001 ) +
150- (sub.sipnet.output $ coarseRootC + sub.sipnet.output $ fineRootC ) * 0.001 , # Total living C kgC/m2
151- " TotSoilCarb" = (sub.sipnet.output $ soil * 0.001 ) + (sub.sipnet.output $ litter * 0.001 ) # Total soil C kgC/m2
137+ output <- list (
138+ " GPP" = PEcAn.utils :: ud_convert(sub.sipnet.output $ gpp , " g/m2" , " kg/m2" ) / timestep.s ,
139+ " NPP" = PEcAn.utils :: ud_convert(sub.sipnet.output $ gpp - (sub.sipnet.output $ rAboveground + sub.sipnet.output $ rRoot ), " g/m2" , " kg/m2" ) / timestep.s ,
140+ " TotalResp" = PEcAn.utils :: ud_convert(sub.sipnet.output $ rtot , " g/m2" , " kg/m2" ) / timestep.s ,
141+ " AutoResp" = (PEcAn.utils :: ud_convert(sub.sipnet.output $ rAboveground + sub.sipnet.output $ rRoot , " g/m2" , " kg/m2" )) / timestep.s ,
142+ " HeteroResp" = PEcAn.utils :: ud_convert(sub.sipnet.output $ rSoil - sub.sipnet.output $ rRoot , " g/m2" , " kg/m2" ) / timestep.s ,
143+ " SoilResp" = PEcAn.utils :: ud_convert(sub.sipnet.output $ rSoil , " g/m2" , " kg/m2" ) / timestep.s ,
144+ " NEE" = PEcAn.utils :: ud_convert(sub.sipnet.output $ nee , " g/m2" , " kg/m2" ) / timestep.s ,
145+ " AbvGrndWood" = PEcAn.utils :: ud_convert(sub.sipnet.output $ plantWoodC , " g/m2" , " kg/m2" ),
146+ " leaf_carbon_content" = PEcAn.utils :: ud_convert(sub.sipnet.output $ plantLeafC , " g/m2" , " kg/m2" ),
147+ " TotLivBiom" = (PEcAn.utils :: ud_convert(sub.sipnet.output $ plantWoodC + sub.sipnet.output $ plantLeafC +
148+ sub.sipnet.output $ coarseRootC + sub.sipnet.output $ fineRootC , " g/m2" , " kg/m2" )),
149+ " TotSoilCarb" = PEcAn.utils :: ud_convert(sub.sipnet.output $ soil + sub.sipnet.output $ litter , " g/m2" , " kg/m2" )
152150 )
153151 if (revision == " unk" ) {
154152 # # *** NOTE : npp in the sipnet output file is actually evapotranspiration, this is due to a bug in sipnet.c : ***
@@ -164,8 +162,12 @@ model2netcdf.SIPNET <- function(outdir, sitelat, sitelon, start_date, end_date,
164162 output [[" SoilMoist" ]] <- (sub.sipnet.output $ soilWater * 10 ) # Soil moisture kgW/m2
165163 output [[" SoilMoistFrac" ]] <- (sub.sipnet.output $ soilWetnessFrac ) # Fractional soil wetness
166164 output [[" SWE" ]] <- (sub.sipnet.output $ snow * 10 ) # SWE
167- output [[" litter_carbon_content" ]] <- sub.sipnet.output $ litter * 0.001 # # litter kgC/m2
168- output [[" litter_mass_content_of_water" ]] <- (sub.sipnet.output $ litterWater * 10 ) # Litter water kgW/m2
165+ output [[" litter_carbon_content" ]] <- PEcAn.utils :: ud_convert(sub.sipnet.output $ litter , " g/m2" , " kg/m2" )
166+ # litterWater was removed in SIPNET v2; only extract if present
167+ if (" litterWater" %in% names(sub.sipnet.output )) {
168+ # Units are labeled elsewhere as kg water m-2 (which is equivalent to mm, but ud_convert doesn't know that)
169+ output [[" litter_mass_content_of_water" ]] <- PEcAn.utils :: ud_convert(sub.sipnet.output $ litterWater , " cm" , " mm" )
170+ }
169171 # calculate LAI for standard output
170172 # LAI = plantLeafC / leafCSpWt
171173 # both operands are in carbon units (gC/m2 and gC/m2_leaf),
@@ -176,17 +178,19 @@ model2netcdf.SIPNET <- function(outdir, sitelat, sitelon, start_date, end_date,
176178 leafCSpWt <- param [param [, 1 ] == " leafCSpWt" , 2 ]
177179 SLA <- 1000 / leafCSpWt # m2 leaf / kg C
178180 output [[" LAI" ]] <- output [[" leaf_carbon_content" ]] * SLA
179- output [[" fine_root_carbon_content" ]] <- sub.sipnet.output $ fineRootC * 0.001 # # fine_root_carbon_content kgC/m2
180- output [[" coarse_root_carbon_content" ]] <- sub.sipnet.output $ coarseRootC * 0.001 # # coarse_root_carbon_content kgC/m2
181- output [[" GWBI" ]] <- (sub.sipnet.output $ woodCreation * 0.001 ) / 86400 # # kgC/m2/s - this is daily in SIPNET
182- output [[" AGB" ]] <- (sub.sipnet.output $ plantWoodC + sub.sipnet.output $ plantLeafC ) * 0.001 # Total aboveground biomass kgC/m2
181+ output [[" fine_root_carbon_content" ]] <- PEcAn.utils :: ud_convert(sub.sipnet.output $ fineRootC , " g/m2" , " kg/m2" )
182+ output [[" coarse_root_carbon_content" ]] <- PEcAn.utils :: ud_convert(sub.sipnet.output $ coarseRootC , " g/m2" , " kg/m2" )
183+ if (" woodCreation" %in% names(sub.sipnet.output )) {
184+ output [[" GWBI" ]] <- PEcAn.utils :: ud_convert(sub.sipnet.output $ woodCreation , " g/m2/day" , " kg/m2/s" )
185+ }
186+ output [[" AGB" ]] <- PEcAn.utils :: ud_convert(sub.sipnet.output $ plantWoodC + sub.sipnet.output $ plantLeafC , " g/m2" , " kg/m2" )
183187 # columns only present in sipnet >= v2 with N and methane turned on
184188 if (" n2o" %in% names(sub.sipnet.output )) {
185- output [[" N2O_flux" ]] <- (sub.sipnet.output $ n2o * 0.001 ) / timestep.s
189+ output [[" N2O_flux" ]] <- PEcAn.utils :: ud_convert (sub.sipnet.output $ n2o , " g/m2 " , " kg/m2 " ) / timestep.s
186190 # convert g N m-2 per timestep -> kg N m-2 s-1
187191 }
188192 if (" ch4" %in% names(sub.sipnet.output )) {
189- output [[" CH4_flux" ]] <- (sub.sipnet.output $ ch4 * 0.001 ) / timestep.s
193+ output [[" CH4_flux" ]] <- PEcAn.utils :: ud_convert (sub.sipnet.output $ ch4 , " g/m2 " , " kg/m2 " ) / timestep.s
190194 # convert g C m-2 per timestep -> kg C m-2 s-1
191195 }
192196 output [[" time_bounds" ]] <- c(rbind(bounds [,1 ], bounds [,2 ]))
@@ -235,19 +239,22 @@ model2netcdf.SIPNET <- function(outdir, sitelat, sitelon, start_date, end_date,
235239 " SoilMoistFrac" = PEcAn.utils :: to_ncvar(" SoilMoistFrac" , dims ),
236240 " SWE" = PEcAn.utils :: to_ncvar(" SWE" , dims ),
237241 " litter_carbon_content" = PEcAn.utils :: to_ncvar(" litter_carbon_content" , dims ),
238- " litter_mass_content_of_water" = PEcAn.utils :: to_ncvar(" litter_mass_content_of_water" , dims ),
239242 " LAI" = PEcAn.utils :: to_ncvar(" LAI" , dims ),
240243 " fine_root_carbon_content" = PEcAn.utils :: to_ncvar(" fine_root_carbon_content" , dims ),
241244 " coarse_root_carbon_content" = PEcAn.utils :: to_ncvar(" coarse_root_carbon_content" , dims ),
242- " GWBI" = ncdf4 :: ncvar_def(" GWBI" , units = " kg C m-2" , dim = list (lon , lat , t ), missval = - 999 ,
243- longname = " Gross Woody Biomass Increment" ),
244245 " AGB" = ncdf4 :: ncvar_def(" AGB" , units = " kg C m-2" , dim = list (lon , lat , t ), missval = - 999 ,
245246 longname = " Total aboveground biomass" ),
246247 " time_bounds" = ncdf4 :: ncvar_def(name = " time_bounds" , units = ' ' ,
247248 longname = " history time interval endpoints" , dim = list (time_interval ,time = t ),
248249 prec = " double" )
249250 )
250-
251+ if (" litter_mass_content_of_water" %in% names(output )) {
252+ nc_var [[" litter_mass_content_of_water" ]] <- PEcAn.utils :: to_ncvar(" litter_mass_content_of_water" , dims )
253+ }
254+ if (" litter_mass_content_of_water" %in% names(output )) {
255+ nc_var [[" GWBI" ]] <- ncdf4 :: ncvar_def(" GWBI" , units = " kg C m-2" , dim = list (lon , lat , t ), missval = - 999 ,
256+ longname = " Gross Woody Biomass Increment" )
257+ }
251258 if (" N2O_flux" %in% names(output )) {
252259 nc_var [[" N2O_flux" ]] <- PEcAn.utils :: to_ncvar(" N2O_flux" , dims )
253260 }
0 commit comments