Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global_time_series plot parameters to the cfg #399

Closed
forsyth2 opened this issue Feb 2, 2023 · 4 comments · Fixed by #400
Closed

Add global_time_series plot parameters to the cfg #399

forsyth2 opened this issue Feb 2, 2023 · 4 comments · Fixed by #400
Labels
semver: new feature New feature (will increment minor version)

Comments

@forsyth2
Copy link
Collaborator

forsyth2 commented Feb 2, 2023

#389 significantly streamlined the process to add plots. However, people wishing to add new plots will still need to create pull requests to edit zppy/templates/coupled_global.py; specifically they need to add their own specific plot function, such as the following, which gives values to each of the plot parameters.

# 1
def plot_net_toa_flux_restom(ax, xlim, exps):
    param_dict = {
        "2nd_var": False,
        "axhline_y": 0,
        "check_exp_ocean": False,
        "check_exp_vol": False,
        "check_exp_year": True,
        "default_ylim": [-1.5, 1.5],
        "do_add_line": True,
        "do_add_trend": True,
        "format": "%4.2f",
        "lw": 1.0,
        "ohc": False,
        "set_axhline": True,
        "set_legend": True,
        "shorten_year": False,
        "title": "Net TOA flux (restom)",
        "use_getmoc": False,
        "var": lambda exp: np.array(exp["annual"]["RESTOM"]),
        "verbose": False,
        "vol": False,
        "ylabel": "W m-2",
    }
    plot(ax, xlim, exps, param_dict)

If further changes are needed, they'll have to edit the plot function itself. However, presumably in most cases new plots will only require setting the above parameters accordingly. That could be done with the configuration file.

Note that it would significantly pollute the name space of zppy/templates/default.ini to include all these parameters in there. That said, e3sm_diags similarly includes many parameters that get passed on to the actual E3SM Diags package, so it wouldn't be unprecedented.

(I was thinking we could do something like #138 and have a global_time_series-specific cfg but it looks like that would have the same problem of a user needing to merge changes into the repository).

Complications:

  • It's not at all clear to me how a user could pass in these 20 parameters for 50 plots (as needed for Add BGC global mean analysis #365). The only way that comes to mind is to create 50 different subtasks of global_time_series, each setting these differently -- but then that would create 50 independent plots, not one PDF of all 50 plots. In the case of Add BGC global mean analysis #365, we're effectively talking about specifying 20*50=1,000 parameters.
  • Even if we figure out how to get all these parameters passed in without the user needing to actually modify the code... there's the problem of that lambda for "Var". The functions for "var" differ signficantly between plots and cannot simply be automated. https://github.com/E3SM-Project/zppy/blob/main/zppy/templates/coupled_global.py currently has:
"var": lambda exp: np.array(exp["annual"]["RESTOM"]),
"var": lambda exp: np.array(exp["annual"]["TREFHT"]) - 273.15,
"var": lambda exp: np.array(exp["annual"]["FSNTOA"]),
"var": lambda exp: np.array(exp["annual"]["RESTOM"])
"var": lambda exp: np.array(exp["annual"]["ohc"]),
"var": None,
"var": lambda exp: (
    1e3
    * np.array(exp["annual"]["volume"])
    / (4.0 * math.pi * (6371229.0) ** 2 * 0.7)
),
"var": lambda exp: (
    365
    * 86400
    * (
        np.array(exp["annual"]["QFLX"])
        - 1e3
        * (np.array(exp["annual"]["PRECC"]) + np.array(exp["annual"]["PRECL"]))
    )
),
  • Lastly, any significant changes we make to global_time_series now will make Make an independent package for Global Time Series #398 that much harder to implement -- and thus make it less likely global_time_series will ever be decoupled from zppy (perhaps that is not a major concern though).
@forsyth2
Copy link
Collaborator Author

forsyth2 commented Feb 2, 2023

@chengzhuzhang @BunnyVon @golaz @xylar You may have thoughts on the above; please let me know if so.

@forsyth2
Copy link
Collaborator Author

forsyth2 commented Feb 2, 2023

Frankly, I think this may be infeasible. The global time series plots were created ad-hoc and not at all standardized (though I tried my best to do so in #389). They are thus difficult to generalize.

I know E3SM Diags creates a large number of plot types for different variables, but my understanding is the plot structures are more or less standardized in a category. That said, looking at the lat-lon plots of https://web.lcrc.anl.gov/public/e3sm/zppy_test_resources/expected_complete_run/e3sm_diags/atm_monthly_180x360_aave/model_vs_obs_1850-1851/viewer/lat_lon/index.html I see the color bars differ between some of the plots; I suppose that would be an example of a structure change between plots. I may need to revisit how E3SM diags handles this -- @chengzhuzhang can you point me to the files where that is done, if possible? The colors aren't specified from the zppy level.

@forsyth2
Copy link
Collaborator Author

forsyth2 commented Feb 2, 2023

@chengzhuzhang did mention "For accommodating additional variables, I would suggest to create a striped down version of plot function that can work with any variables without customization."

I suppose that option would entail picking a "standard" setting for all of the above parameters, letting users pass in a global_time_series_vars list, and then looping over that list calling the standardized plot function each time. That would actually be a feasible option.

@forsyth2 forsyth2 added the semver: new feature New feature (will increment minor version) label Feb 3, 2023
@forsyth2
Copy link
Collaborator Author

forsyth2 commented Feb 3, 2023

I suppose that option would entail picking a "standard" setting for all of the above parameters, letting users pass in a global_time_series_vars list, and then looping over that list calling the standardized plot function each time. That would actually be a feasible option.

I got started on this option in #400 -- but there are still a number of obstacles to running successfully. See that pull request for further comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: new feature New feature (will increment minor version)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant