Creating Sections into different types of objects

Conventionally, we draw Section objects into a Cube. However, it is also possible to create Section objects into other objects, such as a Mask or Planform or any arbitrary array-like data.

First, let’s create a Section into a Cube and a basic Planform and compare.

golfcube = dm.sample_data.golf()
pl = dm.plan.Planform(golfcube, idx=-1)

css = dm.section.StrikeSection(golfcube, distance=1200)
pss = dm.section.StrikeSection(pl, distance=1200)

fig, ax = plt.subplots()
golfcube.quick_show('eta', idx=-1)
css.show_trace(ax=ax)
pss.show_trace('--', ax=ax)
plt.show()

(Source code, png, hires.png)

../../../_images/sections_into_arbitrary-1.png

Because the css section is underlain by a Cube, it returns variables with dimensions time x along section. Whereas, the pss section is underlain by a Planform at time index -1, it returns variables with dimensions along section.

If we plot the elevation returned from pss and the last time index of the css, we can see that the underlying data are the same!

fig, ax = plt.subplots()

ax.plot(css.s, css['eta'][-1, :])
ax.plot(pss.s, pss['eta'], '--')

plt.show()

(Source code, png, hires.png)

../../../_images/sections_into_arbitrary-2.png

Similarly to creating a Section into the Planform, we can use an underlying Mask.

EM = dm.mask.ElevationMask(
    golfcube["eta"][-1],
    elevation_threshold=0)
mss = dm.section.StrikeSection(EM, distance=1200)

ax.plot(mss.s, mss['mask'], ':')

plt.show()

(Source code, png, hires.png)

../../../_images/sections_into_arbitrary-3.png

Important

A common “gotcha” is forgetting that some Section types (e.g., CircularSection and RadialSection) will try to guess a useful origin during instantiation, by reading various attributes of an underlying DataCube. These attributes are not available during instantiation of a Section that reads into a Planform or Mask. This can lead to discrepencies in the locations of the Section objects!

In this example, the Section into the Planform is offset by L0, because this attribute is not known to the Planform.

ccs = dm.section.CircularSection(golfcube, radius=1000)
pcs = dm.section.CircularSection(pl, radius=1000)

(Source code, png, hires.png)

../../../_images/sections_into_arbitrary-4.png

Arbitrary data

You can also create a Section into any array-like data.

arr = np.random.uniform(size=(100, 200))
arrss = dm.section.StrikeSection(arr, distance_idx=30)

(Source code)

Note

There are no variable names associated with a single array, but you still need to specify an argument when slicing the section. You can use anything, but we suggest [None].

fig, ax = plt.subplots()
ax.plot(arrss[None])
plt.show()

(Source code, png, hires.png)

../../../_images/sections_into_arbitrary-6.png