-
Notifications
You must be signed in to change notification settings - Fork 0
/
trajplot_monthly.py
70 lines (48 loc) · 2.67 KB
/
trajplot_monthly.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset
from netCDF4 import date2index
from datetime import datetime
def traj_plot_monthly(state, month, seaice_, levels = ['780', '1000', '1400', '1850', '2850', '3950', '5220', '6730', '8600']):
"""Function to plot monthly clear or cloudy state plots with option of monthly seaice data.
Arguments: state, month, masked seaice, levels to be plotted as a list
levels = ['780', '1000', '1400', '1850', '2850', '3950', '5220', '6730', '8600'] """
# Extract seaice concentration value based on month
# Better to ask user to give the sea ice data with proper masking
path = 'H:/IUP/Student_job_AWI/Ollie_data/traj_sheba_sounding/winter_all/'
# checking for clear or cloudy
if (state == 'cloudy'):
dates_ = open('C:\\Users\\Mub\\Documents\\Python_AWI\\Avg_dates\\3havg_cloudy_' + month,'r').read().split('\n')
else:
dates_ = open('C:\\Users\\Mub\\Documents\\Python_AWI\\Avg_dates\\3havg_clear_' + month,'r').read().split('\n')
# specifying the levels or ask user to give levels as a list
#levels = ['780', '1000', '1400', '1850', '2850', '3950', '5220', '6730', '8600']
for lvl in levels:
#to loop over all levels
fig = plt.figure(figsize=(12,10))
# plt.figure(figsize=(10,8))
m = Basemap(projection='ortho', lat_0=80, lon_0=270, resolution='l')
m.fillcontinents(color='0.75')
m.drawparallels(np.arange(-80.,81.,20.), color='grey')
m.drawmeridians(np.arange(-180.,181.,20.))
m.pcolormesh(lon_ice, lat_ice, seaice_, latlon=True, cmap='Blues')
plt.clim(0, 100) # Set the color limits of the current image
plt.colorbar(label='Sea Ice Concentration')
# inner loop for plotting all the trajectories on one map
# read the monthly file
for line_ in dates_:
df = pd.read_csv(path+'tdump_'+lvl+'_'+line_, skiprows=7, header=None, delim_whitespace=True)
lat = np.array(df.iloc[:, 9].copy())
lon = np.array(df.iloc[:, 10].copy())
#Convert lat lon to map coordinates
x, y = m(lon, lat)
#Plot the points on the map
plt.plot(x, y,linewidth=1.0, color='red')
#source point
xpt, ypt = m(lon[-1], lat[-1])
plt.plot(xpt, ypt, marker = '*', markerfacecolor='red', markersize=8)
plt.title("Level: {} m AGL".format(lvl))
plt.savefig(path1+lvl+'_'+state+month+'_test_level.png')
plt.close(fig)