Skip to content

Commit b72107c

Browse files
authored
Merge pull request #110 from csiro-coasts/transect
Add `emsarray.transect` module
2 parents 69fb788 + ed8efd6 commit b72107c

File tree

17 files changed

+940
-11
lines changed

17 files changed

+940
-11
lines changed

continuous-integration/environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ channels:
33

44
dependencies:
55
- geos ~=3.10.2
6+
- udunits2 >=2.2.25

continuous-integration/requirements.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ certifi==2023.7.22
2828
# pyproj
2929
# requests
3030
cftime==1.6.2
31-
# via netcdf4
31+
# via
32+
# cfunits
33+
# netcdf4
34+
cfunits==3.3.6
35+
# via emsarray (setup.cfg)
3236
chardet==5.2.0
3337
# via tox
3438
charset-normalizer==3.2.0
@@ -127,6 +131,7 @@ numpy==1.25.2
127131
# bottleneck
128132
# cartopy
129133
# cftime
134+
# cfunits
130135
# contourpy
131136
# dask
132137
# emsarray (setup.cfg)
@@ -142,6 +147,7 @@ packaging==23.1
142147
# via
143148
# bokeh
144149
# cartopy
150+
# cfunits
145151
# dask
146152
# distributed
147153
# emsarray (setup.cfg)

docs/_static/images/kgari-path.png

56.8 KB
Loading
27.5 KB
Loading

docs/api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ API reference
1919
utils.rst
2020
tutorial.rst
2121
plot.rst
22+
transect.rst
2223
types.rst
2324
exceptions.rst

docs/api/transect.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. module:: emsarray.transect
2+
3+
=================
4+
emsarray.transect
5+
=================
6+
7+
.. currentmodule:: emsarray.transect
8+
9+
Plot transects through your dataset.
10+
Transects are vertical slices along some path through your dataset.
11+
12+
Examples
13+
--------
14+
15+
.. list-table::
16+
17+
* - :ref:`example-kgari-transect`
18+
19+
.. image:: /_static/images/kgari-transect.png
20+
:width: 200
21+
:class: no-scaled-link
22+
23+
.. autofunction:: plot
24+
25+
.. autoclass:: Transect
26+
:members:
27+
28+
.. autoclass:: TransectPoint
29+
30+
.. autoclass:: TransectSegment
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,21 @@ To explore these notebooks interactively on the web you can launch a
1212
If you would prefer to download the examples and explore them locally,
1313
they are available on Github at
1414
`csiro-coasts/emsarray-notebooks <https://github.com/csiro-coasts/emsarray-notebooks>`_.
15+
16+
Gallery
17+
=======
18+
19+
.. toctree::
20+
:glob:
21+
:hidden:
22+
23+
*
24+
25+
.. list-table::
26+
27+
* - :ref:`example-kgari-transect`
28+
29+
.. image:: /_static/images/kgari-transect.png
30+
:width: 200
31+
:class: no-scaled-link
32+

docs/examples/kgari-transect.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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)

docs/examples/kgari-transect.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.. _example-kgari-transect:
2+
3+
====================
4+
K'gari transect plot
5+
====================
6+
7+
The following is a :mod:`transect <emsarray.transect>` path
8+
starting in the Great Sandy Strait near K'gari,
9+
heading roughly North out to deeper waters:
10+
11+
.. image:: /_static/images/kgari-path.png
12+
:alt: Transect of GBR1 dataset along Great Sandy Strait and past K'gari
13+
showing the water temperature.
14+
:align: center
15+
16+
The temperature along this transect can be plotted:
17+
18+
.. image:: /_static/images/kgari-transect.png
19+
:alt: Transect of GBR1 dataset along Great Sandy Strait and past K'gari
20+
showing the water temperature.
21+
22+
Code
23+
====
24+
25+
:download:`Download kgari-transect.py example <kgari-transect.py>`.
26+
27+
.. literalinclude:: kgari-transect.py
28+
:language: python
29+

docs/getting-started/installing.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,28 @@ You can install these by :ref:`choosing some extras at install time <extras>`.
3333
Dependencies
3434
============
3535

36-
``emsarray`` depends on
37-
`cartopy <https://scitools.org.uk/cartopy/docs/latest/installing.html>`_
38-
for plotting.
39-
This depends on the non-Python ``geos`` library.
36+
Most of the dependencies of ``emsarray`` are installable via pip,
37+
however some dependencies require non-Python components
38+
that must be installed using some other method.
39+
``emsarray`` uses the following libraries that can not be installed via pip:
40+
41+
* ``geos``, via
42+
`cartopy <https://scitools.org.uk/cartopy/docs/latest/installing.html>`_.
43+
This is used for plotting
44+
* ``udunits2``, via
45+
* `cfunits <https://ncas-cms.github.io/cfunits/installation.html>`.
46+
This is used for plotting.
4047

4148
These can be installed via your package manager or via ``conda``.
4249
Installing from ``conda`` is the recommended approach
4350
as these packages are often more up-to-date than the system packages
44-
and it guarantees that compatible versions of ``geos`` is installed.
51+
and it guarantees that compatible versions are installed.
4552

4653
.. code-block:: shell-session
4754
4855
$ conda create -n my-env
4956
$ conda activate my-env
50-
$ conda install cartopy
57+
$ conda install cartopy cfunits
5158
5259
If ``geos`` is installed using your system package manager,
5360
and ``cartopy`` is installed via pip,

0 commit comments

Comments
 (0)