Exemple #1
0
 def project(self, in_file, out_file):
     with time_block("Load lons and lats time:", switch=TIME_TEST):
         # 加载经纬度数据
         self._load_lons_lats(in_file)
     with time_block("Create lut time:", switch=TIME_TEST):
         # 使用查找表生成经纬度对应的行列信息
         self._create_lut()
     with time_block("Get index time:", switch=TIME_TEST):
         # 使用生成的行列信息生成数据的索引信息
         self._get_index()
     with time_block("Write data time:", switch=TIME_TEST):
         # 将数据的索引信息和在全球的行列信息进行写入
         self._write(out_file)
Exemple #2
0
def main(sat_sensor, in_file):
    """
    对L3数据进行合成
    :param sat_sensor: 卫星+传感器
    :param in_file: yaml 文件
    :return:
    """
    # ######################## 初始化 ###########################
    # 获取程序所在位置,拼接配置文件
    app = InitApp(sat_sensor)
    if app.error:
        print "Load config file error."
        return

    gc = app.global_config
    sc = app.sat_config

    log = LogServer(gc.path_out_log)

    # 加载全局配置信息

    # 加载程序配置信息

    # 加载卫星配置信息

    # ######################## 开始处理 ###########################
    print "-" * 100
    print "Start plot combine map."

    if not os.path.isfile(in_file):
        log.error("File is not exist: {}".format(in_file))
        return

    print "<<< {}".format(in_file)

    combine = CombineL3()  # 初始化一个合成实例
    combine.load_yaml(in_file)  # 加载 yaml 文件

    with time_block("One combine time", switch=TIME_TEST):
        combine.combine()
    with time_block("One write time", switch=TIME_TEST):
        combine.write()

    if not combine.error:
        print ">>> {}".format(combine.ofile)
    else:
        print "Error: Combine days error: {}".format(in_file)

    print '-' * 100
Exemple #3
0
def plot_map(lats, lons, values, out_file, box=None):
    p = dv_map_oc.dv_map()
    p.show_bg_color = False
    p.colorbar_fmt = "%0.2f"

    title = ''

    # 是否绘制某个区域
    if box:
        lat_s = float(box[0])
        lat_n = float(box[1])
        lon_w = float(box[2])
        lon_e = float(box[3])
        box = [lat_s, lat_n, lon_w, lon_e]
    else:
        box = [90, -90, -180, 180]

    # 绘制经纬度线
    p.delat = 10
    p.delon = 10
    if box[0] - box[1] > 90:
        p.delat = 30  # 30
    elif box[2] - box[3] > 180:
        p.delon = 30  # 30
    p.show_line_of_latlon = True

    # 是否设置 colorbar 范围
    if len(values) == 0:
        return
    vmin = np.min(values)
    vmax = np.max(values)
    # # 是否填写 colorbar title
    # p.colorbar_label = colorbar_label
    #
    # p.colorbar_ticks = legend["ticks"]
    #
    # p.colorbar_tick_labels = legend["tick_labels"]

    p.title = title
    with time_block("plot combine map", switch=TIME_TEST):
        p.easyplot(lats,
                   lons,
                   values,
                   ptype=None,
                   vmin=vmin,
                   vmax=vmax,
                   box=box,
                   markersize=2,
                   marker='o')
        # p.easyplot(lats, lons, value, ptype="pcolormesh", vmin=vmin, vmax=vmax, box=box)
        pb_io.make_sure_path_exists(os.path.dirname(out_file))
        p.savefig(out_file, dpi=300)
        print '>>> {}'.format(out_file)
Exemple #4
0
def main():
    array = np.arange(51).astype(np.float64).reshape((1, 51))
    with time_block('congrid'):
        result = congrid(array, (1, 1018), method='spline')
        for i in result:
            print i
        print result.shape
        print np.std(result)
        print np.mean(result)
        print np.std(array)
        print np.mean(array)
        print array
Exemple #5
0
    def combine(self):
        if self.error:
            return

        # 如果输出文件已经存在,跳过
        elif os.path.isfile(self.ofile):
            self.error = True
            print "Error: File is already exist, skip it: {}".format(
                self.ofile)
            return
        # 合成日数据
        elif pb_io.is_none(self.ifile, self.ofile):
            self.error = True
            print "Error: Is None: ifile or ofile: {}".format(self.yaml_file)
            return
        elif len(self.ifile) < 1:
            self.error = True
            print "Error: File count lower than 1: {}".format(self.yaml_file)
            return

        for in_file in self.ifile:
            if os.path.isfile(in_file):
                print "<<< {}".format(in_file)
            else:
                print "Warning: File is not exist: {}".format(in_file)
                continue
            self.one_in_file = in_file
            # 日合成
            with time_block("One combine time:", switch=TIME_TEST):
                self._combine_2d()

        # 计算数据的平均值
        with time_block("Calculate mean time:", switch=TIME_TEST):
            print "Start calculate."
            self._2d_data_calculate()

        # 输出数据集有效数据的数量
        self._print_data_count()
Exemple #6
0
def main(sat_sensor, in_file):
    """
    对L2数据进行合成
    :param sat_sensor: 卫星+传感器
    :param in_file: yaml 文件
    :return:
    """
    # ######################## 初始化 ###########################
    # 获取程序所在位置,拼接配置文件
    app = InitApp(sat_sensor)
    if app.error:
        print "Load config file error."
        return

    gc = app.global_config
    sc = app.sat_config

    log = LogServer(gc.path_out_log)

    # 加载全局配置信息

    # 加载程序配置信息

    # 加载卫星配置信息
    res = sc.project_res
    half_res = deg2meter(res) / 2.
    cmd = sc.project_cmd % (half_res, half_res)
    row = sc.project_row
    col = sc.project_col

    combine_quick = sc.combine_quick

    # ######################## 开始处理 ###########################
    print "-" * 100
    print "Start combine."

    if not os.path.isfile(in_file):
        log.error("File is not exist: {}".format(in_file))
        return

    print "<<< {}".format(in_file)

    if not combine_quick:
        combine = CombineL2()  # 初始化一个投影实例
        combine.load_cmd_info(cmd=cmd, res=res, row=row, col=col)
        combine.load_yaml(in_file)  # 加载 yaml 文件

        with time_block("One combine time:", switch=TIME_TEST):
            combine.combine()
    else:
        combine = CombineL2Quick()  # 初始化一个投影实例
        combine.load_cmd_info(cmd=cmd, res=res, row=row, col=col)
        combine.load_yaml(in_file)  # 加载 yaml 文件

        with time_block("One combine time:", switch=TIME_TEST):
            combine.combine()

        with time_block("One write time:", switch=TIME_TEST):
            combine.write()

    if not combine.error:
        print ">>> {}".format(combine.ofile)
    else:
        print "Error: Combine day error: {}".format(in_file)

    print "-" * 100
Exemple #7
0
    def draw_combine(self):
        """
        通过日合成文件,画数据集的全球分布图
        文件中需要有 Latitude 和Longitude 两个数据集
        :return:
        """
        try:
            with h5py.File(self.in_file, 'r') as h5:
                dataset = h5.get(self.dataset_name)

                value = dataset[:]
                slope = dataset.attrs["Slope"]
                intercept = dataset.attrs["Intercept"]
                value = value * slope + intercept

                lats = h5.get("Latitude")[:]
                lons = h5.get("Longitude")[:]
        except Exception as why:
            print why
            return

        # 过滤有效范围外的值
        idx = np.where(value > 0)  # 不计算小于 0 的无效值
        if len(idx[0]) == 0:
            print "Don't have enough valid value: {}  {}".format(
                self.dataset_name, len(idx[0]))
            return
        else:
            print "{} valid value count: {}".format(self.dataset_name,
                                                    len(idx[0]))

        value = value[idx]
        lats = lats[idx]
        lons = lons[idx]

        # ############对特殊数据集的值进行处理
        # 有一些数据集的数据在绘图时需要取对数,否则无法区分
        if self.map is not None and "log10" in self.map:
            if self.map["log10"]:
                value = np.log10(value)
        # 有一些数据按照原来的 slope 不对,需要乘 10
        if "Rw" in self.dataset_name:
            value = value * 10
        # #################################

        if DEBUG:
            print "-" * 100
            print self.dataset_name
            d = np.histogram(value, bins=[x * 0.05 for x in xrange(-40, 80)])
            for i in xrange(len(d[0])):
                print "{:10} :: {:10}".format(d[1][i], d[0][i])
            print value.min()
            print value.max()
            print "-" * 100

        p = dv_map_oc.dv_map()
        p.show_bg_color = True
        p.colorbar_fmt = "%0.2f"

        if self.map is not None and "title" in self.map:
            title = self.map["title"]
        else:
            title = self.dataset_name

        # 绘制经纬度线
        if self.map is not None and "lat_lon_line" in self.map:
            lat_lon_line = self.map["lat_lon_line"]
            delat = lat_lon_line["delat"]
            delon = lat_lon_line["delon"]
            p.delat = delat  # 30
            p.delon = delon  # 30
            p.show_line_of_latlon = True
        else:
            p.show_line_of_latlon = False

        # 是否绘制某个区域
        if self.map is not None and "area_range" in self.map:
            area_range = self.map["area_range"]
            lat_s = float(area_range.get("lat_s"))
            lat_n = float(area_range.get("lat_n"))
            lon_w = float(area_range.get("lon_w"))
            lon_e = float(area_range.get("lon_e"))
            box = [lat_s, lat_n, lon_w, lon_e]
        else:
            box = None

        # 是否设置 colorbar 范围
        if self.map is not None and "legend" in self.map:
            legend = self.map["legend"]
            vmin = legend["vmin"]
            vmax = legend["vmax"]
            # 是否填写 colorbar title
            if "label" in legend:
                colorbar_label = legend["label"]
                p.colorbar_label = colorbar_label
            if "ticks" in legend:
                p.colorbar_ticks = legend["ticks"]
            if "tick_labels" in legend:
                p.colorbar_tick_labels = legend["tick_labels"]
        else:
            vmin = vmax = None

        p.title = title
        with time_block("plot combine map", switch=TIME_TEST):
            p.easyplot(lats,
                       lons,
                       value,
                       ptype=None,
                       vmin=vmin,
                       vmax=vmax,
                       box=box,
                       markersize=0.1,
                       marker='o')
            # p.easyplot(lats, lons, value, ptype="pcolormesh", vmin=vmin, vmax=vmax, box=box)
            pb_io.make_sure_path_exists(os.path.dirname(self.out_file))
            p.savefig(self.out_file, dpi=300)
Exemple #8
0
        app = "oc_a02_calibrate.py"
        arg2 = file10
        cmd = "{} {} {} {}".format(python, app, sat_sensor2, arg2)
    else:
        return

    os.system(cmd)


######################### 程序全局入口 ##############################
if __name__ == "__main__":
    # 获取程序参数接口
    ARGS = sys.argv[1:]
    HELP_INFO = \
        u"""
        [arg1]:test_id
        [example]: python app.py arg2
        """
    if "-h" in ARGS:
        print HELP_INFO
        sys.exit(-1)

    if len(ARGS) != 1:
        print HELP_INFO
        sys.exit(-1)
    else:
        TEST_ID = int(ARGS[0])

        with time_block("test time", switch=TIME_TEST):
            main(TEST_ID)
Exemple #9
0
def main(sat_sensor, in_file):
    """
    对L2数据进行投影,记录投影后的位置信息和数据信息
    :param sat_sensor: 卫星+传感器
    :param in_file: HDF5 文件
    :return: 
    """
    # ######################## 初始化 ###########################
    # 获取程序所在位置,拼接配置文件
    app = InitApp(sat_sensor)
    if app.error:
        print "Load config file error."
        return

    gc = app.global_config
    sc = app.sat_config

    log = LogServer(gc.path_out_log)

    # 加载全局配置信息
    out_path = gc.path_mid_projection

    # 加载程序配置信息

    # 加载卫星配置信息
    res = sc.project_res
    half_res = deg2meter(res) / 2.
    cmd = sc.project_cmd % (half_res, half_res)
    row = sc.project_row
    col = sc.project_col
    mesh_size = sc.project_mesh_size

    # ######################## 开始处理 ###########################
    print "-" * 100
    print "Start projection."

    if not os.path.isfile(in_file):
        log.error("File is not exist: {}".format(in_file))
        return

    print "<<< {}".format(in_file)

    with time_block("One project time:", switch=TIME_TEST):
        # 生成输出文件的文件名
        ymd = _get_ymd(in_file)
        hm = _get_hm(in_file)
        sat, sensor = sat_sensor.split('+')
        out_name = "{}_{}_ORBT_L2_OCC_MLT_NUL_{}_{}_{}.HDF".format(
            sat, sensor, ymd, hm, mesh_size.upper())
        out_path = pb_io.path_replace_ymd(out_path, ymd)
        out_file = os.path.join(out_path, out_name)

        # 如果输出文件已经存在,跳过
        if os.path.isfile(out_file):
            print "File is already exist, skip it: {}".format(out_file)
            return

        # 开始创建投影查找表
        projection = Projection(cmd=cmd, row=row, col=col, res=res)
        projection.project(in_file, out_file)

        if not projection.error:
            print ">>> {}".format(out_file)
        else:
            print "Error: Projection error: {}".format(in_file)

        print "-" * 100
# ######################## 程序全局入口 ##############################
if __name__ == "__main__":
    # 获取程序参数接口
    ARGS = sys.argv[1:]
    HELP_INFO = \
        u"""
        [arg1]:sat+sensor
        [arg2]:yaml file
        [arg3]: is_time_series [bool]
        [example]: python app.py arg1 arg2
        """
    if "-h" in ARGS:
        print HELP_INFO
        sys.exit(-1)

    if len(ARGS) == 2:
        SAT_SENSOR = ARGS[0]
        FILE_PATH = ARGS[1]

        with time_block("All", switch=TIME_TEST):
            main(SAT_SENSOR, FILE_PATH)
    else:
        print HELP_INFO
        sys.exit(-1)

# ######################### TEST ##############################
# if __name__ == '__main__':
#     yaml_file = r'20110101_20181231.yaml'
#     main('FY3B+MERSI_AQUA+MODIS', yaml_file)
Exemple #11
0
@Time    : 2018/7/18 14:43
@Author  : AnNing
"""
import os
import sys
from PB.DRC.pb_drc_MVISR_L1 import CLASS_MVISR_L1
from PB.pb_time import time_block
from PB.pb_io import get_files_by_ymd
from DV.dv_map import dv_map

if __name__ == '__main__':
    in_path = r'E:\projects\six_sv_data'
    # in_files = get_files_by_ymd(in_path, '200205181821', '200205181821', '.hdf', r".*FY1D.*GDPT_(\d{8})_(\d{4})")
    in_files = [os.path.join(in_path, 'FY1D_L1_GDPT_20020519_0800.HDF')]
    for in_file in in_files:
        with time_block('all'):
            mvisr = CLASS_MVISR_L1()
            mvisr.Load(in_file)
            print mvisr.ir_coeff_k0['CH_01'].shape
            print mvisr.ir_coeff_k1['CH_01'].shape
            print mvisr.Time.shape
            print mvisr.Lats.shape
            print mvisr.Lons.shape
        lat_0 = 28.550000
        lon_0 = 23.390000
        lat_max = lat_0 + 3
        lat_min = lat_0 - 3
        lon_max = lon_0 + 3
        lon_min = lon_0 - 3

        picture_name = os.path.basename(in_file).split('.')[0] + '.png'
Exemple #12
0
    def draw(self, in_file, proj_file, dataset_name, vmin=None, vmax=None):
        if self.error:
            return
        # 加载 Proj 数据
        if os.path.isfile(proj_file):
            try:
                with h5py.File(proj_file, 'r') as h5:
                    lut_ii = h5.get("lut_ii")[:]
                    lut_jj = h5.get("lut_jj")[:]
                    data_ii = h5.get("data_ii")[:]
                    data_jj = h5.get("data_jj")[:]
            except Exception as why:
                print why
                print "Can't open file: {}".format(proj_file)
                return
        else:
            print "File does not exist: {}".format(proj_file)
            return

        with time_block("Draw load", switch=TIME_TEST):
            # 加载产品数据
            if os.path.isfile(in_file):
                try:
                    with h5py.File(in_file, 'r') as h5:
                        proj_value = h5.get(dataset_name)[:][data_ii, data_jj]
                except Exception as why:
                    print why
                    print "Can't open file: {}".format(in_file)
                    return
            else:
                print "File does not exist: {}".format(in_file)
                return

        if vmin is not None:
            vmin = vmin
        if vmax is not None:
            vmax = vmax

        p = dv_map.dv_map()
        p.title = "{}    {}".format(dataset_name, self.ymd)

        # 增加省边界
        #       p1.show_china_province = True
        p.delat = 30
        p.delon = 30
        p.show_line_of_latlon = False
        #         p.colormap = 'gist_rainbow'
        #         p.colormap = 'viridis'
        #         p.colormap = 'brg'

        # 创建查找表
        lookup_table = prj_core(
            self.cmd, self.res, unit="deg", row=self.row, col=self.col)
        lookup_table.grid_lonslats()
        lons = lookup_table.lons
        lats = lookup_table.lats

        # 创建完整的数据投影
        value = np.full((self.row, self.col), self.fill_value, dtype='f4')

        value[lut_ii, lut_jj] = proj_value
        value = np.ma.masked_less_equal(value, 0)  # 掩掉 <=0 的数据

        # 乘数据的系数,水色产品为 0.001
        slope = 0.001
        value = value * slope

        p.easyplot(lats, lons, value, ptype=None, vmin=vmin,
                   vmax=vmax, markersize=0.1, marker='o')

        out_png_path = os.path.dirname(in_file)
        out_png = os.path.join(out_png_path, '{}.png'.format(dataset_name))
        pb_io.make_sure_path_exists(os.path.dirname(out_png))
        p.savefig(out_png, dpi=300)
Exemple #13
0
    def combine(self):
        if self.error:
            return

        # 如果输出文件已经存在,跳过
        elif os.path.isfile(self.ofile):
            self.error = True
            print "File is already exist, skip it: {}".format(self.ofile)
            return
        # 合成日数据
        elif pb_io.is_none(self.ifile, self.pfile, self.ofile):
            self.error = True
            print "Is None: ifile or pfile or ofile: {}".format(self.yaml_file)
            return
        elif len(self.ifile) < 1:
            self.error = True
            print "File count lower than 1: {}".format(self.yaml_file)

        fill_value = -32767
        for file_idx, in_file in enumerate(self.ifile):
            proj_file = self.pfile[file_idx]
            if os.path.isfile(in_file) and os.path.isfile(proj_file):
                print "*" * 100
                print "Start combining file:"
                print "<<< {}\n<<< {}".format(in_file, proj_file)
            else:
                print "File is not exist: {} OR {}".format(in_file, proj_file)
                continue

            # 加载 proj 数据
            self.load_proj_data(proj_file)
            # 日合成
            with time_block("One combine time:", switch=TIME_TEST):
                try:
                    with h5py.File(in_file, 'r') as h5:
                        for k in h5.keys():
                            # 记录属性信息
                            if k not in self.attrs:
                                self.attrs[k] = pb_io.attrs2dict(
                                    h5.get(k).attrs)

                            if k == "Longitude" or k == "Latitude":
                                continue
                            elif k not in self.out_data:
                                if k == "Ocean_Flag":
                                    self.out_data[k] = np.full(
                                        (self.row, self.col),
                                        fill_value,
                                        dtype='i4')
                                else:
                                    self.out_data[k] = np.full(
                                        (self.row, self.col),
                                        fill_value,
                                        dtype='i2')
                            # 合并一个数据
                            proj_data = h5.get(k)[:]
                            self.out_data[k][self.lut_ii,
                                             self.lut_jj] = proj_data[
                                                 self.data_ii, self.data_jj]

                except Exception as why:
                    print why
                    print "Can't combine file, some error exist: {}".format(
                        in_file)

        with time_block("Grid to lons and lats time:", switch=TIME_TEST):
            if "Longitude" not in self.out_data:
                lookup_table = prj_core(self.cmd,
                                        self.res,
                                        unit="deg",
                                        row=self.row,
                                        col=self.col)
                lookup_table.grid_lonslats()
                self.out_data["Longitude"] = lookup_table.lons
                self.out_data["Latitude"] = lookup_table.lats

        # 输出数据集有效数据的数量
        keys = [x for x in self.out_data]
        keys.sort()
        for k in keys:
            if self.out_data[k] is None:
                print k
                continue
            idx = np.where(self.out_data[k] > 0)
            print "{:30} : {}".format(k, len(idx[0]))
Exemple #14
0
    @staticmethod
    def filter_invalid_data(data):
        """
        过滤无效值,将无效值赋值为nan,
        数据集的dtype改为np.float32
        :param data:
        :return:
        """
        data = data.astype(np.float32)
        idx_invalid = np.where(~np.isfinite(data))
        data[idx_invalid] = np.nan
        return data


if __name__ == '__main__':
    with time_block('all'):
        t_in_file = r'D:\nsmc\fix_data\FY1CD\FY1D_L1_GDPT_20020518_1458.HDF'
        t_mvisr = CLASS_MVISR_L1()
        t_mvisr.Load(t_in_file)
        t_data = t_mvisr.get_extract_data()
        t_channel_name = 'CH_'
        for k in t_data:
            if t_channel_name in k:
                for j in t_data[k]:
                    print k, j, t_data[k][j].shape, np.nanmin(
                        t_data[k][j]), np.nanmax(t_data[k][j])
            else:
                print k, t_data[k].shape, np.nanmin(t_data[k]), np.nanmax(
                    t_data[k])
        print t_mvisr.file_attr
        # mvisr.Load(in_file)
Exemple #15
0
def get_day(l, activity):
    d = {}

    for x in l:
        if x[0] not in d.keys():
            d[x[0]] = []
        d[x[0]].append(x[1])

    d = {k: [v.count(activity), len(v)] for k, v in d.items()}

    l = [[k, v[0], v[1]] for k, v in d.items()]

    l = sorted(l, key=lambda x: (x[1], x[2]))
    return l[0][0]


if __name__ == '__main__':
    mylist = [['Day 1', 'Activity A'], ['Day 2', 'Activity A'],
              ['Day 1', 'Activity A'], ['Day 2', 'Activity C'],
              ['Day 2', 'Activity D']]
    mylist = mylist * 50
    for i in xrange(10):
        with time_block('new'):
            for i in xrange(100000):
                get_day_new(mylist, 'Activity D')

        with time_block('old'):
            for i in xrange(100000):
                get_day(mylist, 'Activity D')
Exemple #16
0
    _, secs = np.modf(mins_point * 60.)

    times = datetime.strptime("%s%02d%02d%02d" % (ymd, hour, mins, secs),
                              '%Y%m%d%H%M%S')
    ymdhms = (times - datetime(1970, 1, 1, 0, 0, 0)).total_seconds()
    return ymdhms


if __name__ == '__main__':
    T1 = datetime.now()
    BandLst = ['CH_20', 'CH_21', 'CH_22', 'CH_23', 'CH_24', 'CH_25']
    L1File = 'D:/data/IASI/IASI_xxx_1C_M02_20180502060857Z_20180502061152Z_N_O_20180502072426Z__20180502072755'
    L1File = 'D:/data/IASI/IASI_xxx_1C_M02_20180809140252Z_20180809140556Z_N_O_20180809150225Z__20180809150600'
    L1File = 'D:/data/IASI_NC/W_XX-EUMETSAT-Darmstadt,HYPERSPECT+SOUNDING,MetOpA+IASI_C_EUMP_20181111053809_62589_eps_o_l1.nc'
    iasi1 = ReadIasiL1(L1File)
    with time_block('>>>>>>>>>>>>read iasi', True):
        print iasi1.satellite  # 卫星名
        print iasi1.sensor  # 传感器名
        print iasi1.ymd  # L1 文件年月日 YYYYMMDD
        print iasi1.hms  # L1 文件时分秒 HHMMSS
        print iasi1.resolution  # 分辨率
        print iasi1.channels  # 通道数量
        print iasi1.data_shape
        print iasi1.file_attr

        def print_data_status(datas, name=None):
            data_shape = datas.shape
            data_min = np.nanmin(datas)
            data_max = np.nanmax(datas)
            data_mean = np.nanmean(datas)
            data_median = np.nanmedian(datas)
Exemple #17
0
        "right_top": right_top,
        "right_bottom": right_bottom,
    }

    return text


######################### 程序全局入口 ##############################
if __name__ == "__main__":
    # 获取程序参数接口
    ARGS = sys.argv[1:]
    HELP_INFO = \
        u"""
        [arg1]:sat+sensor
        [arg2]:hdf_file
        [example]: python app.py arg1 arg2
        """
    if "-h" in ARGS:
        print HELP_INFO
        sys.exit(-1)

    if len(ARGS) != 2:
        print HELP_INFO
        sys.exit(-1)
    else:
        SAT_SENSOR = ARGS[0]
        FILE_PATH = ARGS[1]

        with time_block("Calibrate time:", switch=TIME_TEST):
            main(SAT_SENSOR, FILE_PATH)
Exemple #18
0
def main(sat_sensor, in_file):
    """
    绘制 L3 产品的全球投影图。
    :param sat_sensor: 卫星+传感器
    :param in_file: HDF5 文件
    :return: 
    """
    # ######################## 初始化 ###########################
    # 获取程序所在位置,拼接配置文件
    app = InitApp(sat_sensor)
    if app.error:
        print "Load config file error."
        return

    gc = app.global_config
    sc = app.sat_config

    log = LogServer(gc.path_out_log)

    # 加载全局配置信息

    # 加载程序配置信息

    # 加载卫星配置信息
    colorbar_range = sc.plt_combine_colorbar_range
    area_range = sc.plt_combine_area_range
    plot_global = sc.plt_combine_plot_global
    plot_china = sc.plt_combine_plot_china
    log10_ticks = sc.plt_combine_log10_ticks
    log10_tick_labels = sc.plt_combine_log10_tick_label
    log10_set = sc.plt_combine_log10_set
    # ######################## 开始处理 ###########################
    print "-" * 100
    print "Start plot combine map."

    if not os.path.isfile(in_file):
        log.error("File is not exist: {}".format(in_file))
        return

    print "<<< {}".format(in_file)

    sat, sensor = sat_sensor.split("+")
    for legend in colorbar_range:
        print "*" * 100
        dataset_name, name, vmax, vmin, colorbar_label = legend
        vmax = float(vmax)  # color bar 范围 最大值
        vmin = float(vmin)  # color bar 范围 最小值

        dir_path = os.path.dirname(in_file)
        ymd = _get_ymd(in_file)
        kind = _get_kind(in_file)

        ymd_date = datetime.strptime(ymd, "%Y%m%d")

        if dataset_name in log10_set:
            _ticks = log10_ticks
            _tick_labels = log10_tick_labels
            if dataset_name == "Ocean_TSM":
                _ticks.append(2.00)
                _tick_labels.append("100")
            if dataset_name == "Ocean_YS443":
                _ticks = _ticks[:-3]
                _tick_labels = _tick_labels[:-3]
        else:
            _ticks = None
            _tick_labels = None

        png = "{}_{}_{}_{}.png".format(sat_sensor,
                                       dataset_name.replace("Aod", "AOD"), ymd,
                                       kind)
        title = _get_title(sat, sensor, name, kind, ymd_date)

        plot_map = {
            "title": title,
            "legend": {
                "vmax": vmax,
                "vmin": vmin,
                "label": colorbar_label,
                "ticks": _ticks,
                "tick_labels": _tick_labels
            },
            "area_range": area_range,
            "lat_lon_line": {
                "delat": 30,
                "delon": 30,
            },
        }

        # 画全球范围
        if plot_global.lower() == "on":
            pic_name = os.path.join(dir_path, "picture_global", png)
            # 如果输出文件已经存在,跳过
            if os.path.isfile(pic_name):
                print "File is already exist, skip it: {}".format(pic_name)
            else:
                if dataset_name in log10_set:
                    plot_map["log10"] = True

                with time_block("Draw combine time:", switch=TIME_TEST):
                    plot_map_global = PlotMapL3(in_file,
                                                dataset_name,
                                                pic_name,
                                                map_=plot_map)
                    plot_map_global.draw_combine()

                if not plot_map_global.error:
                    print ">>> {}".format(plot_map_global.out_file)
                else:
                    print "Error: Plot global picture error: {}".format(
                        in_file)

        # 单画中国区域
        if plot_china.lower() == "on":
            pic_name = os.path.join(dir_path, "picture_china", png)
            # 如果输出文件已经存在,跳过
            if os.path.isfile(pic_name):
                print "File is already exist, skip it: {}".format(pic_name)
            else:
                area_range_china = {
                    "lat_s": "56",
                    "lat_n": "2",
                    "lon_w": "65",
                    "lon_e": "150",
                }
                lat_lon_line = {
                    "delat": 10,
                    "delon": 10,
                }
                plot_map["area_range"] = area_range_china
                plot_map["lat_lon_line"] = lat_lon_line

                with time_block("Draw combine time:", switch=TIME_TEST):
                    plot_map_china = PlotMapL3(in_file,
                                               dataset_name,
                                               pic_name,
                                               map_=plot_map)
                    plot_map_china.draw_combine()

                if not plot_map_china.error:
                    print ">>> {}".format(plot_map_china.out_file)
                else:
                    print "Error: Plot china picture error: {}".format(in_file)

    print '-' * 100
Exemple #19
0
                    print why
            return out_file
    except Exception as why:
        print why
        return


######################### 程序全局入口 ##############################
if __name__ == "__main__":
    # 获取程序参数接口
    ARGS = sys.argv[1:]
    HELP_INFO = \
        u"""
        [arg1]:sat+sensor
        [arg2]:ncep_file
        [example]: python app.py arg1 arg2
        """
    if "-h" in ARGS:
        print HELP_INFO
        sys.exit(-1)

    if len(ARGS) != 2:
        print HELP_INFO
        sys.exit(-1)
    else:
        SAT_SENSOR = ARGS[0]
        FILE_PATH = ARGS[1]

        with time_block("Ncep to byte time:", switch=TIME_TEST):
            main(SAT_SENSOR, FILE_PATH)
Exemple #20
0
    if m is None:
        return
    else:
        return m.groups()[0]


######################### 程序全局入口 ##############################
if __name__ == "__main__":
    # 获取程序参数接口
    ARGS = sys.argv[1:]
    HELP_INFO = \
        u"""
        [arg1]:sat+sensor
        [arg2]:hdf_file
        [example]: python app.py arg1 arg2
        """
    if "-h" in ARGS:
        print HELP_INFO
        sys.exit(-1)

    if len(ARGS) != 2:
        print HELP_INFO
        sys.exit(-1)
    else:
        SAT_SENSOR = ARGS[0]
        FILE_PATH = ARGS[1]

        with time_block("Projection time:", switch=TIME_TEST):
            main(SAT_SENSOR, FILE_PATH)