source: trunk/UTIL/visu_start_dynamico.py @ 3618

Last change on this file since 3618 was 3617, checked in by afalco, 4 days ago

dynamico: example of file to visualize start and startfi variables.
AF

File size: 1.5 KB
Line 
1import xarray as xr
2import matplotlib.pyplot as plt
3import numpy as np
4
5
6def plot_var(xx, yy, var2d, cmap='magma', extend='both', label='', title='', output="dynamico_plot.png"):
7    plt.figure(figsize=(5.5, 5))
8    plt.subplots_adjust(left=0.01, bottom=0.01, right=0.96, top=0.94)
9    plt.tricontourf(xx, yy, var2d, cmap=cmap)
10    plt.colorbar(extend=extend, label=label, pad=0.01)
11    plt.title(title, size=14)
12    plt.savefig(output)
13
14filename_start = 'start.nc'
15filename_startfi = 'startfi.nc'
16
17def open_file(filename="start.nc", file_type="start"):
18   file = xr.open_dataset(filename)
19   # lon lat names
20   if file_type == 'startphy':
21      lon_name, lat_name = 'longitude', 'latitude'
22   elif file_type == 'start':
23      lon_name, lat_name = 'lon_mesh', 'lat_mesh'
24   elif file_type == 'hist':
25      lon_name, lat_name = 'lon', 'lat'
26   else:
27      raise 'ERROR: file_type must be start or startphy or hist'
28   return file, lon_name, lat_name
29
30file_start, lon_start, lat_start = open_file(filename_start, "start")
31file_startfi, lon_startfi, lat_startfi = open_file(filename_startfi, "startphy")
32
33var_name = 'ps'
34title = 'Surface Pressure'
35unit = "kg/kg"
36plot_var(file_start[lon_start], file_start[lat_start], file_start[var_name], label=unit, title=title, output=f"start_{var_name}.png")
37
38var_name = 'n2'
39title = 'N2 surf'
40unit = "kg/kg"
41plot_var(file_startfi[lon_startfi], file_startfi[lat_startfi], file_startfi[var_name], label=unit, title=title, output=f"startfi_{var_name}.png")
42
Note: See TracBrowser for help on using the repository browser.