[ncl-talk] Ship Track data dots for loop
Melissa Lazenby
M.Lazenby at sussex.ac.uk
Thu Jul 23 04:49:09 MDT 2015
Hi All
I am making images for animation software and I am just having a bit of trouble when it comes to plotting the ship track data which is in text format.
I have got 25 images that I loop through the wind data and I would like to overlay dots for the ship tracks. However the data for the ship tracks is not 25 time steps like for the wind it has more time steps. I would like to make if statements that say when the year is 1815 and the month is 4 then plot all those ship track points on images 1.
Then another if statement for month 5 etc etc.
Here is what the ship txt file looks like:
1815 4 20 10.00 -34.73 28.45 1022.8 48
1815 4 21 10.00 -36.02 25.60 1027.2 65
1815 4 22 10.00 -35.93 24.28 1036.3 54
1815 4 23 11.00 -36.30 22.35 1012.6 62
1815 4 24 11.00 -35.23 22.10 1016.0 52
1815 4 25 11.00 -35.45 21.85 1029.5 51
1815 4 28 11.00 -35.02 16.20 1021.7 56
1815 4 29 11.00 -32.88 13.12 1022.8 23
1815 4 30 11.00 -30.58 10.47 1029.5 0
1815 5 3 12.00 -26.67 6.35 1019.4 66
1815 5 6 12.00 -24.17 3.33 1019.4 43
1815 5 7 12.00 -22.98 2.93 1020.0 22
1815 6 17 8.00 -38.02 55.53 1022.8 85
1815 6 18 8.00 -37.30 59.02 1032.9 79
1815 6 19 8.00 -35.70 62.03 1026.1 52
1815 6 20 8.00 -35.36 63.95 1005.8 53
1815 6 21 8.00 -35.02 65.87 999.1 55
1815 6 22 7.00 -35.00 70.05 1009.5 50
1815 6 23 7.00 -34.93 73.55 1016.0 43
1815 6 24 7.00 -35.03 77.03 1016.0 57
1815 6 25 7.00 -34.87 81.20 1023.4 41
1815 6 26 6.00 -34.10 83.47 1023.4 43
1815 6 27 6.00 -33.83 84.08 1025.5 34
1815 6 28 6.00 -33.00 85.43 1026.1 35
1815 6 29 6.00 -34.30 86.13 1025.8 46
1815 6 30 6.00 -34.75 89.05 1026.1 49
1815 7 1 6.00 -34.55 90.93 1021.1 40
1815 7 2 6.00 -32.38 91.80 1014.3 21
1815 7 5 6.00 -25.43 95.43 1019.4 55
1815 7 6 6.00 -23.32 96.08 1019.4 36
1815 7 7 6.00 -22.87 96.60 1022.8 26
1815 7 9 5.00 -21.53 98.00 1016.0 18
1815 7 10 5.00 -19.28 100.53 1016.0 90
1815 7 11 5.00 -17.42 102.23 1016.0 72
1816 1 19 6.00 -18.55 85.42 1011.2 85
1816 1 20 6.00 -19.38 83.78 1012.6 93
1816 1 21 7.00 -20.60 81.12 1016.0 1
1816 1 22 7.00 -21.60 78.98 1016.0 18
1816 1 23 7.00 -23.08 75.97 1019.4 35
1816 1 26 7.00 -25.53 67.78 1016.0 57
1816 1 27 8.00 -25.98 65.50 1016.0 55
1816 1 28 8.00 -26.37 62.78 1016.0 62
1816 1 31 8.00 -28.17 53.28 1022.8 83
1816 2 1 9.00 -28.60 52.22 1014.6 82
1816 2 2 9.00 -28.37 51.38 1015.3 81
1816 2 3 9.00 -28.50 48.98 1015.3 88
1816 2 4 9.00 -29.28 46.07 1011.6 96
1816 2 5 9.00 -29.27 45.13 1005.8 95
1816 2 6 9.00 -28.83 44.02 1011.9 84
1816 2 7 5.00 -6.30 104.70 1016.0 64
1816 2 7 9.00 -29.42 41.40 1022.8 91
1816 2 8 5.00 -6.42 104.25 1016.0 64
1816 2 9 5.00 -7.47 103.83 1014.3 73
1816 2 9 10.00 -31.18 36.58 1019.4 16
1816 2 10 10.00 -31.37 35.78 1020.0 15
1816 2 11 5.00 -9.23 102.50 1012.6 92
1816 2 11 10.00 -32.53 33.80 1019.4 23
1816 2 12 5.00 -10.02 101.68 1009.2 1
1816 2 12 10.00 -34.20 31.33 1012.6 41
1816 2 13 5.00 -11.72 100.07 1009.2 10
1816 2 13 10.00 -35.00 28.07 1009.9 58
1816 2 14 5.00 -13.83 98.75 1009.2 38
1816 2 14 10.00 -34.57 25.33 1005.8 45
1816 2 15 6.00 -15.85 95.00 1012.6 55
1816 2 16 6.00 -17.30 92.08 1016.0 72
1816 2 16 11.00 -35.17 22.17 1016.0 52
1816 2 17 6.00 -18.25 89.42 1016.0 89
1816 2 17 11.00 -34.95 18.97 1007.9 48
1816 2 18 6.00 -19.32 87.12 1016.0 97
1816 2 18 11.00 -35.05 18.50 1009.2 58
1816 2 19 6.00 -20.22 84.30 1016.0 4
1816 2 19 11.00 -33.68 15.83 1013.3 35
1816 2 20 7.00 -20.95 81.68 1016.0 1
1816 2 20 11.00 -31.58 13.08 1012.6 13
1816 2 21 7.00 -21.90 78.97 1016.0 18
1816 2 21 11.00 -29.97 11.17 1009.2 91
1816 2 22 7.00 -23.08 75.33 1016.0 35
1816 2 22 11.00 -28.63 12.22 1007.5 82
1816 2 23 7.00 -24.08 71.75 1012.6 41
1816 2 24 7.00 -25.13 68.88 1010.6 58
1816 2 25 8.00 -25.27 65.58 1009.2 55
1816 2 25 12.00 -24.75 7.30 1016.0 47
1816 2 26 8.00 -27.12 62.87 1012.6 72
1816 2 26 12.00 -22.90 4.60 1016.0 24
1816 2 27 8.00 -27.38 61.52 1014.6 71
1816 2 27 12.00 -21.23 2.47 1016.0 12
1816 2 28 12.00 -19.85 0.58 1016.0 90
1816 2 29 8.00 -28.70 57.35 1010.9 87
1816 3 1 8.00 -29.15 55.50 1015.0 95
1816 3 2 9.00 -29.18 52.17 1014.6 92
1816 3 5 9.00 -31.28 42.78 1017.0 12
1816 3 6 9.00 -32.37 39.32 1026.1 29
1816 3 10 10.00 -35.00 26.83 1019.4 56
1816 3 11 11.00 -36.22 22.18 1012.6 62
1816 3 12 11.00 -35.83 20.57 1010.9 50
1816 3 13 11.00 -35.08 18.67 1014.6 58
1816 3 14 11.00 -33.47 15.57 1009.2 35
1816 3 15 11.00 -31.03 12.17 1009.2 12
1816 3 16 11.00 -29.17 9.55 1015.3 99
1816 3 17 11.00 -27.62 7.52 1014.6 77
1816 3 18 12.00 -26.33 5.82 1015.3 65
1816 3 19 12.00 -25.02 4.03 1015.0 54
1816 3 20 12.00 -24.43 3.30 1014.3 43
1816 3 21 12.00 -22.85 1.67 1014.3 21
1816 5 1 -99.99 7.95 77.57 1005.6 77
1816 5 2 -99.99 6.27 78.77 1007.9 68
1816 5 3 -99.99 5.48 80.23 1001.1 50
1816 5 4 -99.99 5.67 80.80 1007.2 50
1816 5 5 -99.99 6.13 81.92 1006.5 61
1816 5 6 -99.99 7.67 82.28 1006.2 72
1816 5 7 -99.99 8.58 81.92 1005.6 81
1816 5 8 -99.99 10.03 80.08 1006.6 0
1816 5 9 -99.99 11.01 80.50 1006.7 10
1816 5 10 -99.99 11.98 80.18 1005.0 10
1816 5 11 -99.99 12.11 80.43 1006.4 20
1816 5 12 -99.99 12.23 80.50 1001.0 20
1816 5 13 -99.99 14.30 80.80 1000.7 40
1816 5 14 -99.99 16.03 82.65 999.1 62
1816 5 15 -99.99 17.87 84.50 999.2 74
1816 6 29 12.00 -36.07 0.00 1026.8 60
1816 6 30 12.00 -36.85 3.57 1024.8 63
1816 7 1 12.00 -36.88 7.25 1020.0 67
1816 7 2 11.00 -36.88 9.23 1016.0 69
1816 7 3 11.00 -36.45 12.05 1016.0 62
1816 7 4 11.00 -36.65 14.20 1010.6 64
1816 7 5 11.00 -36.87 15.78 1015.3 65
1816 7 6 11.00 -38.03 17.52 1012.6 87
1816 7 7 11.00 -38.72 18.47 1005.8 88
1816 7 8 11.00 -38.53 21.28 1002.8 81
1816 7 9 10.00 -37.42 24.37 1009.2 74
1816 7 10 10.00 -36.60 27.10 1032.9 67
1816 7 11 10.00 -36.50 31.50 1015.3 61
1816 7 12 10.00 -36.30 35.00 1014.0 65
1816 7 13 10.00 -35.78 36.90 1019.4 56
1816 7 14 9.00 -36.43 41.18 1008.5 61
1816 7 15 9.00 -36.78 44.98 1012.6 64
1816 7 16 9.00 -37.00 49.20 1010.6 79
1816 7 17 8.00 -36.90 53.05 1009.2 63
1816 7 18 8.00 -37.10 57.08 1002.4 77
1816 7 19 8.00 -37.23 60.12 1032.9 70
1816 7 20 8.00 -37.18 62.97 1021.1 72
1816 7 21 8.00 -37.45 66.47 1021.1 76
1816 7 22 7.00 -37.55 71.00 1021.1 71
1816 7 23 7.00 -37.57 75.45 1016.0 75
1816 7 24 7.00 -37.52 79.45 1008.2 79
1816 7 25 6.00 -36.72 83.07 1011.9 63
1816 7 26 6.00 -35.83 87.72 1012.6 57
1816 7 27 6.00 -35.15 91.45 1009.9 51
1816 7 28 6.00 -33.42 94.82 1016.0 34
1816 7 29 5.00 -31.45 98.12 1010.2 18
1816 7 30 5.00 -28.68 100.77 1013.3 80
1816 7 31 5.00 -25.40 102.13 1019.4 52
1816 8 1 5.00 -22.87 102.87 1020.4 22
1816 8 2 5.00 -21.08 103.98 1019.4 13
1816 8 3 5.00 -18.00 104.98 1016.0 84
1816 8 4 5.00 -14.75 105.58 1016.0 45
1816 8 5 5.00 -11.52 105.62 1014.3 15
1816 8 6 5.00 -8.67 105.63 1016.0 85
1816 8 22 -99.99 15.65 90.37 999.8 50
1816 8 23 -99.99 14.92 91.77 1002.8 41
1816 8 24 -99.99 13.62 93.22 1004.1 33
1816 8 25 -99.99 12.67 94.38 1004.0 24
1816 8 27 -99.99 8.12 97.80 1007.3 87
1816 8 28 -99.99 6.47 97.60 1002.8 67
1816 8 30 -99.99 5.03 99.55 1007.9 59
1816 8 31 -99.99 4.50 99.85 1007.5 49
1816 9 2 -99.99 4.17 100.35 1007.2 40
1816 9 3 -99.99 3.50 100.58 1006.5 30
1816 9 4 -99.99 3.50 100.58 1006.5 30
1816 9 6 -99.99 2.17 102.22 1008.2 22
1816 9 8 -99.99 1.60 102.08 1009.2 12
1816 9 9 -99.99 2.27 103.55 1009.9 23
1816 9 11 -99.99 3.60 105.00 1007.9 35
1816 9 12 -99.99 5.13 105.78 1006.5 55
1816 9 13 -99.99 6.48 106.07 1005.9 66
1816 9 14 -99.99 8.85 107.90 1004.6 87
1816 9 16 -99.99 12.30 112.18 1003.7 22
1816 9 17 -99.99 14.17 113.62 1001.4 43
1816 9 18 -99.99 16.03 114.53 997.1 64
1816 9 19 -99.99 16.13 115.47 997.1 65
1816 9 20 -99.99 16.22 115.82 1000.1 65
1816 9 21 -99.99 16.75 116.02 1005.6 66
1816 9 22 -99.99 17.65 116.47 1004.6 76
1816 9 23 -99.99 18.52 116.75 1001.3 86
1816 9 24 -99.99 19.38 117.17 1004.4 97
1816 9 25 -99.99 19.92 115.85 1009.5 95
1816 9 26 -99.99 20.45 114.53 1013.2 4
1816 9 27 -99.99 20.70 113.22 1009.5 3
1816 12 4 -99.99 19.95 114.67 1018.9 94
1816 12 5 -99.99 16.67 112.07 1009.6 62
1816 12 7 -99.99 10.10 108.60 1010.0 8
1816 12 9 -99.99 5.11 104.83 1005.9 54
1816 12 10 -99.99 2.47 104.52 1006.5 24
1816 12 11 -99.99 2.48 103.80 1007.8 23
1816 12 14 -99.99 2.53 101.63 1006.5 21
1816 12 15 -99.99 2.70 101.30 1003.1 21
1816 12 16 -99.99 2.87 100.99 1006.2 20
1816 12 17 -99.99 3.70 100.68 1007.5 30
1816 12 18 -99.99 4.30 100.37 1008.2 40
1816 12 19 -99.99 4.75 100.25 1007.9 40
1816 12 20 -99.99 5.93 98.73 1008.6 58
1816 12 21 -99.99 6.55 96.15 1008.6 66
1816 12 23 -99.99 7.03 90.10 1009.9 70
1816 12 24 -99.99 6.70 86.72 1009.3 66
1816 12 25 -99.99 6.60 83.30 1009.3 63
1816 12 26 -99.99 5.78 80.75 1008.2 50
1816 12 27 -99.99 5.86 80.52 1007.2 50
1816 12 28 -99.99 5.94 80.28 1008.2 50
1816 12 30 -99.99 5.92 79.82 1009.2 59
1816 12 31 -99.99 5.95 79.97 1009.2 59
1817 1 1 -99.99 6.27 80.13 1008.9 60
1817 1 2 -99.99 6.95 79.02 1010.6 69
1817 2 9 -99.99 17.07 87.47 1012.7 77
1817 2 10 -99.99 16.90 87.05 1013.0 67
1817 2 11 -99.99 15.33 86.05 1014.6 56
1817 2 13 -99.99 12.00 84.22 1011.8 24
1817 2 14 -99.99 10.07 83.57 1011.7 3
1817 2 15 -99.99 9.13 82.72 1011.4 92
1817 2 16 -99.99 6.27 81.87 1008.9 61
1817 2 17 -99.99 6.16 80.98 1008.9 60
1817 2 18 -99.99 6.05 80.08 1007.9 60
1817 2 19 -99.99 6.10 79.17 1006.5 69
1817 2 20 -99.99 6.63 79.15 1008.6 69
1817 2 21 -99.99 6.65 79.13 1008.9 69
1817 2 22 -99.99 6.83 79.10 1007.6 69
1817 2 23 -99.99 7.47 78.20 1011.0 78
1817 2 24 -99.99 8.32 76.40 1010.7 86
1817 2 25 -99.99 8.48 76.72 1008.3 86
1817 2 26 -99.99 8.80 76.50 1009.0 86
1817 2 27 -99.99 9.42 76.24 1009.3 96
1817 2 28 -99.99 10.00 75.98 1010.7 5
1817 3 1 -99.99 10.28 75.78 1011.0 5
1817 3 2 -99.99 11.00 75.82 1010.4 15
1817 3 3 -99.99 11.33 75.85 1012.4 15
1817 3 4 -99.99 11.53 75.05 1010.1 15
1817 3 5 -99.99 11.62 74.78 1008.4 14
1817 3 6 -99.99 11.80 75.28 1009.4 15
1817 3 7 -99.99 12.10 75.28 1007.7 25
1817 3 8 -99.99 12.73 74.97 1008.4 24
1817 3 9 -99.99 12.97 74.83 1008.1 24
1817 3 10 -99.99 13.67 74.50 1011.5 34
1817 3 11 -99.99 14.17 74.26 1010.2 44
1817 3 12 -99.99 14.80 74.02 1008.2 44
1817 3 13 -99.99 15.17 73.78 1008.9 53
1817 3 14 -99.99 15.77 73.57 1009.2 53
1817 3 15 -99.99 16.43 73.35 1008.3 63
1817 3 16 -99.99 17.18 73.10 1009.7 73
1817 3 17 -99.99 17.78 72.94 1007.0 72
1817 3 18 -99.99 18.33 72.78 1009.0 82
1817 4 23 -99.99 17.47 72.90 1004.3 72
1817 4 24 -99.99 15.92 73.17 1006.9 53
1817 4 25 -99.99 14.88 73.82 1005.5 43
1817 4 27 -99.99 12.67 74.47 1008.8 24
1817 4 28 -99.99 11.58 75.35 1009.1 15
1817 4 29 -99.99 10.23 76.05 1009.0 6
1817 4 30 -99.99 9.95 76.45 1010.0 96
Many thanks in advance.
Kind Regards
Melissa
Here is the code:
;----------------------------------------------------------------------
; wind_vector_ship_tracks_1.ncl
;----------------------------------------------------------------------
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
begin
f=addfile("/mnt/geog/ml382/McGill_Project/ReanalysisV2/ua_1815-1817_ens_anim.nc", "r")
g=addfile("/mnt/geog/ml382/McGill_Project/ReanalysisV2/va_1815-1817_ens_anim.nc", "r")
latS = -70.
latN = 50.
lonL = 0.
lonR = 150.
u = f->ua(:,0,:,:)
v = g->va(:,0,:,:)
lat = f->lat
lon = f->lon
time = f->time
do gg = 0,dimsizes(time)-1
u_avg = dim_avg_n_Wrap(u,0) ;
v_avg = dim_avg_n_Wrap(v,0) ;
u_avg = u_avg/5
v_avg = v_avg/5
speed = sqrt(u(gg,:,:)^2+v(gg,:,:)^2)
speed!0 = "lat"
speed!1 = "lon"
speed&lat = lat
speed&lon = lon
speed at long_name = "Wind Speed"
speed at units = "m/s"
printVarSummary(u)
printVarSummary(v)
printVarSummary(speed)
wks = gsn_open_wks("X11","MtTambora_Animation_"+time(gg)+"") ; specifies a plot
;gsn_define_colormap(wks,"WhiteBlue") ; choose color map
plot = new (dimsizes(time),"graphic")
plot1= new (dimsizes(time),"graphic")
plot2= new (dimsizes(time),"graphic")
;---Create plot
res = True ; plot mods desired
res at cnFillOn = True ; turn on color for contours
res at cnLinesOn = False ; turn off contour lines
res at cnLineLabelsOn = False ; turn off contour line labels
res at gsnScalarContour = True ; contours desired
res at gsnDraw = False ; do not draw the plot
res at gsnFrame = False
res at vcRefMagnitudeF = 2.0 ; define vector ref mag
res at vcRefLengthF = 0.008 ; define length of vec ref
res at vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector
res at vcRefAnnoArrowLineColor = "black" ; change ref vector color
res at vcRefAnnoArrowUseVecColor = False ; don't use vec color for ref
res at vcLineArrowColor = "black" ; change vector color
res at vcLineArrowThicknessF = 2.0 ; change vector thickness
res at vcVectorDrawOrder = "PostDraw" ; draw vectors last
res at vcMinDistanceF = 0.02
res at gsnLeftString = ""
res at gsnMainString = ""
res at gsnRightString = ""
res at mpMinLonF = lonL ; select a subregion
res at mpMaxLonF = lonR
res at mpMinLatF = latS
res at mpMaxLatF = latN
pres = True
pres at mpFillOn = False
pres at cnFillOn = True ; color on
pres at cnLinesOn = False ; turn off contour lines
pres at gsnScalarContour = True ; vectors over contours
pres at gsnSpreadColors = True ; use full colormap
pres at gsnAddCyclic = False
pres at gsnDraw = False ; do not draw the plot
pres at gsnFrame = False
pres at lbLabelBarOn = False
pres at gsnMaximize = True
pres at mpMinLonF = lonL ; select a subregion
pres at mpMaxLonF = lonR
pres at mpMinLatF = latS
pres at mpMaxLatF = latN
pres at gsnLeftString = ""
pres at gsnMainString = ""
pres at gsnRightString = ""
pres at cnLevelSelectionMode= "ManualLevels" ; manual levels
pres at cnMinLevelValF = -100 ; min level
pres at cnMaxLevelValF = 120 ; max level
pres at cnLevelSpacingF = 10 ; contour spacing
mres = True
mres at gsMarkerIndex = 3 ; polymarker style
mres at gsMarkerSizeF = 20. ; polymarker size
mres at gsMarkerColor = "red"
mpres = True ; plot mods desired
mpres at xyMarkLineModes = "Markers" ; choose which have markers
mpres at xyMarkers = 16 ; choose type of marker
mpres at xyMarkerColor = "red" ; Marker color
mpres at xyMarkerSizeF = 0.01 ; Marker size (default 0.01)
;Ship track data
ship = "/mnt/geog/ml382/McGill_Project/ReanalysisV2/Ship_tracks_Scen2.txt"
data = asciiread(ship,-1,"string")
year = stringtofloat(str_get_cols(data, 1,5))
month = stringtofloat(str_get_cols(data,8,9))
day = stringtofloat(str_get_cols(data,11,13))
hour = stringtofloat(str_get_cols(data,15,20))
slat = stringtofloat(str_get_cols(data,22,28))
slon = stringtofloat(str_get_cols(data,31,37))
nrow = numAsciiRow("ship")
print(nrow)
print(slat)
print(slon)
print(month)
print(year)
print(data)
x=slon
y=slat
if (gg.eq.0) then
year=1815
month=4
polyres = True ; poly marker mods desired
polyres at gsMarkerIndex = 16 ; choose circle as polymarker
polyres at gsMarkerSizeF = 7.0 ; select size to avoid streaking
polyres at gsMarkerColor = "red" ; choose color
pres at gsnLeftString = "Mount Tambora Winds and Shipping Tracks "+time(gg)+""
plot(gg) = gsn_csm_contour_map(wks,speed(:,:),pres)
plot1(gg)= gsn_csm_vector(wks,u(gg,:,:),v(gg,:,:),res)
dum = gsn_add_polymarker(wks,plot(gg),x,y,polyres) ; draw polymarkers
overlay(plot(gg),plot1(gg))
;overlay(plot(gg),dum(gg))
draw(plot(gg))
end if
frame(wks)
end do
;end do
;end do
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150723/897debe5/attachment.html
More information about the ncl-talk
mailing list