source: LMDZ6/trunk/libf/phylmd/ecrad/practical/compare_output_profile.py @ 5322

Last change on this file since 5322 was 4773, checked in by idelkadi, 11 months ago
  • Update of Ecrad in LMDZ The same organization of the Ecrad offline version is retained in order to facilitate the updating of Ecrad in LMDZ and the comparison between online and offline results. version 1.6.1 of Ecrad (https://github.com/lguez/ecrad.git)
  • Implementation of the double call of Ecrad in LMDZ


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