|
| 1 | +import emsarray |
| 2 | +import shapely |
| 3 | +from emsarray import plot, transect |
| 4 | +from matplotlib import pyplot |
| 5 | + |
| 6 | +dataset_url = 'https://dapds00.nci.org.au/thredds/dodsC/fx3/model_data/gbr4_bgc_GBR4_H2p0_B2p0_Chyd_Dcrt.ncml' |
| 7 | +dataset = emsarray.open_dataset(dataset_url).isel(time=-1) |
| 8 | +dataset = dataset.ems.select_variables(['botz', 'temp']) |
| 9 | + |
| 10 | +line = shapely.LineString([ |
| 11 | + [152.9768944, -25.4827962], |
| 12 | + [152.9701996, -25.4420345], |
| 13 | + [152.9727745, -25.3967620], |
| 14 | + [152.9623032, -25.3517828], |
| 15 | + [152.9401588, -25.3103560], |
| 16 | + [152.9173279, -25.2538563], |
| 17 | + [152.8962135, -25.1942238], |
| 18 | + [152.8692627, -25.0706729], |
| 19 | + [152.8623962, -24.9698750], |
| 20 | + [152.8472900, -24.8415806], |
| 21 | + [152.8308105, -24.6470172], |
| 22 | + [152.7607727, -24.3521012], |
| 23 | + [152.6392365, -24.1906056], |
| 24 | + [152.4792480, -24.0615124], |
| 25 | +]) |
| 26 | +landmarks = [ |
| 27 | + ('Round Island', shapely.Point(152.9262543, -25.2878719)), |
| 28 | + ('Lady Elliot Island', shapely.Point(152.7145958, -24.1129146)), |
| 29 | +] |
| 30 | + |
| 31 | +# Plot the transect |
| 32 | +figure = transect.plot( |
| 33 | + dataset, line, dataset['temp'], |
| 34 | + figsize=(7.9, 3), |
| 35 | + bathymetry=dataset['botz'], |
| 36 | + landmarks=landmarks) |
| 37 | +figure.savefig('kgari-transect.png') |
| 38 | + |
| 39 | +# Plot the path of the transect |
| 40 | +figure = pyplot.figure(figsize=(5, 5), dpi=100) |
| 41 | +axes = figure.add_subplot(projection=dataset.ems.data_crs) |
| 42 | +axes.set_aspect(aspect='equal', adjustable='datalim') |
| 43 | +axes.set_title('Transect path') |
| 44 | +axes.add_collection(dataset.ems.make_poly_collection( |
| 45 | + dataset['botz'], cmap='Blues_r', edgecolor='face', |
| 46 | + linewidth=0.5, zorder=0)) |
| 47 | +plot.add_coast(axes, zorder=1) |
| 48 | +plot.add_gridlines(axes) |
| 49 | +plot.add_landmarks(axes, landmarks) |
| 50 | +axes = figure.axes[0] |
| 51 | +axes.set_extent(plot.bounds_to_extent(line.envelope.buffer(0.2).bounds)) |
| 52 | +axes.plot(*line.coords.xy, zorder=2) |
| 53 | +figure.savefig('kgari-path.png') |
| 54 | + |
| 55 | +pyplot.show(block=True) |
0 commit comments