plotCombined.py 4.49 KB
Newer Older
Espen Sollum's avatar
Espen Sollum committed
1
#!/usr/bin/env python3.7
Espen Sollum's avatar
Espen Sollum committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

"""
Plot combined ash detections for selected IASI (processed) netcdf files

"""

import IASITools as IASITools
from glob import glob
import os
import sys
import argparse
import atexit
import numpy as np
import re
import shutil
import datetime as dt
from datetime import timedelta
import pdb
import importlib
importlib.reload(IASITools)


24
25
26
27
28
29
30
def plotCombined(file_name,
                 ignore=False,
                 Type=None, proj='PS_NE',
                 verbose=False,
                 db_ash=None,
                 db_unk=None,
):
Espen Sollum's avatar
Espen Sollum committed
31
32
    ## :TODO: make input arg
#    Type='dBT_already_calculated'
33
34
    if Type is None or Type == "SEVIRI_dBT":
        plotmethod='SEVIRI_dBT_already_calculated'
Espen Sollum's avatar
Espen Sollum committed
35
        str1 = 'SEVIRI_dBT'
36
    elif Type == "IASI_dBT":
Espen Sollum's avatar
Espen Sollum committed
37
        plotmethod = 'dBT_already_calculated'
Espen Sollum's avatar
Espen Sollum committed
38
        str1 = 'IASI_dBT'
Espen Sollum's avatar
Espen Sollum committed
39
40
41
    elif Type == "SEVIRI_AshML":
        plotmethod = 'SEVIRI_AshML'
        str1 = 'IASI_dBT'
42
43
44
    elif Type == "IASI_AshML":
        plotmethod = 'IASI_AshML'
        str1 = 'IASI_dBT'        
45
46
47
48
49
50
    elif Type == "SEVIRI_dBT_AF":
        plotmethod = "SEVIRI_dBT_AF"
        str1 = 'IASI_dBT'
    elif Type == "IASI_dBT_AF":
        plotmethod = "IASI_dBT_AF"
        str1 = 'IASI_dBT'
Espen Sollum's avatar
Espen Sollum committed
51
52
53
    else:
        print("Invalid plot Type, exiting")
        sys.exit(0)
Espen Sollum's avatar
Espen Sollum committed
54
    
55
56
57
58
59
60
    if ignore:
        date_str = dt.datetime.utcnow().strftime('%Y%m%d%H%M%S')
        man_title = date_str
        fnpng = os.path.basename(file_name).split('.nc')[0] + '_' + Type + ".png"
    else:
        _tmp = os.path.basename(file_name).split('_')
Espen Sollum's avatar
Espen Sollum committed
61
62
        #        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]
63
64
        man_title = date_str
        fnpng = os.path.basename(file_name).split('.nc')[0] + '_' + Type + ".png"
Espen Sollum's avatar
Espen Sollum committed
65
        print("man_title ", man_title)
Espen Sollum's avatar
Espen Sollum committed
66
67
68
69
    
    s = IASITools.Scene()
    s.ReadNetCDF(file_name)

70
71


Espen Sollum's avatar
Espen Sollum committed
72
73
74

    s.PlotLatLonVals(Title=False,
                     ManualTitle=man_title,
75
                     Type=plotmethod, 
Espen Sollum's avatar
Espen Sollum committed
76
77
78
                     test=True,
                     PlotAshContour=True,
                     PlotFile=fnpng,
79
80
81
82
83
                     #                     Projection='PS_NE')
                     Projection=proj,
                     verbose=verbose,
                     db_ash=db_ash,
                     db_unk=db_unk)
Espen Sollum's avatar
Espen Sollum committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99


if __name__ == "__main__":      
    parser = argparse.ArgumentParser(prog="plotCombined", 
                                     description=":DESCRIPTION:",
                                     formatter_class=argparse.
                                     ArgumentDefaultsHelpFormatter)
        
    parser.add_argument('-f', '--file_name', 
                        dest='file_name',
                        help="IASI Netcdf file to plot")

    parser.add_argument('-p', '--path', 
                        dest='path_name',
                        help="Path to IASI Netcdf files to plot")

100
101
102
    parser.add_argument('-t', '--type', 
                        dest='Type',
                        default ='SEVIRI_dBT',
103
104
                        help=("plot type [IASI_dBT, SEVIRI_dBT, SEVIRI_AshML, IASI_AshML, "
                              "SEVIRI_dBT_AF, IASI_dBT_AF]"))
105
106
107
108
    parser.add_argument('-m', '--map_projection', 
                        dest='map_projection',
                        default ='PS_NE',
                        help="map proj [try: PS_NE (=northern europe), lcc(=fit to swath)]")
109
110
111
112
    parser.add_argument('-i', '--ignore_date', 
                        dest='ignore_date', action="store_true",
                        default=False,
                        help="Just plot the file, ignoring date and time info from file name")
113
114
115
116
117
118
119
120
121
122
    parser.add_argument('--dba', 
                        dest='dba', default=3.0,
                        help="IASI dBT ash limit (for IASI ash flag plot only)")
    parser.add_argument('--dbu', 
                        dest='dbu', default=2.0,
                        help="IASI dBT unknown limit")
    parser.add_argument('-v', 
                        dest='verbose', action="store_true",
                        default=False,
                        help="")
123
124
125

    

Espen Sollum's avatar
Espen Sollum committed
126
127
128
129
130
    args = parser.parse_args()

    # Plot file (skip if size 0)
    full_file_name = os.path.join(args.path_name, args.file_name) 
    if os.stat(full_file_name).st_size > 0:
131
        plotCombined(full_file_name, ignore=args.ignore_date, Type=args.Type, proj=args.map_projection, verbose=args.verbose, db_ash=float(args.dba), db_unk=float(args.dbu))
Espen Sollum's avatar
Espen Sollum committed
132
133
134
135