1- # Script to plot some global atmosphere and ocean time series
1+ # Script to generate global time series plots
2+ import csv
23import glob
34import math
45import os
@@ -1022,24 +1023,88 @@ def generate_viewer(self):
10221023 )
10231024
10241025
1025- def create_viewer (figstr , regions , component_to_plots_dict ):
1026+ class LandVariable (object ):
1027+ def __init__ (self , csv_row : List [str ]):
1028+ self .variable_name = csv_row [
1029+ 0
1030+ ] # the name of the ELM variable on the monthly h0 history file
1031+ self .metric = csv_row [
1032+ 1
1033+ ] # “A” or “T” for global average over land area or global total, respectively
1034+ self .scale_factor = csv_row [
1035+ 2
1036+ ] # the factor that should convert from original units to final units, after standard processing with nco
1037+ self .original_units = csv_row [
1038+ 3
1039+ ] # test string for the units as given on the history file (included here for possible testing)
1040+ self .final_units = csv_row [
1041+ 4
1042+ ] # the units that should be reported in time series plots, based on A/T and Scale Factor
1043+ self .group = csv_row [
1044+ 5
1045+ ] # a name used to cluster variables together, to be separated in groups within the output web pages
1046+ self .long_name = csv_row [
1047+ 6
1048+ ] # Descriptive text to add to the plot page to help users identify the variable
1049+
1050+
1051+ def construct_land_variables () -> List [LandVariable ]:
1052+ var_list : List [LandVariable ] = []
1053+ header = True
1054+ with open ("zppy_land_fields.csv" , newline = "" ) as csv_file :
1055+ var_reader = csv .reader (
1056+ csv_file ,
1057+ )
1058+ for row in var_reader :
1059+ # Skip the header row
1060+ if header :
1061+ header = False
1062+ else :
1063+ var_list .append (LandVariable (row ))
1064+ return var_list
1065+
1066+
1067+ class LandGroup (object ):
1068+ def __init__ (self , name : str , land_variables : List [LandVariable ]):
1069+ self .group_name = name
1070+ self .short_name = name .lower ().replace (" " , "" )
1071+ self .land_variables = land_variables
1072+
1073+
1074+ def get_land_groups (land_variables : List [LandVariable ]) -> List [LandGroup ]:
1075+ group_names : List [str ] = []
1076+ groups : List [LandGroup ] = []
1077+ for lv in land_variables :
1078+ g : str = lv .group
1079+ if g not in group_names :
1080+ # A new group!
1081+ groups .append (LandGroup (g , [lv ]))
1082+ else :
1083+ # Add a new variable to this existing group
1084+ for group in groups :
1085+ if g == group .group_name :
1086+ group .land_variables .append (lv )
1087+ return groups
1088+
1089+
1090+ def create_viewer (figstr , regions ):
10261091 # TODO: change to results dir
10271092 # Currently: https://web.lcrc.anl.gov/public/e3sm/diagnostic_output/ac.forsyth2/zppy_min_case_global_time_series_single_plots_www/test-601-output-viewer/v3.LR.historical_0051/global_time_series/global_time_series_1985-1995_results/viewer/
10281093 # just has css, js
10291094 viewer = OutputViewer (path = "." )
10301095 viewer .add_page ("Table" , regions )
1031- components = component_to_plots_dict .keys ()
1032- for component in components :
1033- viewer .add_group (component )
1034- plot_names = component_to_plots_dict [component ]
1096+ land_variables : List [LandVariable ] = construct_land_variables ()
1097+ groups : List [LandGroup ] = get_land_groups (land_variables )
1098+ for group in groups :
1099+ viewer .add_group (group .group_name )
1100+ plot_names = list (map (lambda lv : lv .variable_name , group .land_variables ))
10351101 for plot_name in plot_names :
10361102 viewer .add_row (plot_name )
10371103 for rgn in regions :
1038- component_short = component [0 :3 ]
10391104 viewer .add_col (
1040- f"{ figstr } _{ rgn } _{ component_short } _{ plot_name } .png" ,
1105+ f"{ figstr } _{ rgn } _{ group . short_name } _{ plot_name } .png" ,
10411106 is_file = True ,
1042- title = f"{ rgn } _{ component_short } _{ plot_name } " ,
1107+ title = f"{ rgn } _{ group . short_name } _{ plot_name } " ,
10431108 )
10441109
10451110 url = viewer .generate_page ()
@@ -1061,46 +1126,7 @@ def run_by_region(parameters):
10611126 raise RuntimeError (f"Invalid rgn={ rgn } " )
10621127 run (parameters , rgn )
10631128 figstr = parameters [3 ]
1064- # Going by zppy/templates/ilamb/ilamb.cfg
1065- component_to_plots_dict = {
1066- "atm" : ["TREFHT" ],
1067- "lnd > Ecosystem and Carbon Cycle > Biomass" : [
1068- "QVEGE" ,
1069- "QVEGT" ,
1070- "TOTVEGC" ,
1071- ], # biomass/cVeg
1072- "lnd > Ecosystem and Carbon Cycle > Gross Primary Productivity" : ["GPP" ], # gpp
1073- "lnd > Ecosystem and Carbon Cycle > Leaf Area Index" : [
1074- "LAISHA" ,
1075- "LAISUN" ,
1076- ], # lai
1077- "lnd > Ecosystem and Carbon Cycle > Global Net Ecosystem Carbon Balance" : [
1078- "NBP"
1079- ], # nbp
1080- "lnd > Ecosystem and Carbon Cycle > Soil Carbon" : [
1081- "QSOIL" ,
1082- "SOIL1C" ,
1083- "SOIL2C" ,
1084- "SOIL3C" ,
1085- "SOIL4C" ,
1086- ], # cSoil/soilc
1087- "lnd > Hyrdology Cycle > Runoff" : ["QRUNOFF" ], # runoff/mrro
1088- "lnd > Hyrdology Cycle > Sensible Heat" : ["FSH" ], # hfss/sh
1089- "lnd > Hyrdology Cycle > Terrestial Water Storage Anomaly" : ["TSA" ], # twsa/tws
1090- "lnd > Hyrdology Cycle > Snow Water Equivalent" : ["H2OSNO" ], # swe/snw
1091- "lnd > Forcings > Surface Relative Humidity" : ["RH2M" ], # rhums/hurs
1092- "lnd > Other" : [
1093- "QINTR" ,
1094- "QOVER" ,
1095- "SOILWATER_10CM" ,
1096- "TOTLITC" ,
1097- "CWDC" ,
1098- "WOOD_HARVESTC" ,
1099- "AR" ,
1100- "HR" ,
1101- ],
1102- }
1103- url = create_viewer (figstr , regions , component_to_plots_dict )
1129+ url = create_viewer (figstr , regions )
11041130 print (url )
11051131
11061132
0 commit comments