@@ -24,9 +24,6 @@ getField_GUESS <- function(source,
24
24
verbose ,
25
25
... ) {
26
26
27
- # Give warning if file.name is used because it is currently being ignored
28
- if (! is.null(file.name )) warning(paste0(" Argument file.name (currently set to " , file.name , " ) is being ignored." ))
29
-
30
27
# First check if quantity is for FireMIP, if so call a special function with the extra processing required
31
28
if (" FireMIP" %in% quant @ format ) {
32
29
return (openLPJOutputFile_FireMIP(source , quant , target.sta = target.STAInfo , file.name = file.name , verbose = verbose , ... ))
@@ -38,7 +35,7 @@ getField_GUESS <- function(source,
38
35
return (getStandardQuantity_LPJ(source , quant , target.sta = target.STAInfo , file.name = file.name , verbose = verbose , ... ))
39
36
}
40
37
else {
41
- stop(" Unrecognised Quantity in 'quant' argument to getField_GUESS()" )
38
+ stop(" Unrecognised Format of Quantity in 'quant' argument to getField_GUESS()" )
42
39
}
43
40
44
41
@@ -94,7 +91,8 @@ openLPJOutputFile <- function(run,
94
91
95
92
96
93
# Make the filename and check for the file, gunzip if necessary, fail if not present
97
- file.string = file.path(run @ dir , paste(variable , " .out" , sep = " " ))
94
+ if (is.null(file.name )) file.string <- file.path(run @ dir , paste(variable , " .out" , sep = " " ))
95
+ else file.string <- file.path(run @ dir , file.name )
98
96
re.zip <- FALSE
99
97
if (file.exists(file.string )){
100
98
if (verbose ) message(paste(" Found and opening file" , file.string , sep = " " ))
@@ -326,13 +324,13 @@ openLPJOutputFile_FireMIP <- function(run,
326
324
# ############ PER PFT VARIABLES
327
325
328
326
if (variable == " lai" ) {
329
- dt <- openLPJOutputFile(run , " lai" , data.table.only = TRUE , target.sta = target.sta , verbose = verbose )
327
+ dt <- openLPJOutputFile(run , " lai" , data.table.only = TRUE , target.sta = target.sta , file.name = file.name , verbose = verbose )
330
328
}
331
329
if (variable == " landCoverFrac" ) {
332
- dt <- openLPJOutputFile(run , " fpc" , data.table.only = TRUE , target.sta = target.sta , verbose = verbose )
330
+ dt <- openLPJOutputFile(run , " fpc" , data.table.only = TRUE , target.sta = target.sta , file.name = file.name , verbose = verbose )
333
331
}
334
332
if (variable == " theightpft" ) {
335
- dt <- openLPJOutputFile(run , " speciesheights" , data.table.only = TRUE , target.sta = target.sta , verbose = verbose )
333
+ dt <- openLPJOutputFile(run , " speciesheights" , data.table.only = TRUE , target.sta = target.sta , file.name = file.name , verbose = verbose )
336
334
}
337
335
338
336
@@ -476,7 +474,7 @@ openLPJOutputFile_FireMIP <- function(run,
476
474
# Now calculate these bad boys
477
475
if (monthly.to.second || monthly.to.percent || monthly ){
478
476
479
- dt <- openLPJOutputFile(run , guess.var , target.sta , verbose , data.table.only = TRUE )
477
+ dt <- openLPJOutputFile(run , guess.var , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
480
478
setnames(dt , guess.var , variable )
481
479
if (monthly.to.second ){
482
480
# suppressWarnings(dt[, Seconds := seconds.in.month[Month]])
@@ -499,7 +497,7 @@ openLPJOutputFile_FireMIP <- function(run,
499
497
# ## Special monthly variables
500
498
if (variable == " meanFire" ) {
501
499
guess.var <- " real_fire_size"
502
- dt <- openLPJOutputFile(run , guess.var , target.sta , verbose , data.table.only = TRUE )
500
+ dt <- openLPJOutputFile(run , guess.var , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
503
501
setnames(dt , guess.var , variable )
504
502
dt [, (variable ) : = get(variable ) * 10000 ]
505
503
}
@@ -522,10 +520,10 @@ openLPJOutputFile_FireMIP <- function(run,
522
520
dt_cap [, Capacity : = wcap [Code ]]
523
521
dt_cap [, Code : = NULL ]
524
522
525
- dt_upper <- openLPJOutputFile(run , " mwcont_upper" , target.sta , verbose , data.table.only = TRUE )
523
+ dt_upper <- openLPJOutputFile(run , " mwcont_upper" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
526
524
setKeyDGVM(dt_upper )
527
525
528
- dt_lower <- openLPJOutputFile(run , " mwcont_lower" , target.sta , verbose , data.table.only = TRUE )
526
+ dt_lower <- openLPJOutputFile(run , " mwcont_lower" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
529
527
setKeyDGVM(dt_lower )
530
528
dt <- dt_upper [dt_lower ]
531
529
@@ -557,7 +555,7 @@ openLPJOutputFile_FireMIP <- function(run,
557
555
dt_cap [, Capacity : = wcap [Code ]]
558
556
dt_cap [, Code : = NULL ]
559
557
560
- dt <- openLPJOutputFile(run , " mwcont_upper" , target.sta , verbose , data.table.only = TRUE )
558
+ dt <- openLPJOutputFile(run , " mwcont_upper" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
561
559
setKeyDGVM(dt )
562
560
563
561
dt <- dt [dt_cap ]
@@ -575,16 +573,16 @@ openLPJOutputFile_FireMIP <- function(run,
575
573
if (variable == " evapotrans" ) {
576
574
577
575
# firstly combine transpiration and evaporation
578
- dt_trans <- openLPJOutputFile(run , " maet" , target.sta , verbose , data.table.only = TRUE )
579
- dt_evap <- openLPJOutputFile(run , " mevap" , target.sta , verbose , data.table.only = TRUE )
576
+ dt_trans <- openLPJOutputFile(run , " maet" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
577
+ dt_evap <- openLPJOutputFile(run , " mevap" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
580
578
setKeyDGVM(dt_trans )
581
579
setKeyDGVM(dt_evap )
582
580
dt_trans <- dt_evap [dt_trans ]
583
581
rm(dt_evap )
584
582
gc()
585
583
586
584
# now add interception
587
- dt_intercep <- openLPJOutputFile(run , " mintercep" , target.sta , verbose , data.table.only = TRUE )
585
+ dt_intercep <- openLPJOutputFile(run , " mintercep" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
588
586
setKeyDGVM(dt_intercep )
589
587
dt_trans <- dt_trans [dt_intercep ]
590
588
rm(dt_intercep )
@@ -604,19 +602,19 @@ openLPJOutputFile_FireMIP <- function(run,
604
602
# ## ANNUAL C POOLS FROM cpool.out FILE
605
603
606
604
if (variable == " cVeg" ) {
607
- dt <- openLPJOutputFile(run , " cpool" , target.sta , verbose , data.table.only = TRUE )
605
+ dt <- openLPJOutputFile(run , " cpool" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
608
606
target.cols <- append(getDimInfo(dt ), " VegC" )
609
607
dt <- dt [,target.cols ,with = FALSE ]
610
608
setnames(dt , " VegC" , " cVeg" )
611
609
}
612
610
if (variable == " cLitter" ) {
613
- dt <- openLPJOutputFile(run , " cpool" , target.sta , verbose , data.table.only = TRUE )
611
+ dt <- openLPJOutputFile(run , " cpool" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
614
612
target.cols <- append(getDimInfo(dt ), " LittC" )
615
613
dt <- dt [,target.cols ,with = FALSE ]
616
614
setnames(dt , " LittC" , " cLitter" )
617
615
}
618
616
if (variable == " cSoil" ) {
619
- dt <- openLPJOutputFile(run , " cpool" , target.sta , verbose , data.table.only = TRUE )
617
+ dt <- openLPJOutputFile(run , " cpool" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
620
618
target.cols <- append(unlist(getDimInfo(dt )), c(" SoilfC" , " SoilsC" ))
621
619
dt <- dt [,target.cols ,with = FALSE ]
622
620
dt [, " cSoil" : = SoilfC + SoilsC ]
@@ -627,15 +625,15 @@ openLPJOutputFile_FireMIP <- function(run,
627
625
# ## LAND USE FLUX AND STORE FROM luflux.out FILE
628
626
629
627
if (variable == " cProduct" ) {
630
- dt <- openLPJOutputFile(run , " luflux" , target.sta , verbose , data.table.only = TRUE )
628
+ dt <- openLPJOutputFile(run , " luflux" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
631
629
target.cols <- append(getDimInfo(dt ), " Products_Pool" )
632
630
dt <- dt [,target.cols , with = FALSE ]
633
631
setnames(dt , " Products_Pool" , " cProduct" )
634
632
}
635
633
636
634
if (variable == " fLuc" ) {
637
635
638
- dt <- openLPJOutputFile(run , " luflux" , target.sta , verbose , data.table.only = TRUE )
636
+ dt <- openLPJOutputFile(run , " luflux" , target.sta , file.name = file.name , verbose = verbose , data.table.only = TRUE )
639
637
target.cols <- append(getDimInfo(dt ), " Deforest_Flux" )
640
638
dt <- dt [,target.cols , with = FALSE ]
641
639
setnames(dt , " Deforest_Flux" , " fLuc" )
@@ -726,7 +724,7 @@ getStandardQuantity_LPJ <- function(run,
726
724
if (quant @ id == " vegcover_std" ) {
727
725
728
726
# vegcover.out provides the right quantity here (note this is not standard LPJ-GUESS)
729
- data.list <- openLPJOutputFile(run , lookupQuantity(" vegcover" , GUESS ), target.sta , verbose = verbose )
727
+ data.list <- openLPJOutputFile(run , lookupQuantity(" vegcover" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
730
728
731
729
# But we need to scale it to %
732
730
if (verbose ) message(" Multiplying fractional areal vegetation cover by 100 to get percentage areal cover" )
@@ -742,23 +740,23 @@ getStandardQuantity_LPJ <- function(run,
742
740
else if (quant @ id == " vegC_std" ) {
743
741
744
742
# cmass provides the right quantity here - so done
745
- this.Field <- openLPJOutputFile(run , lookupQuantity(" cmass" , GUESS ), target.sta , verbose = verbose )
743
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" cmass" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
746
744
747
745
}
748
746
749
747
# LAI_std
750
748
else if (quant @ id == " LAI_std" ) {
751
749
752
750
# lai provides the right quantity here - so done
753
- this.Field <- openLPJOutputFile(run , lookupQuantity(" lai" , GUESS ), target.sta , verbose = verbose )
751
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" lai" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
754
752
755
753
}
756
754
757
755
# FPAR_std
758
756
else if (quant @ id == " FPAR_std" ) {
759
757
760
758
# lai provides the right quantity here - so done
761
- this.Field <- openLPJOutputFile(run , lookupQuantity(" fpc" , GUESS ), target.sta , verbose = verbose )
759
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" fpc" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
762
760
all.layers <- layers(this.Field )
763
761
drop.layers <- all.layers [! all.layers %in% c(" Total" )]
764
762
this.Field @ data [, (drop.layers ) : = NULL ]
@@ -772,10 +770,10 @@ getStandardQuantity_LPJ <- function(run,
772
770
# in older version of LPJ-GUESS, the mgpp file must be aggregated to annual
773
771
# newer versions have the agpp output variable which has the per PFT version
774
772
if (file.exists(file.path(run @ dir , " agpp.out" )) || file.exists(file.path(run @ dir , " agpp.out.gz" ))){
775
- this.Field <- openLPJOutputFile(run , lookupQuantity(" agpp" , GUESS ), target.sta , verbose = verbose )
773
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" agpp" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
776
774
}
777
775
else {
778
- this.Field <- openLPJOutputFile(run , lookupQuantity(" mgpp" , GUESS ), target.sta , verbose = verbose )
776
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" mgpp" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
779
777
this.Field <- aggregateSubannual(this.Field , method = " sum" , target = " Year" )
780
778
}
781
779
@@ -789,10 +787,10 @@ getStandardQuantity_LPJ <- function(run,
789
787
# newer versions have the agpp output variable which has the per PFT version
790
788
791
789
if (file.exists(file.path(run @ dir , " anpp.out" )) || file.exists(file.path(run @ dir , " anpp.out.gz" ))){
792
- this.Field <- openLPJOutputFile(run , lookupQuantity(" anpp" , GUESS ), target.sta , verbose = verbose )
790
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" anpp" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
793
791
}
794
792
else {
795
- this.Field <- openLPJOutputFile(run , lookupQuantity(" mnpp" , GUESS ), target.sta , verbose = verbose )
793
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" mnpp" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
796
794
this.Field <- aggregateSubannual(this.Field , method = " sum" , target = " Year" )
797
795
}
798
796
@@ -801,7 +799,7 @@ getStandardQuantity_LPJ <- function(run,
801
799
# mNPP_std
802
800
else if (quant @ id == " aNEE_std" ) {
803
801
804
- this.Field <- openLPJOutputFile(run , lookupQuantity(" cflux" , GUESS ), target.sta , verbose = verbose )
802
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" cflux" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
805
803
806
804
# take NEE and ditch the rest
807
805
all.layers <- layers(this.Field )
@@ -814,7 +812,7 @@ getStandardQuantity_LPJ <- function(run,
814
812
else if (quant @ id == " canopyheight_std" ) {
815
813
816
814
# The canopyheight output fromth e benchmarkoutput output module is designed to be exactly this quantity
817
- this.Field <- openLPJOutputFile(run , lookupQuantity(" canopyheight" , GUESS ), target.sta , verbose = verbose )
815
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" canopyheight" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
818
816
renameLayers(this.Field , " CanHght" , " CanopyHeight" )
819
817
820
818
}
@@ -824,15 +822,15 @@ getStandardQuantity_LPJ <- function(run,
824
822
825
823
# if mfirefrac is present the open it and use it
826
824
if (" mfirefrac" %in% availableQuantities_GUESS(run , names = TRUE )){
827
- this.Field <- openLPJOutputFile(run , lookupQuantity(" mfirefrac" , GUESS ), target.sta , verbose = verbose )
825
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" mfirefrac" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
828
826
this.Field <- aggregateSubannual(this.Field , method = " sum" )
829
827
renameLayers(this.Field , " mfirefrac" , quant @ id )
830
828
831
829
}
832
830
833
831
# otherwise open firert to get GlobFIRM fire return interval and invert it
834
832
else {
835
- this.Field <- openLPJOutputFile(run , lookupQuantity(" firert" , GUESS ), target.sta , verbose = verbose )
833
+ this.Field <- openLPJOutputFile(run , lookupQuantity(" firert" , GUESS ), target.sta , file.name = file.name , verbose = verbose )
836
834
this.Field @ data [, " burntfraction_std" : = 1 / FireRT ]
837
835
this.Field @ data [, FireRT : = NULL ]
838
836
}
0 commit comments