@@ -633,6 +633,192 @@ end
633
633
634
634
635
635
636
+ """
637
+ plotforcingandstates(simulation::DiscretizedSPAC)
638
+
639
+ Plots the forcing, states and major fluxes as results of a SPAC Simulation.
640
+ """
641
+ @userplot PlotForcingAndStates
642
+ @recipe function f (plam:: PlotForcingAndStates )
643
+ # 0) parse input arguments
644
+ if length (plam. args) == 1
645
+ simulation = plam. args[1 ]
646
+ else
647
+ error (" plotforcingandstates requires an unnamed first argument of type DiscretizedSPAC. Other arguments to plot() should be separated by `;`." )
648
+ end
649
+ if ! (simulation isa DiscretizedSPAC)
650
+ error (" First unnamed argument to plotamounts should be of type DiscretizedSPAC. Got: $(typeof (simulation)) " )
651
+ end
652
+ if isnothing (simulation. ODESolution)
653
+ error (" plotamounts requires a solved system. Please `simulate!()` the DiscretizedSPAC first." )
654
+ end
655
+
656
+ # 1) prepare data to plot
657
+ sol = simulation. ODESolution;
658
+
659
+ # 1a) extract data from solution object `sol`
660
+ # 1a) i) forcing (wind, vappres, globrad, tmax, tmin, prec, lai, )
661
+ x1 = simulation. ODESolution_datetime;
662
+ y11 = simulation. ODESolution. prob. p. p_WIND .(simulation. ODESolution. t); lbl11 = " p_WIND [m/s]" ;
663
+ y12 = simulation. ODESolution. prob. p. p_VAPPRES .(simulation. ODESolution. t); lbl12 = " p_VAPPRES [kPa]" ;
664
+ y13 = simulation. ODESolution. prob. p. p_GLOBRAD .(simulation. ODESolution. t); lbl13 = " p_GLOBRAD [MJ/day/m2]"
665
+ y14 = hcat (simulation. ODESolution. prob. p. p_TMIN .(simulation. ODESolution. t),
666
+ simulation. ODESolution. prob. p. p_TMAX .(simulation. ODESolution. t)); lbl14 = [" p_TMIN [°C]" " p_TMAX [°C]" ]
667
+ y15 = simulation. ODESolution. prob. p. p_PREC .(simulation. ODESolution. t); lbl15 = " p_PREC [mm]"
668
+ # plot_forcing = plot(layout = (:,1),
669
+ # plot(x1, y11; labels = lbl11),
670
+ # plot(x1, y12; labels = lbl12),
671
+ # plot(x1, y13; labels = lbl13),
672
+ # plot(x1, y14; labels = lbl14),
673
+ # plot(x1, y15; labels = lbl15))
674
+
675
+ x2 = simulation. ODESolution_datetime;
676
+ y21 = hcat (simulation. ODESolution. prob. p. p_DENSEF .(simulation. ODESolution. t),
677
+ simulation. ODESolution. prob. p. p_SAI .(simulation. ODESolution. t),
678
+ simulation. ODESolution. prob. p. p_LAI .(simulation. ODESolution. t)); lbl21 = [" p_DENSEF [-]" " p_SAI [-]" " p_LAI [-]" ];
679
+ y22 = simulation. ODESolution. prob. p. p_HEIGHT .(simulation. ODESolution. t); lbl22 = " p_HEIGHT [-]" ;
680
+ # plot_vegetation = plot(layout = (2,1), title = "Vegetation",
681
+ # plot(x2, y21; labels = lbl21),
682
+ # plot(x2, y22;labels = lbl22))
683
+ # # plot!(twinx(),100*rand(10))
684
+ # # plot!(twinx(), simulation.ODESolution_datetime, simulation.ODESolution.prob.p.p_HEIGHT.(simulation.ODESolution.t))#;labels = "p_HEIGHT [-]")
685
+
686
+ # 1a) ii) states (scalar and vector)
687
+ (u_SWATI, u_aux_WETNES, u_aux_PSIM, u_aux_PSITI, u_aux_θ, p_fu_KK) = LWFBrook90. get_auxiliary_variables (simulation. ODESolution)
688
+
689
+ x3 = simulation. ODESolution_datetime;
690
+ y31 = hcat (reduce (hcat, [simulation. ODESolution (t). INTR. mm for t in simulation. ODESolution. t])' ,
691
+ reduce (hcat, [simulation. ODESolution (t). INTS. mm for t in simulation. ODESolution. t])' ,
692
+ reduce (hcat, [simulation. ODESolution (t). SNOW. mm for t in simulation. ODESolution. t])' ,
693
+ reduce (hcat, [simulation. ODESolution (t). SNOWLQ. mm for t in simulation. ODESolution. t])' ,
694
+ reduce (hcat, [simulation. ODESolution (t). XYLEM. mm for t in simulation. ODESolution. t])' );
695
+ lbl31 = [" INTR [mm]" " INTS [mm]" " SNOW [mm]" " SNOWLQ [mm]" " XYLEM [mm]" ];
696
+ y32 = hcat (sum (u_SWATI; dims= 1 )' ,
697
+ reduce (hcat, [simulation. ODESolution (t). GWAT. mm for t in simulation. ODESolution. t])' );
698
+ lbl32 = [" Total Soil Water [mm]" " GWAT [mm]" ];
699
+ # pl_states1 = plot(x3,
700
+ # # yaxis=:log, 1 .+
701
+ # y31; title = "Scalar states", labels = lbl31)
702
+ # pl_states2 = plot(x3, y32 = ; title = "Soil/ground water", labels = lbl32)
703
+ # plot_states = plot(pl_states1, pl_states2, layout = (2,1))
704
+
705
+ # 1a) iii) fluxes
706
+ x4 = simulation. ODESolution_datetime;
707
+ y41 = hcat ( reduce (hcat, [simulation. ODESolution (t). RWU. mmday for t in simulation. ODESolution. t])' ,
708
+ sum (reduce (hcat, [simulation. ODESolution (t). TRANI. mmday for t in simulation. ODESolution. t]); dims= 1 )' )
709
+ lbl41 = [" RWU (mm/day)" " sum(TRANI)" ]
710
+ # plot_fluxes = plot(x4, y41; labels = lbl41)
711
+
712
+ # plot(plot_forcing, plot_vegetation, plot_states, plot_fluxes,
713
+ # layout = grid(4, 1, heights=[0.5 ,0.2, 0.2, 0.1]),
714
+ # size=(800,2000), dpi = 300, leftmargin = 15mm)
715
+
716
+ # 2) set up the common arguments for all plots below
717
+ # lay = RecipesBase.grid(4, 1, heights=[0.5 ,0.2, 0.2, 0.1])
718
+ lay = RecipesBase. grid (10 , 1 )
719
+ layout --> lay
720
+ size --> (800 ,2000 )
721
+ dpi --> 300
722
+ # xlim --> xlimits
723
+ leftmargin --> 15 mm
724
+
725
+ # # 3) generate plots
726
+ # # NOTE: --> sets attributes only when they don't already exist
727
+ # # NOTE: := sets attributes even when they already exist
728
+ @series begin
729
+ yguide := " PREC [mm]"
730
+ # seriestype := :bar
731
+ # legend := false
732
+ subplot := 1
733
+ label := lbl11
734
+ # and other arguments:
735
+ x1, y11
736
+ end
737
+ @series begin
738
+ yguide := " PREC [mm]"
739
+ # seriestype := :bar
740
+ # legend := false
741
+ subplot := 2
742
+ label := lbl12
743
+ # and other arguments:
744
+ x1, y12
745
+ end
746
+ @series begin
747
+ yguide := " PREC [mm]"
748
+ # seriestype := :bar
749
+ # legend := false
750
+ subplot := 3
751
+ label := lbl13
752
+ # and other arguments:
753
+ x1, y13
754
+ end
755
+ @series begin
756
+ yguide := " PREC [mm]"
757
+ # seriestype := :bar
758
+ # legend := false
759
+ subplot := 4
760
+ label := lbl14
761
+ # and other arguments:
762
+ x1, y14
763
+ end
764
+ @series begin
765
+ yguide := " PREC [mm]"
766
+ # seriestype := :bar
767
+ # legend := false
768
+ subplot := 5
769
+ label := lbl15
770
+ # and other arguments:
771
+ x1, y15
772
+ end
773
+ @series begin
774
+ yguide := " PREC [mm]"
775
+ # seriestype := :bar
776
+ # legend := false
777
+ subplot := 6
778
+ label := lbl21
779
+ # and other arguments:
780
+ x2, y21
781
+ end
782
+ @series begin
783
+ yguide := " PREC [mm]"
784
+ # seriestype := :bar
785
+ # legend := false
786
+ subplot := 7
787
+ label := lbl22
788
+ # and other arguments:
789
+ x2, y22
790
+ end
791
+ @series begin
792
+ yguide := " PREC [mm]"
793
+ # seriestype := :bar
794
+ # legend := false
795
+ subplot := 8
796
+ label := lbl31
797
+ # and other arguments:
798
+ x3, y31
799
+ end
800
+ @series begin
801
+ yguide := " PREC [mm]"
802
+ # seriestype := :bar
803
+ # legend := false
804
+ subplot := 9
805
+ label := lbl32
806
+ # and other arguments:
807
+ x3, y32
808
+ end
809
+ @series begin
810
+ yguide := " PREC [mm]"
811
+ # seriestype := :bar
812
+ # legend := false
813
+ subplot := 10
814
+ label := lbl41
815
+ # and other arguments:
816
+ x4, y41
817
+ end
818
+ end
819
+
820
+
821
+
636
822
# #########################
637
823
# Functions to get values linked to soil domain:
638
824
0 commit comments