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

Develop minimization plots #85

Merged
merged 13 commits into from
Nov 15, 2021
Merged
34 changes: 22 additions & 12 deletions LAMDA/minimization_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__all__ = ['plot_minimization']


def _plot_cost_function(df, outdir):
def _plot_cost_function(df, config, outdir):
"""
Use data from dataframe to plot the cost function.
"""
Expand Down Expand Up @@ -48,18 +48,22 @@ def _plot_cost_function(df, outdir):
myplot.add_ylabel('log (J)')
myplot.add_legend(loc='upper right',
fontsize='large')
myplot.add_title('FV3LAM Cost', loc='left')

title = f"{config['experiment']} Cost - {config['tm']}"
myplot.add_title(title, loc='left')
myplot.add_title(cyclestr, loc='right',
fontweight='semibold')

fig = myplot.return_figure()

plt.savefig(outdir + f"{cyclestr}_cost_function.png",
bbox_inches='tight', pad_inches=0.1)
savefile = (f"{cyclestr}_{config['experiment']}_" +
f"tm0{config['tm']}_cost_function.png")
plt.savefig(outdir + savefile, bbox_inches='tight',
pad_inches=0.1)
plt.close('all')


def _plot_gnorm(df, outdir):
def _plot_gnorm(df, config, outdir):
"""
Use date from dataframe to plot gnorm.
"""
Expand Down Expand Up @@ -97,32 +101,38 @@ def _plot_gnorm(df, outdir):
myplot.draw_data([gnorm, avg_gnorm])
# myplot.set_yscale('log')
myplot.add_grid()
myplot.set_xlim(0, len(j)-1)
myplot.set_xlim(0, len(gJ)-1)
myplot.add_xlabel('Iterations')
myplot.add_ylabel('log (gnorm)')
myplot.add_legend(loc='upper right',
fontsize='large')
myplot.add_title('FV3LAM gnorm', loc='left')

title = f"{config['experiment']} gnorm - {config['tm']}"
myplot.add_title(title, loc='left')
myplot.add_title(cyclestr, loc='right',
fontweight='semibold')

fig = myplot.return_figure()

plt.savefig(outdir + f"{cyclestr}_gnorm.png",
bbox_inches='tight', pad_inches=0.1)
savefile = (f"{cyclestr}_{config['experiment']}_" +
f"tm0{config['tm']}_gnorm.png")
plt.savefig(outdir + savefile, bbox_inches='tight',
pad_inches=0.1)
plt.close('all')


def plot_minimization(df, outdir):
def plot_minimization(df, plotting_config, outdir):
"""
Plot minimization plots including gnorm and cost function
and save them to outdir.

Args:
df : (pandas dataframe) dataframe with appropriate information
from GSI Stat file
plotting_config : (dict) dictionary with information about
minimization period
outdir : (str) path to output diagnostics
"""

_plot_gnorm(df, outdir)
_plot_cost_function(df, outdir)
_plot_gnorm(df, plotting_config, outdir)
_plot_cost_function(df, plotting_config, outdir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird no end of line thing here again like what happens sometimes

8 changes: 7 additions & 1 deletion LAMDA/scripts/LAMDA_stats_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ def create_minimization_plots(data_dict, outdir):
# Concatenate all files into one dataframe
fits2_df = concatenate_dfs(fits2_data, 'cost', cycles,
data_type='cost')

# Get plotting information
plotting_config = {}
plotting_config['tm'] = tm
current_file = fits2_data[-1].split('/')[-1]
plotting_config['experiment'] = current_file.split('.')[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this return? Ideally experiment would be a YAML defined thing I think.


# Create plot by calling plotting script
minimization_plots(fits2_df, outdir)
minimization_plots(fits2_df, plotting_config outdir)


def stats_workflow(config_yaml, nprocs, outdir):
Expand Down