source: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/practical/plot_output_profile.py @ 4999

Last change on this file since 4999 was 4728, checked in by idelkadi, 11 months ago

Update of ecrad in the LMDZ_ECRad branch of LMDZ:

  • version 1.6.1 of ecrad
  • files are no longer grouped in the same ecrad directory.
  • the structure of ecrad offline is preserved to facilitate updating in LMDZ
  • cfg.bld modified to take into account the new added subdirectories.
  • the interface routines and those added in ecrad are moved to the phylmd directory
  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/env python3
2import os
3import warnings
4import seaborn as sns
5from ecradplot import plot as eplt
6
7def warn(*args, **kwargs):
8    pass
9
10warnings.warn = warn
11
12
13def format_latitude(latitude):
14    if latitude<0:
15        return f"{abs(latitude):.0f}S"
16
17    return f"{abs(latitude):.0f}N"
18
19def main(latitude, input_srcfile, output_srcfiles, dstdir):
20    """
21    Plot input files
22    """
23
24    if not os.path.isdir(dstdir):
25        os.makedirs(dstdir)
26
27    name_string  = os.path.splitext(os.path.basename(input_srcfile))[0]
28    outputs_string = "_".join([os.path.splitext(os.path.basename(f))[0] for f in output_srcfiles])
29
30    styles = [{'lw':3, 'color':'k', 'ls':'-', 'zorder':10},
31              #{'lw':4, 'color':'0.5', 'ls':'-'},
32              #{'lw':4, 'color':'0.75', 'ls':'-'},
33              {'lw':5, 'color':sns.color_palette()[0], 'ls':'-'},
34              {'lw':5, 'color':sns.color_palette()[2], 'ls':'-'},
35              {'lw':3, 'color':sns.color_palette()[3], 'ls':'--'},
36              {'lw':3, 'color':sns.color_palette()[5], 'ls':'-.'},
37              {'lw':5, 'color':sns.color_palette()[6], 'ls':'-'},
38              {'lw':5, 'color':sns.color_palette()[9], 'ls':'-'}]
39
40
41    dstfile = os.path.join(
42        dstdir,
43        f"{name_string}_{outputs_string}_profile_{format_latitude(latitude)}.png"
44    )
45    print(f"Plotting output profiles to {dstfile}")
46    eplt.plot_output_profile(latitude, input_srcfile, output_srcfiles, styles, dstfile=dstfile)
47
48if __name__ == "__main__":
49    import argparse
50    parser = argparse.ArgumentParser(
51        description="Plot radiative fluxes and heating rates from ecRAD output file. \
52                    If a reference file is given, plot differences with respect to the reference."
53    )
54    parser.add_argument("latitude",  help="Latitude at which to extract profiles", type=float)
55    parser.add_argument("input",     help="ecRAD input file")
56    parser.add_argument("outputs",   help="ecRAD output files", nargs='+')
57    parser.add_argument("--dstdir",  help="Destination directory for plots", default="./")
58    args = parser.parse_args()
59
60    main(args.latitude, args.input, args.outputs, args.dstdir)
Note: See TracBrowser for help on using the repository browser.