Commit 2c592f8d authored by Espen Sollum's avatar Espen Sollum
Browse files

Small changes

parent e37e4e88
......@@ -848,6 +848,7 @@ class Scene(object):
from matplotlib import colors, cm
from mpl_toolkits.basemap import Basemap, cm, shiftgrid
contour_colors = ['k', 'r']
fsize = 15.0
rcParams.update({'font.size':fsize})
......@@ -1145,11 +1146,24 @@ class Scene(object):
# pdb.set_trace()
data = self.SEVIRI_dBT
vmin= -2
vmax= 4
step= 2.
vmax= 2
step= 1.
cblabel='Brigthness temperature difference(K)'
# levels=[self.SEVIRI_dBTLimit]
levels=[-0.3]
levels=[-0.5, -0.2]
contour_colors = ['r', 'k']
elif Type=='SEVIRI_AshML':
data = self.MassLoading[:]
# data = self.AshML[:]*1000 # Convert from g/m**3 to g/m**2 assuming a 1 km thick cloud
vmin=0
vmax= 10.0 #2.5 #0.007*1000 # 2 # 20 #data.max()*0.5#
step= 1.0 #0.8 # vmax/5. #0.01
cblabel='Ash Mass Loading (g/m$^2$)'
#cmap = plt.get_cmap('gist_ncar_r')
cmap = plt.get_cmap('jet')
#levels=[.5, 2.0]
levels=[.1]
tri=True
# print "data min/max", Type, data.min(), data.max(), test, Type
......@@ -1175,7 +1189,8 @@ class Scene(object):
norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
# cmap = cm.jet
cmap = plt.get_cmap('jet')
#cmap = plt.get_cmap('jet')
#cmap = plt.get_cmap('gist_ncar_r')
ms = cm.ScalarMappable(norm=norm, cmap=cmap)
ip=0
Ntot, = data.shape #self.Nspectra*self.Nscanlines
......@@ -1224,6 +1239,7 @@ class Scene(object):
if Type=='dBT' or Type=='SEVIRIdBT' or PlotAshContour:
# Include contour line at +0.5K
# Or at selected levels of mass loading
# from matplotlib.mlab import griddata
# ESO: trying different library
from scipy.interpolate import griddata
......@@ -1254,7 +1270,7 @@ class Scene(object):
# cs = m.contour(XM,YM,DATA,levels, colors='r',linewidths=1.5)
# pdb.set_trace()
cs = m.contour(Xi,Yi,DATA,levels, colors=['k', 'r'], linewidths=1.5, latlon=True) #, tri=True)
cs = m.contour(Xi,Yi,DATA,levels, colors=contour_colors, linewidths=1.5, latlon=True) #, tri=True)
if not test:
ticks = np.arange(vmin,vmax+0.0001,step)
cb=m.colorbar(im,location='right', pad="5%", ticks=ticks)
......@@ -1306,11 +1322,23 @@ class Scene(object):
self.lons = ncfile.variables['lon'][:]
self.ascan = ncfile.variables['ascan'][:]
self.atrack = ncfile.variables['atrack'][:]
self.dBT = ncfile.variables['dBT'][:]
self.npoints = len(self.lats)
# These variables are possibly missing
try:
self.dBT = ncfile.variables['dBT'][:]
except:
pass
try:
self.SEVIRI_dBT = ncfile.variables['SEVIRI_dBT'][:]
except:
pass
try:
self.MassLoading = ncfile.variables['MassLoading'][:]
except:
pass
self.npoints = len(self.lats)
# These variables are possibly missing
try:
self.AshML = ncfile.variables['ML'][:]
self.AshRe = ncfile.variables['Re'][:]
self.corr = ncfile.variables['corr'][:]
......@@ -1346,7 +1374,7 @@ class Scene(object):
self.npoints = len(self.lats)
except Exception as e:
print("Exception: ", e)
print("Exception in IASITools/ReadNetcdf: ", e)
return
......
......@@ -22,6 +22,7 @@ import shutil
import datetime as dt
from datetime import timedelta
import pdb
#from joblib import Parallel, delayed
import importlib
importlib.reload(IASITools)
......@@ -154,8 +155,6 @@ def PlotIASIFilteredGeo(nc_directory,
man_title = date_str[0:4] +'-'+date_str[4:6]+'-'+date_str[6:8]+' '+date_str[8:10]+':'+date_str[10:12] + ' UTC'
# pdb.set_trace()
if verbose:
print("Plotting file ", fnpng)
......@@ -179,6 +178,16 @@ def PlotIASIFilteredGeo(nc_directory,
del(s)
continue
def do_plot(f, **kwargs):
""" The main job from PlotIASIFilteredGeo, moved to a function to allow
parallelization
"""
pass
if __name__ == "__main__":
......@@ -202,7 +211,9 @@ if __name__ == "__main__":
dest='netcdf_directory',
help="")
parser.add_argument(
'--plot_directory', default="/viper/nadir/nvap/IASI/plots/",
'--plot_directory',
# default="/viper/nadir/nvap/IASI/plots/",
default="/homevip/espen/repos/ash-iasi/Plots/",
dest='plot_directory',
help="")
parser.add_argument(
......@@ -267,6 +278,8 @@ if __name__ == "__main__":
lat_min = args.lat_min
lat_max = args.lat_max
# nc_directory = config.NETCDF_OUT
if args.netcdf_directory == None:
......
......@@ -241,22 +241,22 @@ if __name__ == "__main__":
if args.verbose:
print(dt.datetime.utcnow().strftime("%Y-%m-%d %H:%M"),": processing file ", fn)
lonmin, lonmax, latmin, latmax = IASITools.GetLatLonRegion(fn, verbose=args.verbose)
if args.verbose:
print(lonmin, lonmax, latmin, latmax, fnpng)
if latmin < -75:
Projection='spstere'
elif latmax > 75:
Projection='npstere'
else:
Projection='lcc'
Scene = ReadAndPlotSingleIASIFile(fn, Projection=Projection, PlotFile=fnpng, ncfFile=fnncf, verbose=args.verbose, old_iasi=args.old_iasi)
ii = ii + 1
processed_count = processed_count + 1
if Scene == None:
print("Invalid Scene")
continue
lonmin, lonmax, latmin, latmax = IASITools.GetLatLonRegion(fn, verbose=args.verbose)
if args.verbose:
print(lonmin, lonmax, latmin, latmax, fnpng)
if latmin < -75:
Projection='spstere'
elif latmax > 75:
Projection='npstere'
else:
Projection='lcc'
Scene = ReadAndPlotSingleIASIFile(fn, Projection=Projection, PlotFile=fnpng, ncfFile=fnncf, verbose=args.verbose, old_iasi=args.old_iasi)
ii = ii + 1
processed_count = processed_count + 1
if Scene == None:
print("Invalid Scene")
continue
except Exception as e:
print("Error", e)
ii = ii + 1
......
#!/usr/bin/env python3
#!/usr/bin/env python3.7
"""
DESCRIPTION
Combine IASI netcdf files (created by `PlotSelectedNCF.py´) into
......@@ -62,7 +62,7 @@ def run_test(idir):
add_parameter(file_list, time_stamp, idir)
def make_file_list(in_directory):
def make_file_list(in_directory, old_iasi=False):
"""
Return list of IASI nc files to be merged
......@@ -71,9 +71,13 @@ def make_file_list(in_directory):
"""
start_str='W_XX'
if old_iasi:
start_str='iasi_'
in_files = [f for f in os.listdir(in_directory) if (f.endswith('.nc') and
f.startswith('W_XX'))]
f.startswith(start_str))]
# Note: for older files (e.g. 2010) use this:
# f.startswith('iasi_'))]
......@@ -82,7 +86,7 @@ def make_file_list(in_directory):
files_dict = {}
for f in in_files:
files_dict.update({datetime_iasi(f) : f})
files_dict.update({datetime_iasi(f, old_iasi=old_iasi) : f})
return files_dict
......@@ -94,6 +98,11 @@ def make_interval(files_dict, days_to_process=None):
"""
if days_to_process is None:
days_to_process=10000
else:
days_to_process=int(days_to_process)
earliest_date = min(files_dict)
latest_date = max(files_dict)
......@@ -137,20 +146,20 @@ def dt_to_name(start, end):
return start.strftime("%Y%m%d_%H%M") + end.strftime("-%H%M")
def datetime_iasi(file_name):
def datetime_iasi(file_name, old_iasi=False):
"""
Extract date from IASI file name.
Return as datetime object
"""
# For older IASI files:
# DT_FMT = "%Y%m%d_%H%M"
# date_str = re.findall(r"\d{8}_\d{4}", file_name)
DT_FMT = "%Y%m%d%H%M"
date_str = re.findall(r"\d{12}", file_name)
# For older IASI files:
if old_iasi:
DT_FMT = "%Y%m%d_%H%M"
date_str = re.findall(r"\d{8}_\d{4}", file_name)
if len(date_str) != 1:
......@@ -239,17 +248,23 @@ def add_parameter(file_list, time_stamp, idir):
print("Error removing file", f)
def run_program(in_dir, out_dir, days_tp):
def run_program(args): #in_dir, out_dir, days_tp, old_iasi=False):
"""
Process all files in in_dir, wrirte output to out_dir
Process all files in in_dir, write output to out_dir
"""
in_dir=args.idir
out_dir=args.odir
days_tp=args.days_to_process
old_iasi=args.old_iasi
# Get all dates and file names
files_dict = make_file_list(in_dir)
files_dict = make_file_list(in_dir, old_iasi=old_iasi)
# Find files within each 6h interval
interval_files = make_interval(files_dict, days_to_process=int(days_tp))
# interval_files = make_interval(files_dict, days_to_process=int(days_tp))
interval_files = make_interval(files_dict, days_to_process=days_tp)
# Merge files and add ncf parameters
for key in interval_files:
......@@ -283,6 +298,12 @@ if __name__ == "__main__":
dest='run',
help="If true, run for all files in input directory")
parser.add_argument('--old_iasi',
default=False,
action='store_true',
dest='old_iasi',
help="If true, input is old IASI files (with different name convention)")
parser.add_argument('--idir',
default=INDIR,
dest='idir',
......@@ -311,7 +332,8 @@ if __name__ == "__main__":
if args.test:
run_test(args.idir)
elif args.run:
run_program(args.idir, args.odir, args.days_to_process)
# run_program(args.idir, args.odir, args.days_to_process, )
run_program(args)
else:
print("Nothing to do")
sys.exit(0)
......
#!/usr/bin/env python3
#!/usr/bin/env python3.7
"""
Plot combined ash detections for selected IASI (processed) netcdf files
......@@ -28,8 +28,14 @@ def plotCombined(file_name, ignore=False, Type=None):
plotmethod='SEVIRI_dBT_already_calculated'
str1 = 'SEVIRI_dBT'
elif Type == "IASI_dBT":
plotmethod = 'SEVIRI_dBT_already_calculated'
plotmethod = 'dBT_already_calculated'
str1 = 'IASI_dBT'
elif Type == "SEVIRI_AshML":
plotmethod = 'SEVIRI_AshML'
str1 = 'IASI_dBT'
else:
print("Invalid plot Type, exiting")
sys.exit(0)
if ignore:
date_str = dt.datetime.utcnow().strftime('%Y%m%d%H%M%S')
......@@ -37,9 +43,11 @@ def plotCombined(file_name, ignore=False, Type=None):
fnpng = os.path.basename(file_name).split('.nc')[0] + '_' + Type + ".png"
else:
_tmp = os.path.basename(file_name).split('_')
date_str = _tmp[2][0:4] + '-' + _tmp[2][4:6] + '-' + _tmp[2][6:8] + '-' + _tmp[3][0:3]
# date_str = _tmp[2][0:4] + '-' + _tmp[2][4:6] + '-' + _tmp[2][6:8] + '-' + _tmp[3][0:3]
date_str = _tmp[2][0:4] + '-' + _tmp[2][4:6] + '-' + _tmp[2][6:8] + '-' + _tmp[3][0:4]
man_title = date_str
fnpng = os.path.basename(file_name).split('.nc')[0] + '_' + Type + ".png"
print("man_title ", man_title)
s = IASITools.Scene()
s.ReadNetCDF(file_name)
......@@ -73,7 +81,7 @@ if __name__ == "__main__":
parser.add_argument('-t', '--type',
dest='Type',
default ='SEVIRI_dBT',
help="plot type [IASI_dBT, SEVIRI_dBT]")
help="plot type [IASI_dBT, SEVIRI_dBT, SEVIRI_AshML]")
parser.add_argument('-i', '--ignore_date',
dest='ignore_date', action="store_true",
......
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