|
| 1 | +import logging |
| 2 | +import pathlib |
| 3 | + |
| 4 | +import matplotlib |
| 5 | +import pytest |
| 6 | +import shapely |
| 7 | + |
| 8 | +import emsarray.transect |
| 9 | + |
| 10 | +logger = logging.getLogger(__name__) |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.matplotlib(mock_coast=True) |
| 14 | +@pytest.mark.tutorial |
| 15 | +def test_plot( |
| 16 | + datasets: pathlib.Path, |
| 17 | + tmp_path: pathlib.Path, |
| 18 | +): |
| 19 | + dataset = emsarray.tutorial.open_dataset('gbr4') |
| 20 | + temp = dataset['temp'].copy() |
| 21 | + temp = temp.isel(time=-1) |
| 22 | + |
| 23 | + line = shapely.LineString([ |
| 24 | + [152.9768944, -25.4827962], |
| 25 | + [152.9701996, -25.4420345], |
| 26 | + [152.9727745, -25.3967620], |
| 27 | + [152.9623032, -25.3517828], |
| 28 | + [152.9401588, -25.3103560], |
| 29 | + [152.9173279, -25.2538563], |
| 30 | + [152.8962135, -25.1942238], |
| 31 | + [152.8692627, -25.0706729], |
| 32 | + [152.8623962, -24.9698750], |
| 33 | + [152.8472900, -24.8415806], |
| 34 | + [152.8308105, -24.6470172], |
| 35 | + [152.7607727, -24.3521012], |
| 36 | + [152.6392365, -24.1906056], |
| 37 | + [152.4792480, -24.0615124], |
| 38 | + ]) |
| 39 | + emsarray.transect.plot( |
| 40 | + dataset, line, temp, |
| 41 | + bathymetry=dataset['botz']) |
| 42 | + |
| 43 | + figure = matplotlib.pyplot.gcf() |
| 44 | + axes = figure.axes[0] |
| 45 | + # This is assembled from the variable long_name and the time coordinate |
| 46 | + assert axes.get_title() == 'Temperature\n2022-05-11T14:00' |
| 47 | + # This is the long_name of the depth coordinate |
| 48 | + assert axes.get_ylabel() == 'Z coordinate' |
| 49 | + # This is made up |
| 50 | + assert axes.get_xlabel() == 'Distance along transect' |
| 51 | + |
| 52 | + colorbar = figure.axes[-1] |
| 53 | + # This is the variable units |
| 54 | + assert colorbar.get_ylabel() == 'degrees C' |
| 55 | + |
| 56 | + matplotlib.pyplot.savefig(tmp_path / 'plot.png') |
| 57 | + logger.info("Saved plot to %r", tmp_path / 'plot.png') |
0 commit comments