def test_computable_mvars(self): # for debugging we draw the sparse_powerset_graph of the actually present computers and mvars spsg = sparse_powerset_graph(bgc_md2_computers()) f = plt.figure() ax = f.add_subplot(1, 1, 1) draw_ComputerSetMultiDiGraph_matplotlib(ax, spsg, bgc_md2_mvar_aliases(), bgc_md2_computer_aliases(), targetNode=frozenset( {SmoothModelRun})) f.savefig("spgs.pdf") fig = plt.figure() draw_update_sequence(bgc_md2_computers(), max_it=8, fig=fig) fig.savefig("c1.pdf") # https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests for mn in [ "Potter1993GlobalBiogeochemicalCycles", "testVectorFree", "Williams2005GCB", # just uncomment the one model you are working on and comment the others ]: with self.subTest(mn=mn): mvs = MVarSet.from_model_name(mn) mvars = mvs.computable_mvar_types() list_str = "\n".join( ["<li> " + str(var.__name__) + " </li>" for var in mvars]) print(list_str) for var in mvars: print("########################################") print(str(var.__name__)) print(mvs._get_single_mvar_value(var))
def test_from_model_name(self): # alternative constructor mvs= MVarSet.from_model_name("testVectorFree") res = frozenset( [ InFluxesBySymbol, OutFluxesBySymbol, InternalFluxesBySymbol, TimeSymbol, StateVariableTuple, ] ) self.assertSetEqual(mvs.provided_mvar_types, res)
def setUp(self): self.mn = "Williams2005GCB" self.mvs = MVarSet.from_model_name(self.mn) self.ref_provided_mvars = frozenset([ CompartmentalMatrix, TimeSymbol, StateVariableTuple, VegetationCarbonInputPartitioningTuple, VegetationCarbonInputScalar, InputTuple, NumericStartValueDict, NumericSimulationTimes, NumericParameterization, QuantityStartValueDict, QuantitySimulationTimes, QuantityParameterization, BibInfo, # QuantityModelRun, # QuantityParameterizedModel ])
def setUp(self): self.mn = "Castanho2013Biogeosciences" self.mvs = MVarSet.from_model_name(self.mn) self.ref_provided_mvars = frozenset([ CompartmentalMatrix, TimeSymbol, StateVariableTuple, VegetationCarbonInputPartitioningTuple, VegetationCarbonInputScalar, VegetationCarbonStateVariableTuple, InputTuple, # # NumericStartValueDict, # # NumericSimulationTimes, # NumericParameterization, # # QuantityStartValueDict, # # QuantitySimulationTimes, # # QuantityParameterization, # BibInfo, # # QuantityModelRun, # # QuantityParameterizedModel ])
def setUp(self): # self.mn = "" self.mn = "ElMasri2013AgricForMeteorol" # self.mn = "Pavlick2013Biogeosciences" # self.mn = "Hilbert1991AnnBot" # self.mn = "Foley1996GBC" # self.mn = "Gu2010EcologicalComplexity" # self.mn = "Arora2005GCB-1" # self.mn = "King1993TreePhysiol" # self.mn = "Murty2000EcolModell" # self.mn = "Wang2010Biogeosciences" # self.mn = "DeAngelis2012TheorEcol" # self.mn = "Comins1993EA" # self.mn = "Running1988EcolModel" # self.mn = "Luo2012TE" self.mvs = MVarSet.from_model_name(self.mn) self.ref_provided_mvars = frozenset( [ CompartmentalMatrix, TimeSymbol, StateVariableTuple, VegetationCarbonInputPartitioningTuple, VegetationCarbonInputScalar, VegetationCarbonStateVariableTuple, InputTuple, # # NumericStartValueDict, # # NumericSimulationTimes, # NumericParameterization, # # QuantityStartValueDict, # # QuantitySimulationTimes, # # QuantityParameterization, # BibInfo, # # QuantityModelRun, # # QuantityParameterizedModel ] )
# "ElMasri2013AgricForMeteorol", #Paper shows results for soil carbon, and fig. 1 has litter and C pools, but the equations on table A2 (although very detailed) don't include them. There are also equations for Phenology, but they were not included in the source.py # "Scheiter2009GlobalChangeBiol", #No soil compartments # "Turgman2018EcologyLetters", #No soil compartments # "Haverd2016Biogeosciences", #No soil compartments # "Foley1996GBC", #No equations for litter and soil, but the figure has those compartments. See Markus’ Ibis.yaml? # "Gu2010EcologicalComplexity", #No equations for litter and soil, but the model description (CEVSA) mentions them # "King1993TreePhysiol", #No soil compartments # "DeAngelis2012TheorEcol", #No soil compartments (model based on G’Day, but removed litter and soil compartments) # "Potter1993GlobalBiogeochemicalCycles", #No equations for litter and soil, but the model description mentions them # "testVectorFree", # "Williams2005GCB", "CARDAMOM", ] ###################################################################### ####### MODELS NOT TRANSLATED FROM .YAML TO SOURCE.PY # Sitch2003GlobChangBiol: Not included because allocation (see pg 8) has no ODEs; biomass increment is allocated to the tissue pools while satisfying the functional balance difference equations... # VanDerWerf1993PlantSoil: this model has no compartment for wood. It is used to simulate effect of nitrogen on growth of a grass (Dactylis glomerata L.). # ICBM: same as Andren1997EA but less parameter sets # Schimel2003SoilBiologyandBiochemistry.yaml, Schimel2003SoilBiologyandBiochemistry_rMM.yaml, Schimel2003SoilBiologyandBiochemistry_rMM_improved.yaml: Original model has no outputs, corrected by Holger # Ibis: includes soil, no metadata -added by Markus. Vero’s version: Foley ###################################################################### for mn in model_names: mvs = MVarSet.from_model_name(mn) mvars = mvs.computable_mvar_types() list_str = "\n".join(["<li> " + str(var.__name__) + " </li>" for var in mvars]) print(list_str) for var in mvars: print("########################################") print(str(var.__name__)) print(mvs._get_single_mvar_value(var))
def setUp(self): self.mn = "cable_all" self.mvs = MVarSet.from_model_name(self.mn)
# text_representation: # extension: .py # format_name: light # format_version: '1.5' # jupytext_version: 1.10.2 # kernelspec: # display_name: Python 3 # language: python # name: python3 # --- from IPython.display import HTML from bgc_md2.resolve.mvars import CompartmentalMatrix, StateVariableTuple, VegetationCarbonInputPartitioningTuple,VegetationCarbonInputTuple from bgc_md2.resolve.MVarSet import MVarSet display(HTML("<style>.container { width:100% !important; }</style>")) mvs_mm = MVarSet.from_model_name('TECOmm') import igraph g=igraph.Graph(directed=True) in_fluxes, internal_fluxes, out_fluxes = mvs_mm.get_InFluxesBySymbol(),mvs_mm.get_InternalFluxesBySymbol(),mvs_mm.get_OutFluxesBySymbol() in_flux_targets, out_flux_sources = [[str(k) for k in d.keys()] for d in (in_fluxes, out_fluxes)] internal_connections = [(str(s),str(t)) for s,t in internal_fluxes.keys()] # + G=igraph.Graph(directed=True) for i,s in enumerate(mvs_mm.get_StateVariableTuple()): G.add_vertex(str(s))# the name attribute is set automatically
{ VegetationCarbonInputPartitioningTuple, NumericSolutionArray } ), # explicit_exclude_models=frozenset({'CARDAMOM'}) ) li # From these we chose two models to investigate more thoroughly. # We load the first one with a helper function and the second by using standard python tools. # # mvs_Luo = MVarSet.from_model_name('Luo2012TE') # or using a moduel import from bgc_md2.models.TECO.source import mvs as mvs_TECO # # ComputabilityGraphs # Now that we actually have two records (MVarSets) we can exlore what we can comptute from them. # Just add a dot "." behind the variable in the next cell and press the tab key! # mvs_TECO # The options provided by the python interpreter are actually the result of a graph computation. # To see all computable mvars of the TECO MVarSet execute the next cell! # mvs_TECO.computable_mvar_names