[ncl-talk] solved/ activate the NCL environment from within a shell script

Sam McClatchie smcclatchie at fishocean.info
Fri Jan 8 18:26:45 MST 2021


Colleagues

Thank you to both Rick Brownrigg and Gus Corea for your help with this 
problem. Although your specific solutions did not work for me, they gave 
me clues about how to solve the problem. Here is a summary.

Task:

I want to execute a shell script once per day using a cron job. The 
shell script downloads the latest GHRSST data from NOAA ERDDAP using R, 
and then plots maps from the data using NCL.

Problem:

The shell script failed when NCL was called because the conda 
environment ncl_stable was not set up properly.

Solution:

Use conda execute to create a virtual environment for the script to run 
in. See <https://pelson.github.io/2015/conda_execute/>. As written on 
this web page, you need to install conda execute first. Then you add a 
few lines of conda execute metadata to the shell script:

#!/bin/bash
# conda execute
# env:
#  - ncl_stable

When you call the NCL script be sure to provide the path to NCL e.g.

/home/smcc/anaconda3/envs/ncl_stable/bin/ncl 
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand.ncl

The shell script can now be called from crontab, e.g.:

58 13 * * * 
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/shell/download_latest_GHRSST_data_from_ERDdap.sh

-------------------------------

My shell script looks like this:

#!/bin/bash

# conda execute
# env:
#  - ncl_stable

## download_latest_GHRSST_data_from_ERDdap.sh

# Use crontab -e to edit the cron file
# (see https://linux4one.com/how-to-set-cron-jobs-on-ubuntu-18-04/)
# use cronitor to troubleshoot cron file
# (see https://cronitor.io/cron-reference/cron-troubleshooting-guide).
# Try $ cronitor select to test run

########################################
# download the latest GHRSST data from erddap
########################################
Rscript 
"/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/R/download_GHRSST_MUR-JPL-L4-GLOB-v4.1_daily.R"

########################################
# plot GHRSST data
########################################

/home/smcc/anaconda3/envs/ncl_stable/bin/ncl 
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand.ncl

/home/smcc/anaconda3/envs/ncl_stable/bin/ncl 
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand_bigeye.ncl

/home/smcc/anaconda3/envs/ncl_stable/bin/ncl 
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand_bluefin.ncl

/home/smcc/anaconda3/envs/ncl_stable/bin/ncl 
/mnt/data/dynamic_data/projects/projects2020/recreational_fishing_GHRSST/ncl/plot_daily_GHRSST-MUR-JPL-L4-GLOB-v4_1_around_New_Zealand_yellowfin.ncl

-----------------------------------

And here are some of the plots:

http://u.pc.cd/K62rtalK

http://u.pc.cd/AbRrtalK

--------------------------------

Best fishes for New Year, and thanks!

Sam


-- 
email signature Sam McClatchie (fisheries oceanographer)
& Elena Turin (accounting & auditing)
FishOcean Enterprises www.fishocean.info <http://www.fishocean.info>
38 Upland Rd, Huia, Auckland 0604, New Zealand
cell: 027 752 8495


“The three great elemental sounds in nature are the sound of rain,
the sound of wind in a primeval wood, and the sound of outer ocean on a 
beach.
I have heard them all, and of the three elemental voices,
that of ocean is the most awesome, beautiful and varied.”

― Henry Beston, The Outermost House: A Year of Life on the Great Beach 
of Cape Cod
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210109/890ffe85/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SamMcClatchie2_small.jpg
Type: image/jpeg
Size: 45362 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210109/890ffe85/attachment.jpg>


More information about the ncl-talk mailing list