<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Plotting particle distributions with holoviews
Step1:  Background map
Make a background bathymetric map.
A simple land representation is given by colouring the land cells in the
ROMS file. Take the logarithm of the bathymetry to enhance topographic details
in the shallow North Sea.
Step3:  Particle plot function
Open the particle file and make a function to make a
Scatter element of the particle distribution at a given time step.
Step4:  Still images
Set a greyish colour on land and use shades of blue at sea. Show initial
and final particle distributions.
Step5:  Dynamic map
Make a DynamicMap of all the particle distributions.
<ASSISTANT_TASK:>
Python Code:
import numpy as np
from netCDF4 import Dataset
import holoviews as hv
from postladim import ParticleFile
hv.extension('bokeh')
Explanation: Plotting particle distributions with holoviews
End of explanation
# Read bathymetry and land mask
with Dataset('../data/ocean_avg_0014.nc') as ncid:
    H = ncid.variables['h'][:, :]
    M = ncid.variables['mask_rho'][:, :]
jmax, imax = M.shape
# Select sea and land features
H = np.where(M > 0, H, np.nan)  # valid at sea
M = np.where(M < 1, M, np.nan)  # valid on land
# Make land image
ds_land = hv.Dataset((np.arange(imax), np.arange(jmax), M), ['x', 'y'], 'Land mask')
im_land = ds_land.to(hv.Image, kdims=['x', 'y'], group='land')
# Make bathymetry image
ds_bathy = hv.Dataset((np.arange(imax), np.arange(jmax), -np.log10(H)),
                      ['x', 'y'], 'Bathymetry')
im_bathy = ds_bathy.to(hv.Image, kdims=['x', 'y'])
background = im_bathy * im_land
Explanation: Background map
Make a background bathymetric map.
A simple land representation is given by colouring the land cells in the
ROMS file. Take the logarithm of the bathymetry to enhance topographic details
in the shallow North Sea.
End of explanation
pf = ParticleFile('line.nc')
def pplot(timestep):
    Scatter plot of particle distibution at a given time step
    X, Y = pf.position(timestep)
    return background * hv.Scatter((X, Y))
Explanation: Particle plot function
Open the particle file and make a function to make a
Scatter element of the particle distribution at a given time step.
End of explanation
%%opts Image (cmap='blues_r' alpha=0.7) 
%%opts Image.land (cmap=['#AABBAA'])    
%%opts Scatter (color='red')
pplot(0) + pplot(pf.num_times-1)  # Final particle distribution
Explanation: Still images
Set a greyish colour on land and use shades of blue at sea. Show initial
and final particle distributions.
End of explanation
%%output size=150
%%opts Scatter (color='red')
dmap = hv.DynamicMap(pplot, kdims=['timestep'])
dmap.redim.range(timestep=(0, pf.num_times-1))
Explanation: Dynamic map
Make a DynamicMap of all the particle distributions.
End of explanation
<END_TASK>