|
| 1 | +import cfplot as cfp |
| 2 | +import cf |
| 3 | + |
| 4 | +f = cf.read("~/recipes_break/new/POLCOMS_WAM_ZUV_01_16012006.nc") |
| 5 | +print(f) |
| 6 | + |
| 7 | +# Get separate vector components |
| 8 | +u = f[0] |
| 9 | +v = f[1] |
| 10 | +print(u) |
| 11 | +print(v) |
| 12 | + |
| 13 | +# First get rid of the ocean sigma coord size 1 axis |
| 14 | +u = u.squeeze() |
| 15 | +v = v.squeeze() |
| 16 | + |
| 17 | +# Now we need to use some means to condense the u and v fields in the same way into |
| 18 | +# having 1 time point, not 720 - for example we can just pick a time value out: |
| 19 | +chosen_time = "2006-01-16 00:00:00" |
| 20 | +v_1 = v.subspace(T=cf.dt(chosen_time)) |
| 21 | +u_1 = u.subspace(T=cf.dt(chosen_time)) |
| 22 | +v_1 = v_1.squeeze() |
| 23 | +u_1 = u_1.squeeze() |
| 24 | +print(u_1) |
| 25 | +print(v_1) |
| 26 | + |
| 27 | +# Are now in a plottable form! Let's give it a go: |
| 28 | +### cfp.vect(u=u_1, v=v_1) |
| 29 | +# Need to play around with the relative length and spacing of the vectors, using these paramters: |
| 30 | +###cfp.vect(u=u_1, v=v_1, key_length=10, scale=50, stride=2) |
| 31 | + |
| 32 | +# Note that there appear to be some really large vectors all pointing in the |
| 33 | +# same direction which are spamming the plot. We need to remove these. By |
| 34 | +# looking at the data we can see what these are and work out how to remove them: |
| 35 | +print(u.data) |
| 36 | +print(u[:10].data.array) |
| 37 | + |
| 38 | +# ... shows more of the array |
| 39 | + |
| 40 | +# Can see there are lots of -9999 values, seemingly used as a fill/placeholder value |
| 41 | +# so we need to remove those so we can plot the menaingful vectors |
| 42 | +# Apply steps to mask the -9999 fill values, which spam the plot, to x_1 |
| 43 | +u_2 = u_1.where(cf.lt(-9e+03), cf.masked) |
| 44 | +v_2 = v_1.where(cf.lt(-9e+03), cf.masked) |
| 45 | +print(u_2) |
| 46 | +print(v_2) |
| 47 | + |
| 48 | +# We can even plot the final field, effective wave height, as the |
| 49 | +# background contour! |
| 50 | +w = f[2] |
| 51 | +w_1 = w.subspace(T=cf.dt(chosen_time)) |
| 52 | +# This field also needs masking for those data points. |
| 53 | +w_2 = w_1.where(cf.lt(-9e+03), cf.masked) |
| 54 | +print(w_2) |
| 55 | +print(w_2, w_2[:10].data.array) |
| 56 | + |
| 57 | +# Our final basic plot: |
| 58 | +cfp.mapset(resolution="10m") # makes UK coastline more high-res |
| 59 | +cfp.gopen(file="irish-sea-currents.png") |
| 60 | +# BTW ignore the warnings below - they aren't relevant. |
| 61 | +cfp.vect(u=u_2, v=v_2, stride=2, scale=8, key_length=5) |
| 62 | +cfp.levs(min=-5, max=5, step=0.5) |
| 63 | +cfp.con(w_1, blockfill=True, lines=False) |
| 64 | +cfp.gclose() |
| 65 | + |
| 66 | +# Ideas for TODOs: |
| 67 | +# investigate difference days (do this by changing the 'T=cf.dt("2006-01-16 00:00:00")') datetime |
| 68 | +# values to different ones in the time coordinate data so you look at different days, or repace it |
| 69 | +# with a collapse over some stat e.g. mean to show the mean over all the times, |
| 70 | +# calculate divergence, calculate curl / relative voriticity, calculate absolute voriticity, |
| 71 | +# explore the other dataset as well (that covers other dates/times) - you could compare the |
| 72 | +# two to effectively compare the currents across different dates. |
0 commit comments