コード例 #1
0
    def contour_map(self):
        params_dict = self.params_dict
        color_labels = self.color_labels
        color_levels = self.color_levels
        cn_fill_colors = np.arange(0,color_levels,1)

        nboxes = np.shape(cn_fill_colors)[0]

        # labels = [""] * nboxes
        #3.图例解释数据
        # if (self.output_img_name.contains("RH") or self.output_img_name.contains("TK")):
        #     labels[0] = "NoData"
        #     labels[1] = "<" + str(cn_levels[1])
        #     labels[nboxes - 1] = ">" + str(cn_levels[nboxes - 2])
        #     for i in range(2, nboxes - 1):
        #         labels[i] = str(cn_levels[i - 1]) + "~" + str(cn_levels[i])
        # else:
        #     labels[0] = "<" + str(cn_levels[0])
        #     labels[nboxes - 1] = ">" + str(cn_levels[nboxes - 2])
        #     for i in range(1, nboxes - 1):
        #         labels[i] = str(cn_levels[i - 1]) + "~" + str(cn_levels[i])

        #4.其他配置
        params_dict['vpHeightF'] = 0.022 * 0.868 * (nboxes + 3 - (nboxes - 5) / 2.8)
        params_dict['lbFillColors'] = cn_fill_colors
        if (self.output_img_name.contains("TK")):
            params_dict["lbLabelFontHeightF"] = 0.009
        else:
            params_dict["lbLabelFontHeightF"] = 0.009677
        lbres = create_or_update_resource(params_dict=params_dict)
        lbid = Ngl.labelbar_ndc(self.workstation, nboxes, color_labels, 0, 0, lbres)

        #5.色标位置配置
        lblres = create_or_update_resource(params_dict=self.location_params_dict)
        Ngl.add_annotation(self.plot, lbid, lblres)
コード例 #2
0
    def contour_map(self):
        params_dict = self.params_dict

        scala_figure = params_dict.pop('scala_figure')
        lon_axis_value, lat_axis_value = params_dict.pop(
            'location', default='93x17').split("x")

        resource = create_or_update_resource(params_dict)
        Ngl.add_text(self.workstation, self.plot, scala_figure, lon_axis_value,
                     lat_axis_value, resource)
コード例 #3
0
    def contour_map(self):
        params_dict = self.params_dict
        color_levels = self.color_levels
        cn_fill_colors = np.arange(0, len(color_levels), 1)

        # 1.绘制南海底板
        south_sea_baseboard = params_dict.pop('south_sea_baseboard')
        south_sea_baseboard['cnLevels'] = color_levels
        south_sea_baseboard['cnFillColors'] = cn_fill_colors
        resource = create_or_update_resource(params_dict=south_sea_baseboard)
        south_sea_plot = Ngl.contour_map(self.workstation, self.input_data,
                                         resource)

        # 2.绘制南海相关地理线
        south_sea_geoline = params_dict.pop('south_sea_geoline')  # 多级
        for key, params_dict in south_sea_geoline.items():
            file_name = params_dict.pop('file_name')
            type = params_dict.pop('type')
            shape = Nio.open_file(shape_file_path + file_name, "r")
            lon = np.ravel(shape.variables["x"][:])
            lat = np.ravel(shape.variables["y"][:])
            params_dict['gsSegments'] = shape.variables["segments"][:, 0]
            resource = create_or_update_resource(params_dict=params_dict)
            # 2.绘制曲线图
            if type == 'polyline':
                Ngl.add_polyline(self.workstation, south_sea_plot, lon, lat,
                                 resource)
            else:
                pass  #polygon/point 处理待定

        # 3. 南海加比例尺
        south_sea_scale = params_dict.pop('south_sea_scale')
        scala_figure = south_sea_scale.pop('scala_figure')
        x, y = south_sea_scale.pop('location').split('x')
        resource = create_or_update_resource(params_dict=south_sea_scale)
        Ngl.add_text(self.workstation, south_sea_plot, scala_figure, x, y,
                     resource)

        # 4.南海放在中国的位置
        south_sea_location = params_dict.pop('south_sea_location')
        resource = create_or_update_resource(params_dict=south_sea_location)
        Ngl.add_annotation(self.plot, south_sea_plot, resource)
コード例 #4
0
 def contour_map(self):
     for key, params_dict in self.param_dict.items():
         file_name = params_dict.pop('file_name')
         type = params_dict.pop('type')
         shape = Nio.open_file(shape_file_path+file_name, "r")
         lon = np.ravel(shape.variables["x"][:])
         lat = np.ravel(shape.variables["y"][:])
         params_dict['gsSegments'] = shape.variables["segments"][:, 0]
         resource = create_or_update_resource(params_dict=params_dict)
         # 2.绘制曲线图
         if type =='polyline':
             Ngl.add_polyline(self.workstation, self.plot, lon, lat, resource)
コード例 #5
0
    def __init__(self
                 , output_img_type=''  #最终输出图片格式 例:png
                 , output_img_path=''  #最终输出图片位置,例:/usr/local/example
                 , color_levels=''   #色板配置文件
                 , wK_res_params={}  #workstation的Resource相关配置参数
                 , plot=None):

        self.__wk_res = create_or_update_resource(None, wK_res_params)
        # 判断文件路径是否存在,如果不存在,则创建,此处是创建多级目录
        if not os.path.isdir(output_img_path):
            os.makedirs(output_img_path)
        self.__wk = Ngl.open_wks(output_img_type, output_img_path, self.__wk_res)
        # workstation配置颜色
        # cmap = colorTool.getColorMap(color_cfg_file)
        Ngl.define_colormap(self.__wk, color_levels)
        self.plot = plot
コード例 #6
0
    def contour_map(self):
        resource_config = {}

        # 是否有色板配置文件
        if self.color_levels:
            cn_params_dict = {
                "cnLevels": self.color_levels
                , "cnFillColors":np.arange(0,len(self.color_levels),1).tolist()
            }
            resource_config.update(cn_params_dict)

        # 是否有用户自定义配置
        if self.params_dict:
            resource_config.update(self.params_dict)

        # 构造resource对象
        self.resource = create_or_update_resource(params_dict=resource_config)

        # 绘图
        map_plot = Ngl.contour_map(self.workstation, self.input_data, self.resource)

        return map_plot