Inspector plot#
The inspector plot takes in a three-dimensional input and applies a reduction operation (sum by default) along one of the dimensions specified by dim. It displays the result as a two-dimensional image.
In addition, the inspector tool
in the toolbar allows to add markers on the image, which generate one-dimensional slices (retaining only dim) that are displayed in a second figure.
The points can be dragged/moved, as well as deleted (via a middle click). Below is an example on how to create the inspector plot.
[1]:
%matplotlib widget
import plopp as pp
from plopp.data.examples import clusters3d
[2]:
da = clusters3d(nclusters=50, seed=12).hist(z=100, y=100, x=100)
p = pp.inspector(da, dim='z', orientation='vertical', logc=True)
[4]:
p
[4]:
Controls
Left-click to make new point
Left-click and drag existing point to move it
Middle-click to delete point
Rectangle mode#
Instead of using dots to select a single pixel in the 2D image, we can enable 'rectangle' mode to draw rectangles that select everything contained by them, using the
tool.
[5]:
p = pp.inspector(da, dim='z', orientation='vertical', logc=True, mode='rectangle')
[7]:
p
[7]:
Controls
Left-click to start drawing a new rectangle
Left-click again to persist the rectangle
Left-click and drag a vertex to resize the rectangle
Right-click and drag to move the entire rectangle
Middle-click to delete the rectangle
Polygon mode#
Finally, there is also a 'polygon'
mode:
[8]:
p = pp.inspector(da, dim='z', orientation='vertical', logc=True, mode='polygon')
[10]:
p
[10]:
Controls
Left-click to start drawing a new polygon
Left-click again to add more points
Left-click and drag a vertex to resize the polygon
Right-click and drag to move the entire polygon
Middle-click to delete the polygon
Disabling continuous updates#
For performance reasons, it is sometimes preferable to only update the target figure when we have stopped dragging or resizing one of the rectangles/polygons, instead of every step of the way.
This can be done using the continuous_update argument:
[11]:
p = pp.inspector(
da,
dim='z',
orientation='vertical',
logc=True,
mode='rectangle',
continuous_update=False,
)
[13]:
p
[13]:
Changing the reduction operation#
As mentioned above, the default operation applied along the third dimension is a sum. This can be changed via the operation argument (possible other choices are mean, min, and max, as well as their nan-prefixed counterparts).
They can be used when summing the data along the third dimension does not really make physical sense. For instance, below we load a dataset containing the air-temperature recorded above North-America for 2 years. Summing temperatures along the time dimension to create a map would be illogical, and a much better representation of the data would be to plot the average temperature at a given location, over the 2 years measured.
[14]:
from plopp.data.examples import air_temperature
air = air_temperature()
air
Downloading file 'air_temperature.h5' from 'https://public.esss.dk/groups/scipp/plopp/1/air_temperature.h5' to '/home/runner/.cache/plopp/1'.
[14]:
- time: 2920
- lat: 25
- lon: 53
- lat(lat)float32deg75.0, 72.5, ..., 17.5, 15.0
Values:
array([75. , 72.5, 70. , 67.5, 65. , 62.5, 60. , 57.5, 55. , 52.5, 50. , 47.5, 45. , 42.5, 40. , 37.5, 35. , 32.5, 30. , 27.5, 25. , 22.5, 20. , 17.5, 15. ], dtype=float32) - lon(lon)float32deg200.0, 202.5, ..., 327.5, 330.0
Values:
array([200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5, 225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5, 250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5, 275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5, 300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5, 325. , 327.5, 330. ], dtype=float32) - time(time)datetime64ns2013-01-01T00:00:00.000000000, 2013-01-01T06:00:00.000000000, ..., 2014-12-31T12:00:00.000000000, 2014-12-31T18:00:00.000000000
Values:
array(['2013-01-01T00:00:00.000000000', '2013-01-01T06:00:00.000000000', '2013-01-01T12:00:00.000000000', ..., '2014-12-31T06:00:00.000000000', '2014-12-31T12:00:00.000000000', '2014-12-31T18:00:00.000000000'], shape=(2920,), dtype='datetime64[ns]')
- (time, lat, lon)float64K241.200, 242.5, ..., 296.190, 295.690
Values:
array([[[241.2 , 242.5 , 243.5 , ..., 232.8 , 235.5 , 238.6 ], [243.8 , 244.5 , 244.7 , ..., 232.8 , 235.3 , 239.3 ], [250. , 249.8 , 248.89, ..., 233.2 , 236.39, 241.7 ], ..., [296.6 , 296.2 , 296.4 , ..., 295.4 , 295.1 , 294.7 ], [295.9 , 296.2 , 296.79, ..., 295.9 , 295.9 , 295.2 ], [296.29, 296.79, 297.1 , ..., 296.9 , 296.79, 296.6 ]], [[242.1 , 242.7 , 243.1 , ..., 232. , 233.6 , 235.8 ], [243.6 , 244.1 , 244.2 , ..., 231. , 232.5 , 235.7 ], [253.2 , 252.89, 252.1 , ..., 230.8 , 233.39, 238.5 ], ..., [296.4 , 295.9 , 296.2 , ..., 295.4 , 295.1 , 294.79], [296.2 , 296.7 , 296.79, ..., 295.6 , 295.5 , 295.1 ], [296.29, 297.2 , 297.4 , ..., 296.4 , 296.4 , 296.6 ]], [[242.3 , 242.2 , 242.3 , ..., 234.3 , 236.1 , 238.7 ], [244.6 , 244.39, 244. , ..., 230.3 , 232. , 235.7 ], [256.2 , 255.5 , 254.2 , ..., 231.2 , 233.2 , 238.2 ], ..., [295.6 , 295.4 , 295.4 , ..., 296.29, 295.29, 295. ], [296.2 , 296.5 , 296.29, ..., 296.4 , 296. , 295.6 ], [296.4 , 296.29, 296.4 , ..., 297. , 297. , 296.79]], ..., [[243.49, 242.99, 242.09, ..., 244.19, 244.49, 244.89], [249.09, 248.99, 248.59, ..., 240.59, 241.29, 242.69], [262.69, 262.19, 261.69, ..., 239.39, 241.69, 245.19], ..., [294.79, 295.29, 297.49, ..., 295.49, 295.39, 294.69], [296.79, 297.89, 298.29, ..., 295.49, 295.49, 294.79], [298.19, 299.19, 298.79, ..., 296.09, 295.79, 295.79]], [[245.79, 244.79, 243.49, ..., 243.29, 243.99, 244.79], [249.89, 249.29, 248.49, ..., 241.29, 242.49, 244.29], [262.39, 261.79, 261.29, ..., 240.49, 243.09, 246.89], ..., [293.69, 293.89, 295.39, ..., 295.09, 294.69, 294.29], [296.29, 297.19, 297.59, ..., 295.29, 295.09, 294.39], [297.79, 298.39, 298.49, ..., 295.69, 295.49, 295.19]], [[245.09, 244.29, 243.29, ..., 241.69, 241.49, 241.79], [249.89, 249.29, 248.39, ..., 239.59, 240.29, 241.69], [262.99, 262.19, 261.39, ..., 239.89, 242.59, 246.29], ..., [293.79, 293.69, 295.09, ..., 295.29, 295.09, 294.69], [296.09, 296.89, 297.19, ..., 295.69, 295.69, 295.19], [297.69, 298.09, 298.09, ..., 296.49, 296.19, 295.69]]], shape=(2920, 25, 53))
[15]:
inspect_air = pp.inspector(air, dim='time', orientation='vertical', operation='mean')
[17]:
inspect_air
[17]: