import numpy as np import holoviews as hv hv.extension('bokeh') %opts Curve Area [width=600] def fm_modulation(f_carrier=110, f_mod=110, mod_index=1, length=0.1, sampleRate=3000): x = np.arange(0, length, 1.0/sampleRate) y = np.sin(2*np.pi*f_carrier*x + mod_index*np.sin(2*np.pi*f_mod*x)) return hv.Curve((x, y), kdims=['Time'], vdims=['Amplitude']) fm_modulation() carrier_frequencies = [10, 20, 110, 220, 330] modulation_frequencies = [110, 220, 330] hmap = hv.HoloMap({(fc, fm): fm_modulation(fc, fm) for fc in carrier_frequencies for fm in modulation_frequencies}, kdims=['fc', 'fm']) hmap # Exercise: Try changing the function below to return an ``Area`` or ``Scatter`` element, # in the same way `fm_modulation` returned a ``Curve`` element. def fm_modulation2(f_carrier=220, f_mod=110, mod_index=1, length=0.1, sampleRate=3000): x = np.arange(0,length, 1.0/sampleRate) y = np.sin(2*np.pi*f_carrier*x + mod_index*np.sin(2*np.pi*f_mod*x)) # Then declare a HoloMap like above and assign it to a ``exercise_hmap`` variable and display that %%opts Curve (color='red') dmap = hv.DynamicMap(fm_modulation, kdims=['f_carrier', 'f_mod', 'mod_index']) dmap = dmap.redim.range(f_carrier=((10, 110)), f_mod=(10, 110), mod_index=(0.1, 2)) dmap # Exercise: Declare a DynamicMap using the function from the previous exercise and name it ``exercise_dmap`` # Exercise (Optional): Use the ``.redim.step`` method and a floating point range to modify the slider step %%opts Curve [width=150] hv.GridSpace(hmap).opts() # Exercise: Try casting your ``exercise_hmap`` HoloMap from the first exercise to an ``NdLayout`` or # ``NdOverlay``, guessing from the name what the resulting organization will be before testing it. hmap.overlay('fm') %%opts Curve [width=150] dmap.redim.values(f_mod=[10, 20, 30], f_carrier=[10, 20, 30]).overlay('f_mod').grid('f_carrier').opts() # Exercise: Facet the ``exercise_dmap`` DynamicMap using ``.overlay`` and ``.grid`` # Hint: Use the .redim.values method to set discrete values for ``f_mod`` and ``f_carrier`` dimensions %%opts Curve [width=300] hmap[10, 110] + hmap[10, 200:].overlay() + hmap[[10, 110], 110].overlay() (hmap.select(fc=10, fm=110) + hmap.select(fc=10, fm=(200, None)).overlay() + hmap.select(fc=[10, 110], fm=110).overlay()) # Exercise: Try selecting two carrier frequencies and two modulation frequencies on the ``exercise_hmap``