#! /bin/bash #+ # NAME: # sync_ips_daily # PURPOSE: # Controls the processing of new IPS data arriving from Nagoya. # CALLING SEQUENCE: # as cron job: # bash --login -c "sync_ips_daily" # # interactive: # sync_ips_daily [--with-correlations] # - gets new data from Nagoya site # - if no new data available # - only update all images # on the website (correlation graphs will only # be updated if --with-correlations is set) # - if new data are available # - run corotating tomography # - run time-depenent tomography # - update images on website (incl. correlations) # - update moview on website # # Several of the components can be run individually: # # sync_ips_daily --download-only # checks Nagoya site for new IPS data and downloads # if new IPS data are available # # sync_ips_daily --tomography # runs the tomography (both corotating and time-dependent, # and updates the all images (incl. correlations) and # movies on the IPS website # # sync_ips_daily --image-update [--with-correlations] # updates all images on the website. The correlations graphs # are updated only if --with-correlations is set too # # sync_ips_daily --movie-update # updates all movies on the website. # # INPUTS: # OPTIONAL INPUT PARAMETERS: # --tomography if set the script jumps straight to running # the tomography programs, bypassing the download # of new daily IPS files. # --download-only if set the script just runs the download script # and does not run the tomography programs # # --image-update only updates images on IPS website # (incl. correlation graphs if --with-correlations # is set. # --with-correlations # updates correlation graphs, if set in conjunction # with --image-updates # # --movie-update only updates movies on IPS website # # --dry-run a 'dry-run' currently will run the tomography # in $TUB, and suppress copying of images and html # files to the IPS website. # # We have available both NSO/NOAA and WSO/NOAA magnetic field data. # These are added to the processing by defining the env vars BB_PREFIXES, # BB_PREFIXES_SLOW and BB_PREFIXES_FAST. # To use the same magnetic data for both corotating and time-dependent # tomography used BB_PREFIXES: # BB_PREFIXES='wson' only WSO/NOAA data # BB_PREFIXES='nson' only NSO/NOAA data # BB_PREFIXES='wson nson' both WSO/NOAA and NSO/NOAA # To use different magnetic fields for corotating and time-dependent # tomography set the pair BB_PREFIXES_SLOW and BB_PREFIXES_FAST to the # desired magnetic data. # CALLS: # sync_ips_mirror, ipsd, ipsdt, vox_update # run_mean, run_marker # PROCEDURE: # Finally one or more tomography programs are called to update the # latest tomographic reconstructions. # # People on the honcho list receive several email notifications # when a part of the script completes. # Multiple email addresses need to be separated by a space. # # The IDL display software differentiates between corotating # and time-dependent tomography output files by checking the # 'marker' value. This value is coded in the filename, and is present # in the header under the key 'Rotation counter'. # # For a corotating file the marker value in the header MUST be zero; # and the marker is NOT encoded in the filename. # # For a time-dependent file the marker value identifies all files # associated with the same tomography run. It has a value of 1 or higher. # The marker is coded in the filename as a 5-digit integer. # MODIFICATION HISTORY: # JAN-2001, Paul Hick (UCSD/CASS) # SEP-2001, Paul Hick (UCSD/CASS) # Added honcho email list # AUG-2002, Paul Hick (UCSD/CASS) # Removed explicit calls to bash startup scripts # /etc/profile and ~/.bash_profile. # OCT-2002, Paul Hick (UCSD/CASS) # Rewrite of download section. Now uses Perl script 'mirror' # Also added the -tomography keyword. # OCT-2002, Paul Hick (UCSD/CASS) # The script does not abort anymore when the corotating tomography # fails, but continues with the time-dependent program. # All image updates are now done after both tomography programs # have been run. The intermediate update of the corotating images # prior to running the time-dependent tomography has been dropped. # JUN-2003, Paul Hick (UCSD/CASS) # Added calls to gzip to compress all nv3d*, etc., both raw # and final versions. # JUL-2003, Paul Hick (UCSD/CASS) # Removed call to 'idl run_map' # NOV-2003, Paul Hick (UCSD/CASS) # Removed compression of final files in this script using a single # gzip -f after the call to run_marker or run_mean. Instead this is now # done by the IDL procedure vu_write on a file by file basis. # The gzip -f call caused problems for the hourly forecast run while # run_marker was creating new final files. For some time the old # (gzipped) final files would coexist with the new (unzipped) final # files (until gzip -f was completed). An hourly forecast run during # this time would find multiple files referring to the same time. # The results are blank maps at the hourly forecast time. # AUG-2004, Paul Hick (UCSD/CASS) # Modified selection of magnetic field data by env variables. # APR-2011, John Clover (UCSD/CASS) # Modified to use ipstd20n_intel and output/process nv3h files. # APR-2013, Paul Hick (UCSD/CASS; pphick@ucsd.edu) # Substantial cleanup. More documentation. # Switched to long options. #- . tiny_bits.sh __CALLER__=`basename $0` __TIME_TAG__="%m/%d %H:%M" image_update () { # Update of all images and html files for IPS website local __CALLER__="image_update" # The egrep command makes spurious IDL messages go away if [ $WITH_CORRELATIONS -eq 0 ]; then export NOCORRELATION=1 fi idl -quiet run_map.pro 2>&1 | egrep -v " Compiled module:| Loaded DLM:| Program caused arithmetic error:" unset NOCORRELATION } movie_update () { # Update all the movies on the IPS website local __CALLER__="movie_update" # The egrep command makes spurious IDL messages go away idl -quiet run_movie.pro 2>&1 | egrep -v " Compiled module:| Loaded DLM:| Program caused arithmetic error:" # Remove all mng movies $RM -f $HTM/forecast/slow/current/*movie.mng $RM -f $HTM/forecast/fast/current/*movie.mng # === Create vox files ============== # DISABLED, PPH 2013-04 #if [ "$(date +%d)" == "1" ]; then # tiny_say "update vox files (slow)" # vox_update.py -source=$slow_final -destination=$slow_vox -nv_prefix=nv3d # # Final files are not produced anymore # tiny_say "update vox files (fast)" # vox_update.py -source=$fast_final -destination=$fast_vox -nv_prefix=nv3h #fi } align_nv_and_nson () { local __CALLER__="align_nv_and_nson" # If there are no nson files at all, then assume that # magnetic fields were not produced at all, so skip # the alignment. if [ `ls $PWD/nson* 2> /dev/null | egrep -v \.gz$ | wc -l` -eq 0 ]; then tiny_say "no uncompressed (new) nson files present" return 0 fi # Move unmatched nv3d files to subdirectory $slow_raw/ice # Delete unmatched nson files. local prefix local kind=$1 if [ $kind = "slow" ]; then prefix="nv3d" else prefix="nv3h" fi tiny_say "align $prefix and nson files in $PWD" local f local g ls $PWD/nson* 2> /dev/null | egrep -v \.gz$ | while read f; do # Loop over uncompressed (new) nson files #if [[ ! $f =~ \.gz ]]; then # Only check uncompressed (new) files g=`basename $f` g="$PWD/${g/nson/$prefix}" if [ ! -f $g ]; then # No matching nv3d file $RM $f # Remove nson file fi #fi done ls $PWD/$prefix* 2> /dev/null | egrep -v \.gz$ | while read f; do # Loop over nv3d files #if [[ ! $f =~ \.gz ]]; then # Skip gzipped files g=`basename $f` g="$PWD/${g/$prefix/nson}" if [ ! -f $g ]; then # No matching nson file tiny_warn "WARNING: removed $f: no matching nson file !!!" $RM $f # Remove nv3d file fi #fi done return 0 } compress_raw_files () { local __CALLER__="compress_raw_files" # Compress all new raw files for f in $PWD/*.*; do if [[ ! $f =~ \.gz$ ]]; then $GZIP $f fi done } fix_slow_raw_files () { # The new version of the corotating tomography creates # files in time-dependent format: # - the filename contains a 'marker' value of 1 # - the 'Rotation counter' in the header will be 1 # To make sure the IDL software treats these file as # corotating files the marker needs to be removed from the # the filename and the rotation counter needs to be set to zero. # THIS REALLY NEEDS TO BE FIXED IN THE TOMOGRAPHY PROGRAM ITSELF. local __CALLER__="remove_marker_from_filename" # The regex will skip gzipped files. Only uncompressed files, # presumably just created by the tomography, are processed. # The sed command will rewrite each file, setting the marker value # in the header to zero. # The mv command will rename the file, removing the marker. for f in `ls $PWD/*.*_*`; do if [[ $f =~ (.+)_[0-9]{5}$ ]]; then sed --in-place 's/; Rotation counter: 1/; Rotation counter: 0/' $f $MV $f ${BASH_REMATCH[1]} fi done } source_surface_update () { local __CALLER__="source_surface" mag_noaa.py --ftp --sync --obs=nso_ktpk 2>&1 | egrep -v " Compiled module:| Loaded DLM:| Program caused arithmetic error:| READFITS: EOF" } declare -A VALID_OPTIONS declare -A VALID_DESCRIPTION VALID_OPTIONS=( \ [-t,--tomography-only]=bool-TOMOGRAPHY_ONLY \ [-d,--download-only]=bool-DOWNLOAD_ONLY \ [-s,--source-surface-only]=bool-SOURCE_SURFACE_ONLY \ [-i,--image-update]=bool-IMAGE_UPDATE \ [-c,--with-correlations]=bool-WITH_CORRELATIONS \ [-m,--movie-update]=bool-MOVIE_UPDATE \ [--honcho]=HONCHO \ ) VALID_DESCRIPTION=( \ [-t,--tomography-only]="skip IPS download, and only run tomography" \ [-d,--download-only]="only download IPS data, do not run tomography" \ [-s,--source-surface-only]="only create magnetic source surface maps" \ [-i,--image-update]="updates images on IPS website" \ [-c,--with-correlations]="creates correlation images if used with --image-update" \ [-m,--movie-update]="updates movies on IPS website" \ [--honcho]="email address to receive completion notifications by email" \ ) . get_options.sh get_options $* unset get_options ((SILENT=2-$VERBOSE)) export SILENT # For IDL programs export DRYRUN CP="cp" MV="mv" RM="rm" GZIP="gzip -f" if [ $VERBOSE -ge 2 ]; then CP+=" -v" MV+=" -v" RM+=" -v" GZIP+=" -v" fi # --image-update set: update images, and exit if [ $IMAGE_UPDATE -eq 1 ]; then image_update # Create images for website exit 0 fi # --movie-update set: update movies, and exit if [ $MOVIE_UPDATE -eq 1 ]; then movie_update exit 0 fi if [ $SOURCE_SURFACE_ONLY -eq 1 ]; then source_surface_update exit 0 fi if [ $TOMOGRAPHY_ONLY -eq 0 ]; then # Check Nagoya website for new data. sync_ips_realtime $verbose $debug $dryrun $HONCHO exit_code=$? if [ $exit_code -eq 1 ]; then # Error in sync_ips_real_time tiny_die "tomography not run" fi if [ $DOWNLOAD_ONLY -eq 1 ]; then # Only download requested exit 0 fi # Suppress output from hourly image updates ((SILENT+=1)) export SILENT image_update # Create images for website ((SILENT-=1)) export SILENT if [ $exit_code -eq 2 ]; then # No new data; don't run tomography exit 0 fi fi # Run tomography using new IPS data start_time=$(date) # Set type of magnetic data. # The tomography needs source surface magnetic field data to calculate # the heliospheric magnetic field. # These files are created by XuePu hcss program from photospheric maps # downloaded from some remote site. # This process is controlled by cronjobs running the Python script # mag_noaa.py (which in turn calls XuePu's program from the IDL # wrapper xhcs.pro). # mag_wso_noaa="wso_noaa=wso_noaa[4]_[3]_[1].fts,$DAT,map,wso_noaa,hcss" mag_nso_noaa="nso_noaa=nso_ktpk[4]_[3].fts,$DAT,map,nso_ktpk,hcss" if [[ "$BB_PREFIXES $BB_PREFIXES_SLOW" =~ wson ]]; then mag_slow="$mag_slow $mag_wso_noaa" fi if [[ "$BB_PREFIXES $BB_PREFIXES_SLOW" =~ nson ]]; then mag_slow="$mag_slow $mag_nso_noaa" fi if [[ "$BB_PREFIXES $BB_PREFIXES_FAST" =~ wson ]]; then mag_fast="$mag_fast $mag_wso_noaa" fi if [[ "$BB_PREFIXES $BB_PREFIXES_FAST" =~ nson ]]; then mag_fast="$mag_fast $mag_nso_noaa" fi # === Initialization section ================= # Input for the tomography programs. # These files contain all the input parameters requested by the tomography # programs. They are fed to the program by piping them to standard input. #nagoya_slow=$SYS/nagoya/nagoya_forecast.slow-gonly nagoya_slow=$SYS/nagoya/nagoya_forecast.slow_10n_inp_mag #nagoya_fast=$SYS/nagoya/nagoya_forecast.fast_20n #nagoya_fast=$SYS/nagoya/nagoya_forecast.fast_20n_inp nagoya_fast=$SYS/nagoya/nagoya_forecast.fast_20n_inp_mag # The tomography program write output to the working directory. # These 'raw' files are written to directories slow/raw (for # corotating tomography) and fast/raw (for time-dependent tomography). # The raw files can be post-processed to create 'smoothed' final # files. The post-processing is done by IDL programs (run_mean.pro for # corotating tomography); run_marker.pro for time-dependent tomography). # These final files are written to directories slow/final and fast/final. # Currently only the final files for the corotating tomography are # created. The time-dependent tomography files are not smoothed anymore, # so the fast/final directory is not used anymore. slow_raw=$NAGOYA/slow/raw fast_raw=$NAGOYA/fast/raw slow_final=$NAGOYA/slow/final fast_final=$NAGOYA/fast/final slow_vox=$NAGOYA/slow/vox fast_vox=$NAGOYA/fast/vox # Check for magnetic field updates source_surface_update # === Run corotating tomography program ========= # The program takes its input from the file $nagoya_slow. # This starts the program in forecast mode. The modified Julian # reference time is left blank so the default calculated by # the tomography program is accepted. # The tomography program writes its output into the working # directory, so we cd to the directory where we want the output. # If an error occurs a message is output, but the script does not abort. savepwd=$PWD if [ $DRYRUN -eq 0 ]; then if [ -d $slow_raw/transit ]; then rm -rf $slow_raw/transit fi mkdir $slow_raw/transit cd $slow_raw/transit else cd $TUB fi tiny_yell "run co-rotating tomography in $PWD" tiny_yell "magnetic field used is '$mag_slow'" #ipsd $mag_slow < $nagoya_slow > $TUB/cron_ipsd.txt # When the magnetic field works at higher resolutions this can _10n (BVJ) # NOTE: the wildcard (*) after the celias filename is necessary!! # Without the wildcard the celias file name is not picked up by the tomography # program even though the file exists. If that bug gets fixed some day the # wildcard may need to be removed. ipstd_20n_inp_mag_intel ace=acesw_[4].hravg,$DAT/insitu/ celias=$DAT/insitu/realcelias/celias_realtime.hravg* $mag_slow < $nagoya_slow > $TUB/cron_ipsd.txt case $? in 1) status=finished ;; *) status=error ;; esac tiny_yell "corotating tomography $status" if [ -n "$HONCHO" ]; then date | mail -s "Corotating tomography $status" $HONCHO fi if [ $status = "finished" ]; then # Clean up the output from the tomography run in $slow_raw/transit if [ -n "$mag_slow" ]; then # in $PWD: sync plasma and magnetic files align_nv_and_nson slow fi fix_slow_raw_files # in $PWD: remove markers; fix headers compress_raw_files # in $PWD: compress files if [ $DRYRUN -eq 0 ]; then $MV $PWD/*.* $slow_raw # Move the clean output to $slow_raw cd $slow_raw rmdir $slow_raw/transit # Remove the transit directory fi # Produce the final smoothed files in directory $slow_final tiny_yell "creating final corotating tomography files (run_mean)" idl -quiet run_mean.pro 2>&1 | egrep -v " Compiled module:| Loaded DLM:| Program caused arithmetic error:" # Archive raw files (in $slow_raw) and final files (in $slow_final) # that are older than about one Carrington rotation into # subdirectories $slow_raw/ice and $slow_final/ice, respectively. idl -quiet -e "forecast_ice,'slow',silent=$SILENT" 2>&1 | egrep -v " Compiled module:| Loaded DLM:| Program caused arithmetic error:" fi # === Run time-dependent tomography program =========== # The tomography program writes its output into the working # directory, so we cd to the directory where we want the output. # If an error occurs a message is output, but the script does not abort. # Currently (2013-04) the nv3h files are created at 10 degree resolution, # while the nson files are created at 20 degree resolution. if [ $DRYRUN -eq 0 ]; then cd $fast_raw else cd $TUB fi tiny_yell "run time-dependent tomography in $PWD" tiny_yell "magnetic field used is '$mag_fast'" # NOTE: the wildcard (*) after the celias filename is necessary!! # Without the wildcard the celias file name is not picked up by the tomography # program even though the file exists. If that bug gets fixed some day the # wildcard may need to be removed. ipstd_20n_inp_mag_intel ace=acesw_[4].hravg,$DAT/insitu/ celias=$DAT/insitu/realcelias/celias_realtime.hravg* $mag_fast < $nagoya_fast > $TUB/cron_ipsdt.txt case $? in 1) status=finished ;; *) status=error ;; esac tiny_yell "time-dependent tomography $status" if [ -n "$HONCHO" ]; then date | mail -s "Time-dependent tomography $status" $HONCHO fi ## # removed by John Clover 08/29/2011 -- final files not used # # move negoya file, if it exists #mv negoya.2011 $NAGOYA/rtsources/nagoya.2011 #cp $DAT/nagoya/rtsources/nagoya.2011 $DAT/nagoya/rtsources/nagoya.2012 # at the beginning of the year 2013 put in place the following lines: #mv negoya.2012 $NAGOYA/rtsources/nagoya.2013 # for now negoya is 2012 only but if the tomo. program begins to output 2013 # the last mv below should override the previous command # WHAT IS THIS FOR? PPH 2013-04 $MV nggoya.2013 $NAGOYA/rtsources/nagoya.2013 $MV negoya.2013 $NAGOYA/rtsources/nagoya.2013 if [ $status = finished ]; then if [ -n "$mag_fast" ]; then # in $PWD: sync new plasma and magnetic files align_nv_and_nson fast fi compress_raw_files # in $PWD: gzip files #tiny_say "creating final time-dependent tomography files (run_marker)" #export NV_PREFIX="nv3h" #idl -quiet run_marker.pro #unset NV_PREFIX # Archive raw files (in $fast_raw) and final files (in $fast_final) # that are older than about one Carrington rotation into # subdirectories $fast_raw/ice and $fast_final/ice, respectively. idl -quiet -e "forecast_ice,'fast',silent=$SILENT" 2>&1 | egrep -v " Compiled module:| Loaded DLM:| Program caused arithmetic error:" fi cd $savepwd # === Create images and animations (daily) ============= WITH_CORRELATIONS=1 tiny_yell "update images for website" image_update # Create images for website tiny_yell "update movies for website" movie_update # Create movies for website if [ -n "$HONCHO" ]; then echo "Start at $start_time; Finished at $(date)" | mail -s"Nagoya IPS tomography finished" $HONCHO fi tiny_done "done"