SalishSeaCast Web Page View Figure Metadata
This section discusses:
how to add figure metadata to the
salishsea_site.views.salishseacast
module to make a figure appear on a web pagehow to run a local instance of the
salishsea
website to confirm that the figure is on the web page
We’ll use the nowcast.figures.research.tracer_thalweg_and_surface
figure module as an example.
You should run your local salishsea
website server for testing in a Nowcast Figures Development Environment.
You can activate it with:
$ source activate nowcast-fig-dev
salishsea_site.views.salishseacast
Figure Metadata
The salishsea.eos.ubc.ca site web app gathers figures that have been rendered by the nowcast system make_plots
worker and presents them on web pages that are linked by date from the https://salishsea.eos.ubc.ca/nemo/results/ page.
Each row on the https://salishsea.eos.ubc.ca/nemo/results/ page contains links to pages that are generated from a page template by a view function in the salishsea_site.views.salishseacast
module.
Each view function uses a list of salishsea_site.views.salishseacast.FigureMetadata
objects that is also defined in the salishsea_site.views.salishseacast
module.
The FigureMetadata
objects set the title for the figure that will appear on the web page,
and the svg_name
of the figure files rendered by the make_plots
worker.
So,
to add a figure rendered from our nowcast.figures.research.tracer_thalweg_and_surface
figure module to the Biology page,
we add a FigureMetadata
object to the biology_figures
list in the salishsea_site.views.salishseacast
module:
FigureMetadata(
title='Nitrate Fields Along Thalweg and on Surface',
svg_name='nitrate_thalweg_and_surface',
)
The value of the title
attribute appears in Plots list on the page as a link to the figure lower down on the page,
and it appears as a heading above the figure image.
The value of the svg_name
attribute is key that we used to register our figure function module in the make_plots
worker.
Recall that the key is also used as the root part of the file name into which the figure is rendered.
That is:
We registered a call to the
nowcast.figures.research.tracer_thalweg_and_surface.make_figure()
function in thenowcast.workers.make_plots._prep_nowcast_green_research_fig_functions()
function using the keynitrate_thalweg_and_surface
to produce a nitrate thalweg and surface figureWhen the
make_plots
was run with the command-line optionsnowcast-green research --run-date 2017-04-29
it stored the rendered figure with the file namenitrate_thalweg_and_surface_29apr17.svg
The order of FigureMetadata
objects in the biology_figures
list determines the order in which the figures appear on the web page.
Testing the Website View
If you haven’t done so already, activate your Nowcast Figures Development Environment:
$ source activate nowcast-fig-dev\
Assuming that you have successfully run the
make_plots
worker in test mode for your figure, navigate to yourSalishSeaNowcast/
directory, set up the 2 environment variables that the nowcast system expects to find, create a temporary logging directory for it to use:(nowcast-fig-dev)$ export NOWCAST_LOGS=/tmp/$USER (nowcast-fig-dev)$ export NOWCAST_ENV=$CONDA_PREFIX (nowcast-fig-dev)$ mkdir -p $NOWCAST_LOGS
and run the
make_plots
worker to render the figures of the type that you are working on for a recent date (like yesterday). For our test of thenowcast.figures.research.tracer_thalweg_and_surface
figure module, the command would be like:(nowcast-fig-dev)$ python -m nowcast.workers.make_plots config/nowcast.yaml nowcast-green research --debug --run-date 2017-05-07
Navigate to your
salishsea-site/
directory, and launch the local website server with:(nowcast-fig-dev)$ cd salishsea-site/ (nowcast-fig-dev)$ pserve --reload development.ini
You should see output like:
Starting monitor for PID 10564. Starting server in PID 10564. serving on http://0.0.0.0:6543
but the PID number will be different. The web server is now running in this terminal session. You can stop it with Control-c when you are finished.
Use your browser to navigate to
http://localhost:6543/nemo/results/
. From there you should be able to navigate to the page that will show you the figures for the date that you ran themake_plots
worker for; for our test of thenowcast.figures.research.tracer_thalweg_and_surface
figure module, that would be the Biology page.If you need to edit the
FigureMetadata
for your figure, the web server will restart automatically when you save the file so that you can see your changes by refreshing the page in your browser.
Automatic Code Formatting
The salishsea_site package uses the`black`_ code formatting tool to maintain a coding style that is very close to PEP 8.
black is installed as part of the Nowcast Figures Development Environment setup.
Before each commit of the salishsea_site.views.salishseacast
module please run black to automatically format the code with the command:
$ black salishsea_site/views/salishseacast.py