| 1 | #!/usr/bin/env python3 |
|---|
| 2 | import os |
|---|
| 3 | import warnings |
|---|
| 4 | import seaborn as sns |
|---|
| 5 | from ecradplot import plot as eplt |
|---|
| 6 | |
|---|
| 7 | def warn(*args, **kwargs): |
|---|
| 8 | pass |
|---|
| 9 | |
|---|
| 10 | warnings.warn = warn |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | def format_latitude(latitude): |
|---|
| 14 | if latitude<0: |
|---|
| 15 | return f"{abs(latitude):.0f}S" |
|---|
| 16 | |
|---|
| 17 | return f"{abs(latitude):.0f}N" |
|---|
| 18 | |
|---|
| 19 | def 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 | |
|---|
| 48 | if __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) |
|---|