Commit 05f24172 authored by Carl Schreck's avatar Carl Schreck

Working on bsub with monthly maps

parent 75f227fe
""" Kick off the cluster jobs to make monitoring maps for the month."""
__author__ = "Carl Schreck"
__email__ = "carl_schreck@ncsu.edu"
__copyright__ = "Copyright 2020, North Carolina State University"
__license__ = "BSD-3.0"
import os
import argparse
import subprocess
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)
year = int(args.year)
month = int(args.month)
dpi = int(args.dpi)
if month < 1:
month += 12
year -= 1
days_in_month = calendar.monthrange(year, month)[1]
days_in_month = 6 #######################
var_names = ['z500', 'prcp', 'temp']
delta_days = [1, 5]
cjs.tstamp('Here we go!')
for var_name in var_names:
for delta_day in delta_days:
fig_dir = f'figures/{var_name}-{delta_day}'
os.makedirs(fig_dir, exist_ok=True)
old_files = glob.glob(f'{fig_dir}/*')
for file in old_files:
os.remove(file)
first_days = np.arange(start_day, days_in_month - delta_days + 2, 1)
last_days = np.arange(start_day + delta_days - 1, days_in_month + 1, 1)
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'
os.remove(log_file)
os.remove(err_file)
py_option = f'--year {year} --month {month} ' \
f'--first_day {first_day} --last_day {last_day} ' \
f'--dpi {dpi} --fig_dir {fig_dir} --no_terrain'
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.run(command, shell=True)
cjs.tstamp('Thank you, come again.')
......@@ -13,12 +13,29 @@ import calendar
import cjs # '~carl/lib/python'
from datetime import datetime
import numpy as np
import argparse
# These are some parameters that could be useful to have up top
year = 2020
month = 5
first_day = 25
last_day = 31
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('--dpi', default=200)
parser.add_argument('--fig_dir', default='figures/')
parser.add_argument('--no_terrain', dest='terrain', action='store_false')
parser.set_defaults(terrain=True)
year = int(args.year)
month = int(args.month)
if month < 1:
month += 12
year -= 1
first_day = int(args.first_day)
last_day = int(args.last_day)
fig_dir = args.fig_dir
dpi = int(args.dpi)
add_terrain = args.terrain
clobber = False
time_range = slice(f'{year}-{month:02}-{first_day:02}',
......@@ -68,7 +85,8 @@ anom_data = anom_data.where(total_ds['prcp'][0].notnull())
cjs.tstamp('Draw map')
ax = plt.axes(projection=cjs.conus_projection)
cjs.add_conus_map(ax=ax)
cjs.add_shaded_relief(ax=ax)
if add_terrain:
cjs.add_shaded_relief(ax=ax)
cjs.tstamp('Draw data')
levels = [5, 10, 25, 50, 75, 100, 125, 150, 200, 300, 500]
......@@ -99,8 +117,8 @@ plt.text(-0.1, -0.25, today_string,
cjs.tstamp('Save figure')
plt.tight_layout()
plt.savefig(f'figures/prcp-pon-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=200)
plt.savefig(f'{fig_dir}/prcp-pon-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=dpi)
# plt.show()
plt.close()
......
......@@ -40,7 +40,9 @@ if download_err:
file_type = 'prelim'
file_name = f'prcp-{year}{month:02}-grd-{file_type}.nc'
in_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/prcp/{file_name}'
ftp_path = (f'https://www1.ncdc.noaa.gov/pub/data/daily-grids/beta/by-month/'
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)
......
......@@ -15,7 +15,7 @@ import cjs # '~carl/lib/python'
cjs.tstamp('Here we go!')
# These are some parameters that could be useful to have up top
month = 5
month = 6
year = 2020
days_in_month = calendar.monthrange(year, month)[1]
time_range = slice(f'{year}-{month}-01', f'{year}-{month}-{days_in_month}')
......
......@@ -13,12 +13,29 @@ import cartopy.crs as ccrs
import calendar
import cjs # '~carl/lib/python'
from datetime import datetime
import argparse
# These are some parameters that could be useful to have up top
year = 2020
month = 5
first_day = 25
last_day = 31
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('--dpi', default=200)
parser.add_argument('--fig_dir', default='figures/')
parser.add_argument('--no_terrain', dest='terrain', action='store_false')
parser.set_defaults(terrain=True)
year = int(args.year)
month = int(args.month)
if month < 1:
month += 12
year -= 1
first_day = int(args.first_day)
last_day = int(args.last_day)
fig_dir = args.fig_dir
dpi = int(args.dpi)
add_terrain = args.terrain
clobber = False
time_range = slice(f'{year}-{month:02}-{first_day:02}',
......@@ -62,7 +79,8 @@ anom_data = (total_data - clim_data) * 9 / 5
cjs.tstamp('Draw map')
ax = plt.axes(projection=cjs.conus_projection)
cjs.add_conus_map(ax=ax, facecolor='none')
cjs.add_shaded_relief(ax=ax)
if add_terrain:
cjs.add_shaded_relief(ax=ax)
cjs.tstamp('Draw data')
levels = list(np.arange(-5,6)*3)
......@@ -94,8 +112,8 @@ plt.text(-0.1, -0.25, today_string,
cjs.tstamp('Save figure')
plt.tight_layout()
plt.savefig(f'figures/tave-anom-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=200)
plt.savefig(f'{fig_dir}/tave-anom-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=dpi)
# plt.show()
plt.close()
......
......@@ -36,7 +36,9 @@ if download_err:
file_type = 'prelim'
file_name = f'tavg-{year}{month:02}-grd-{file_type}.nc'
in_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/tavg/{file_name}'
ftp_path = (
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=True)
......
......@@ -15,12 +15,26 @@ import calendar
import matplotlib as mpl
import cjs # '~carl/lib/python'
from datetime import datetime
import argparse
# These are some parameters that could be useful to have up top
year = 2020
month = 5
first_day = 25
last_day = 31
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('--dpi', default=200)
parser.add_argument('--fig_dir', default='figures/')
year = int(args.year)
month = int(args.month)
if month < 1:
month += 12
year -= 1
first_day = int(args.first_day)
last_day = int(args.last_day)
fig_dir = args.fig_dir
dpi = int(args.dpi)
clobber = False
time_range = slice(f'{year}-{month:02}-{first_day:02}',
......@@ -125,8 +139,8 @@ for region in ['nhem', 'namer']:
cjs.tstamp('Save figure')
# plt.tight_layout()
plt.savefig(f'figures/hgt500-{region}-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=200)
plt.savefig(f'{fig_dir}/hgt500-{region}-{year}-{month:02}{first_day:02}'
f'-{month:02}{last_day:02}.png', dpi=dpi)
# plt.show()
# plt.close()
......
......@@ -34,7 +34,7 @@ ftp_path = (f'ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.dailyavgs/'
download_err = cjs.download_file(ftp_path, in_path, clobber=clobber)
region = 'namer'
for delta_days in [1, 5]:
for delta_days in [5, 1]:
fig_path = f'figures/hgt500-{region}-{delta_days}/'
os.makedirs(fig_path, exist_ok=True)
old_files = glob.glob(f'{fig_path}/*')
......
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