Commit a541230f authored by Carl Schreck's avatar Carl Schreck

Made a second bsub multi for the final plots.

parent ff36cab8
""" Kick off the cluster jobs to make monitoring maps for custom periods in
month."""
__author__ = "Carl Schreck"
__email__ = "carl_schreck@ncsu.edu"
__copyright__ = "Copyright 2020, North Carolina State University"
__license__ = "BSD-3.0"
import numpy as np
import os
import argparse
import subprocess
from datetime import datetime
import glob
import calendar
import cjs # '~carl/lib/python'
# These are some parameters that could be useful to have up top
parser = argparse.ArgumentParser()
parser.add_argument('--year', default=(datetime.today().year))
parser.add_argument('--month', default=(datetime.today().month - 1))
parser.add_argument('--dpi', default=200)
args = parser.parse_args()
year = int(args.year)
month = int(args.month)
dpi = int(args.dpi)
if month < 1:
month += 12
year -= 1
first_days = np.array([1, 7, 12, 19, 28])
days_in_month = calendar.monthrange(year, month)[1]
clobber = False
var_names = ['z500', 'prcp', 'tavg']
last_days = first_days[1:] - 1
last_days = np.append(last_days, days_in_month)
first_days = np.append(first_days, 1)
last_days = np.append(last_days, days_in_month)
cjs.tstamp('Here we go!')
fig_dir = f'figures/final/'
os.makedirs(fig_dir, exist_ok=True)
old_files = glob.glob(f'{fig_dir}/*')
for file in old_files:
os.remove(file)
for var_name in var_names:
cjs.tstamp(f'Downloading {var_name}')
if var_name == 'z500':
file_name = f'hgt.{year}.nc'
in_path = f'{os.environ["DATA_DIR"]}/ncep1/esrl/daily/{file_name}'
ftp_path = (
f'ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.dailyavgs/'
f'pressure/{file_name}')
download_err = cjs.download_file(ftp_path, in_path, clobber=False)
else:
file_type = 'scaled'
file_name = f'{var_name}-{year}{month:02}-grd-{file_type}.nc'
in_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/{var_name}/' \
f'{file_name}'
ftp_path = (
f'ftp://ftp.ncdc.noaa.gov/pub/data/daily-grids/beta/by-month/'
f'{year}/{month:02}/{file_name}')
web_path = (
f'https://www1.ncdc.noaa.gov/pub/data/daily-grids/beta/by-month/'
f'{year}/{month:02}/{file_name}')
download_err = cjs.download_file(ftp_path, in_path, clobber=False)
if download_err:
file_type = 'prelim'
file_name = f'{var_name}-{year}{month:02}-grd-{file_type}.nc'
in_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/{var_name}/' \
f'{file_name}'
web_path = (
f'https://www1.ncdc.noaa.gov/pub/data/daily-grids/beta/by-month/'
f'{year}/{month:02}/{file_name}')
ftp_path = (
f'ftp://ftp.ncdc.noaa.gov/pub/data/daily-grids/beta/by-month/'
f'{year}/{month:02}/{file_name}')
download_err = cjs.download_file(ftp_path, in_path, clobber=True)
for first_day, last_day in zip(first_days, last_days):
py_dir = os.getcwd()
py_script = f'{var_name}_map.py'
log_dir = f'{py_dir}/log'
os.makedirs(log_dir, exist_ok=True)
job_name = f'{var_name}_{first_day}_{last_day}'
log_file = f'{log_dir}/{job_name}.log'
err_file = f'{log_dir}/{job_name}.err'
try:
os.remove(log_file)
except OSError:
pass
try:
os.remove(err_file)
except OSError:
pass
py_option = f'--year {year} --month {month} ' \
f'--first_day {first_day} --last_day {last_day} ' \
f'--dpi {dpi} --fig_dir {fig_dir}'
command = f'bsub -J {job_name} -o {log_file} -e {err_file} ' \
f'-q allnodes -sp 75 /home/carl/template/run_py.sh ' \
f'{py_dir} {py_script} "{py_option}"'
subprocess.Popen(command, shell=True)
cjs.tstamp('Thank you, come again.')
""" Kick off the cluster jobs to make monitoring maps for the month."""
""" Kick off the cluster jobs to make monitoring maps for each day of the
month."""
__author__ = "Carl Schreck"
__email__ = "carl_schreck@ncsu.edu"
......@@ -18,7 +19,7 @@ import cjs # '~carl/lib/python'
parser = argparse.ArgumentParser()
parser.add_argument('--year', default=(datetime.today().year))
parser.add_argument('--month', default=(datetime.today().month - 1))
parser.add_argument('--dpi', default=200)
parser.add_argument('--dpi', default=100)
args = parser.parse_args()
year = int(args.year)
month = int(args.month)
......
......@@ -22,7 +22,7 @@ parser = argparse.ArgumentParser()
parser.add_argument('--year', default=(datetime.today().year))
parser.add_argument('--month', default=(datetime.today().month - 1))
parser.add_argument('--first_day', default=25)
parser.add_argument('--last_day', default=31)
parser.add_argument('--last_day', default=30)
parser.add_argument('--dpi', default=200)
parser.add_argument('--fig_dir', default='figures/')
args = parser.parse_args()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment