def __init__(self, root): p = root.find("Title") # 是否按Micaps数据的标题写产品描述 self.mtitleposition = Projection.leaf_to_list(p, "MTitlePosition", None) # 产品图片文字描述(可能多个) descs = p.find("Descs").getchildren() self.descs = [] for desc in descs: txt = Projection.leaf_to_string(desc, 'Text', u'测试数据') pos = Projection.leaf_to_list(desc, "Position", [113.2, 30.5]) fonts = desc.find("Font").text.strip().split(',') font = { 'family': 'monospace', 'weight': 'bold', 'fontsize': 12, 'color': 'k' } if len(fonts) == 4: font['fontsize'] = parseInt(fonts[0].strip()) font['family'] = fonts[1] font['weight'] = fonts[2] font['color'] = fonts[3] self.descs.append(HeadDesc(txt, pos, font))
def __init__(self): super(ImageFactory, self).__init__() self.path = None self.image = None self.gray = None self.feature_extractor = Projection() self.content_extractor = Content() self.content_list = None self.feature_list = np.array([]) self.class_list = np.array([]) # for display purpose self.display = None
def __init__(self, root): leaf = root.find("File") if leaf is None: return self.type = Projection.leaf_to_string(leaf, 'Type', 'M4') self.filename = Projection.leaf_to_string(leaf, 'FileName', 'M4') if self.type == 'M4': self.micapsdata = Micaps4Data(self.filename) elif self.type == 'M3': self.micapsdata = Micaps3Data(self.filename) elif self.type == 'M11': self.micapsdata = Micaps11Data(self.filename) else: return
def __init__(self, root): leaf = root.find("UV") if leaf is None: return self.stream = Projection.leaf_to_bool(leaf, 'Stream', False) self.density = Projection.leaf_to_list(leaf, 'Density', [1, 1]) self.color = Projection.leaf_to_string(leaf, 'Color', 'k') self.onspeed = Projection.leaf_to_bool(leaf, 'OnSpeed', False) self.oncolor = Projection.leaf_to_bool(leaf, 'OnColor', False) self.linewidth = Projection.leaf_to_float(leaf, 'LineWidth', 1.) self.scale = Projection.leaf_to_int(leaf, 'Scale', 700) self.markscalelength = Projection.leaf_to_float(leaf, 'MarkScaleLength', 12.) self.barbs = Projection.leaf_to_bool(leaf, 'Barbs', False) self.length = Projection.leaf_to_int(leaf, 'Length', 1)
def __init__(self, response_file_path, capabilities_path): with open(response_file_path) as source: requests = json.load(source) self.layer_key = requests['layerKey'] self.responses = requests['results'] self.crs = Projection(self.layer_key['crs'], "EPSG:4326") # TODO: Move output crs to config self.request_url = self.responses[0]['url'].split("?")[0] self.capabilities = Capabilities(capabilities_path, self.get_layer_name(), self.crs) self.bbox = self.capabilities.bbox try: self.service_version = self.responses[0]['url'].split( "VERSION=")[1].split("&")[0] except: self.service_version = None
def __init__(self, root): leaf = root.find("Stations") self.file = Projection.leaf_to_string(leaf, 'File') self.visible = Projection.leaf_to_bool(leaf, 'Visible', False) self.markstyle = Projection.leaf_to_list(leaf, 'MarkStyle', ['o', 'full']) self.color = Projection.leaf_to_string(leaf, 'Color', 'k') self.edgecolors = Projection.leaf_to_string(leaf, 'EdgeColors', 'k') self.alpha = Projection.leaf_to_float(leaf, 'Alpha', 1.) self.radius = Projection.leaf_to_float(leaf, 'Radius', 5) self.font = Projection.leaf_to_list(leaf, 'Font', [18, 'myyh.ttc', 'bold', 'k']) self.detax = Projection.leaf_to_float(leaf, 'Detax', 0.03) self.micapsdata = Micaps17Data(self.file)
class ImageFactory(object): def __init__(self): super(ImageFactory, self).__init__() self.path = None self.image = None self.gray = None self.feature_extractor = Projection() self.content_extractor = Content() self.content_list = None self.feature_list = np.array([]) self.class_list = np.array([]) # for display purpose self.display = None def initialize(self, path_to_image): self.path = path_to_image self.image = cv2.imread(self.path) self.gray = self.__prepare_image_gray() self.content_list = self.content_extractor.new_leuven_dichotomie(self.image, self.gray) # run extract_features self.extract_features() def extract_features(self): length = len(self.content_list) self.feature_list = np.zeros((length,500)) for x in range(0, length): subImage_tmp = self.image[self.content_list[x][0][1]:self.content_list[x][1][1]+1, self.content_list[x][0][0]:self.content_list[x][1][0]+1] subGray_tmp = self.gray[self.content_list[x][0][1]:self.content_list[x][1][1]+1, self.content_list[x][0][0]:self.content_list[x][1][0]+1] self.feature_list[x] = self.feature_extractor.compute(subImage_tmp, subGray_tmp) pass pass def __prepare_image_gray(self): gray = cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY) height,width,channel = self.image.shape for x in range(0,width): gray[0][x] = 255 gray[height-1][x] = 255 for y in range(0,height): gray[y][0] = 255 gray[y][width-1] = 255 for y in range(0,height): for x in range(0,width): if gray[y][x] >= 250: gray[y][x] = 255 pass pass pass return gray def draw(self): self.display = self.image.copy() for x in range(0,len(self.class_list)): if self.class_list[x][1] == 1: self.display[self.content_list[x][0][1]:self.content_list[x][1][1]+1, self.content_list[x][0][0]:self.content_list[x][1][0]+1, 0] += 100 for x in range(0,len(self.content_list)): cv2.rectangle(self.display, self.content_list[x][0], self.content_list[x][1], (255, 0, 0), 1)
def __init__(self, root, clipborders): p = root.find("Picture") # 生成的图片宽度 self.width = Projection.leaf_to_float(p, "PicWidth", 10) # 生成的图片高度 self.height = Projection.leaf_to_float(p, "PicHeight", 10) # dpi self.dpi = Projection.leaf_to_int(p, "Dpi", 72) # 高宽比 self.widthshrink = Projection.leaf_to_float(p, "WidthShrink", 1.0) # 绘图区外延 self.margin = Projection.leaf_to_list(p, "Margin", [0, 0, 0, 0]) # 绘图区内边距 self.pad = Projection.leaf_to_float(p, "Pad", 0.0) # 绘图区域 extents = p.find("Extents").text.strip() if extents is None or extents == '': if len(clipborders) < 1 or clipborders[0].path is None or ( not clipborders[0].using): self.extents = None else: jxextend = clipborders[0].path.get_extents() delta = self.margin xmax = jxextend.xmax + delta[2] xmin = jxextend.xmin - delta[0] ymax = jxextend.ymax + delta[1] ymin = jxextend.ymin - delta[3] self.extents = Bbox.from_extents(xmin, ymin, xmax, ymax) else: self.extents = Projection.leaf_to_list(p, "Extents", None) # 画布透明度 self.opacity = Projection.leaf_to_float(p, 'Opacity', 1) if self.opacity < 0 or self.opacity > 1: self.opacity = 1 # 生成的图片文件存放路径 self.picfile = Projection.leaf_to_string(p, 'PicFile', 'mytest.png') self.checkFilename() return
def __init__(self, root): p = root.find("Title") # 是否按Micaps数据的标题写产品描述 self.mtitleposition = Projection.leaf_to_list(p, "MTitlePosition", None) # 产品图片文字描述(可能多个) descs = p.find("Descs").getchildren() self.descs = [] for desc in descs: txt = Projection.leaf_to_string(desc, 'Text', u'测试数据') pos = Projection.leaf_to_list(desc, "Position", [113.2, 30.5]) fonts = desc.find("Font").text.strip().split(',') font = {'family': 'monospace', 'weight': 'bold', 'fontsize': 12, 'color': 'k'} if len(fonts) == 4: font['fontsize'] = parseInt(fonts[0].strip()) font['family'] = fonts[1] font['weight'] = fonts[2] font['color'] = fonts[3] self.descs.append(HeadDesc(txt, pos, font))
def __init__(self, leaf): start_pos = 0 filehead = Projection.leaf_to_string(leaf, "File") filetype = Projection.leaf_to_string(leaf, "Type", 'shp') code = Projection.leaf_to_list(leaf, "Code", [360000]) drawswitch = str.upper(Projection.leaf_to_string(leaf, "Draw", 'off')) self.path = self.getPath(filehead=filehead, code=code, filetype=filetype, start_pos=start_pos) self.draw = str.upper(Projection.leaf_to_string(leaf, "Draw", 'off')) self.using = Projection.leaf_to_bool(leaf, "Using", True) self.linewidth = Projection.leaf_to_float(leaf, "LineWidth", 1) self.linecolor = Projection.leaf_to_string( leaf, "LineColor", 'k') if drawswitch == 'ON' else 'none'
def __init__(self, leaf): self.file = Projection.leaf_to_string(leaf, "File") self.filetype = str.upper(Projection.leaf_to_string(leaf, "Type", 'shp')) self.draw = Projection.leaf_to_bool(leaf, "Draw", False) # self.path = self.readPolygon(self.file) if self.filetype != 'SHP' else None # if self.draw: self.path = ClipBorder.readPath(self.file, 0) if self.filetype != 'SHP' else None self.polygon = str.upper(Projection.leaf_to_string(leaf, "Polygon", 'on')) # self.draw = Projection.leaf_to_bool(leaf, "Draw", False) self.linewidth = Projection.leaf_to_float(leaf, "LineWidth", 1) self.linecolor = Projection.leaf_to_string(leaf, "LineColor", 'k')
def __init__(self, leaf): self.file = Projection.leaf_to_string(leaf, "File") self.filetype = str.upper( Projection.leaf_to_string(leaf, "Type", 'shp')) self.draw = Projection.leaf_to_bool(leaf, "Draw", False) # self.path = self.readPolygon(self.file) if self.filetype != 'SHP' else None # if self.draw: self.path = ClipBorder.readPath(self.file, 0) if self.filetype != 'SHP' else None self.polygon = str.upper( Projection.leaf_to_string(leaf, "Polygon", 'on')) # self.draw = Projection.leaf_to_bool(leaf, "Draw", False) self.linewidth = Projection.leaf_to_float(leaf, "LineWidth", 1) self.linecolor = Projection.leaf_to_string(leaf, "LineColor", 'k')
def __init__(self, root): # 地图投影 self.projection = Projection(root[0]) # 边界集合 bordersleaf = root[0].find('Borders').getchildren() self.borders = [] for borderleaf in bordersleaf: self.borders.append(Border(borderleaf)) # clip区域集合 clipsleaf = root[0].find('ClipBorders').getchildren() self.clipborders = [] for clipleaf in clipsleaf: self.clipborders.append(ClipBorder(clipleaf)) # 站点文件 from Stations import Stations self.stations = Stations(root[0]) pass
def Draw(self, products, micapsfile, debug=True): """ 根据产品参数绘制图像 :param micapsfile: 指定绘制产品中包含的一个micapsfile :param debug: 调试状态 :param products: 产品参数 :return: """ self.UpdateData(products, micapsfile) extents = products.picture.extents xmax = extents.xmax xmin = extents.xmin ymax = extents.ymax ymin = extents.ymin # 设置绘图画板的宽和高 单位:英寸 h = products.picture.height if products.map.projection.name == 'sall': # 等经纬度投影时不用配置本身的宽度,直接根据宽高比得到 w = h * np.math.fabs( (xmax - xmin) / (ymax - ymin)) * products.picture.widthshrink else: w = products.picture.width # 创建画布 fig = plt.figure(figsize=(w, h), dpi=products.picture.dpi, facecolor="white") # 必须在前面 ax = fig.add_subplot(111) ax.spines['bottom'].set_linewidth(products.map.projection.axisthick) ax.spines['left'].set_linewidth(products.map.projection.axisthick) ax.spines['right'].set_linewidth(products.map.projection.axisthick) ax.spines['top'].set_linewidth(products.map.projection.axisthick) # 设置绘图区域 plt.xlim(xmin, xmax) plt.ylim(ymin, ymax) # 背景透明 fig.patch.set_alpha(products.picture.opacity) # 坐标系统尽可能靠近绘图区边界 fig.tight_layout(pad=products.picture.pad) clipborder = products.map.clipborders[0] # 获得产品投影 from Projection import Projection m = Projection.GetProjection(products) if m is not plt: # 用投影更新经纬度数据 self.X, self.Y = Micaps.UpdateXY(m, self.X, self.Y) # 用投影更新产品参数中涉及经纬度的数据 Micaps.Update(products, m) # 画世界底图 Map.DrawWorld(products, m) # 绘制裁切区域边界 patch = Map.DrawClipBorders(products.map.clipborders) # draw parallels and meridians. Map.DrawGridLine(products, m) cmap = nclcmaps.cmaps( micapsfile.legend.micapslegendcolor) # cm.jet temp_diff_18lev vmax = math.ceil(self.max) vmin = math.floor(self.min) levels = arange(vmin - self.distance, vmax + self.distance + 0.1, self.distance) if micapsfile.legend.micapslegendvalue: level = levels else: level = micapsfile.legend.legendvalue # 绘制等值线 ------ 等值线和标注是一体的 c = micapsfile.contour Map.DrawContourAndMark(contour=c, x=self.X, y=self.Y, z=self.Z, level=level, clipborder=clipborder, patch=patch, m=m) cf = micapsfile.contour cbar = micapsfile.legend extend = micapsfile.legend.extend # 绘制色斑图 ------ 色版图、图例、裁切是一体的 Map.DrawContourfAndLegend(contourf=cf, legend=cbar, clipborder=clipborder, patch=patch, cmap=cmap, levels=levels, extend=extend, extents=extents, x=self.X, y=self.Y, z=self.Z, m=m) # 绘制描述文本 MicapsFile.MicapsFile.DrawTitle(m, micapsfile.title, self.title) self.DrawUV(m, micapsfile, clipborder, patch) # 绘制地图 Map.DrawBorders(m, products) # 绘制散点 if micapsfile.contour.scatter: if hasattr(self, 'x1'): m.scatter(self.x1, self.y1, s=micapsfile.contour.radius, c=self.z1, alpha=micapsfile.contour.alpha, edgecolors='b') else: m.scatter(self.X, self.Y, s=micapsfile.contour.radius, c=self.Z, alpha=micapsfile.contour.alpha, edgecolors='b') # 绘制站点 stations = products.map.stations if stations.visible: # 'code': code, 'lon': lon, 'lat': lat, 'height': height, # 'iclass': iclass, 'infosum': infosum, 'name': info[0] # stations_tuple = tuple(stations.micapsdata.stations) # (code, lat, lon, height, iclass, infosum, info[0]) # stations_array = np.array(stations.micapsdata.stations, dtype=[ # ('code', 'U'), # ('lat', np.float32), # ('lon', np.float32), # ('height', np.float32), # ('iclass', 'i'), # ('infosum', 'i'), # ('info', 'U') # ]) # stations_array = [list(ele) for ele in zip(*stations.micapsdata.stations)] stations_array = zip(*stations.micapsdata.stations) # 画站点mark if m is not plt: stations_array[2], stations_array[1] = \ Micaps.UpdateXY(m, stations_array[2], stations_array[1]) marker = MarkerStyle(stations.markstyle[0], stations.markstyle[1]) m.scatter(stations_array[2], stations_array[1], marker=marker, s=stations.radius, c=stations.color, alpha=stations.alpha, edgecolors=stations.edgecolors) # 画站点文本 fontfile = r"C:\WINDOWS\Fonts\{0}".format(stations.font[1]) if not os.path.exists(fontfile): font = FontProperties(size=stations.font[0], weight=stations.font[2]) else: font = FontProperties(fname=fontfile, size=stations.font[0], weight=stations.font[2]) for sta in stations.micapsdata.stations: if m is not plt: lon, lat = Micaps.UpdateXY(m, sta[2], sta[1]) lon1, lat1 = Micaps.UpdateXY(m, sta[2] + stations.detax, sta[1]) deta = lon1 - lon else: lon, lat = sta[2], sta[1] deta = stations.detax plt.text(lon + deta, lat, sta[6], fontproperties=font, rotation=0, color=stations.font[3], ha='left', va='center') # 接近收尾 # self.Clip(clipborder, fig, patch) # 存图 Picture.savePicture(fig, products.picture.picfile) print(products.picture.picfile + u'存图成功!') if debug: plt.show()
def __init__(self, root): p = root.find("Legend") if p is None: print(u'没有图例节点') return # 图例图片文件路径,图例叠加到产品图上的位置,为空表示自行生成图例 legend_pic = p.find("LegendPic").text self.islegendpic = False self.legendpic = '' self.legendpos = [0, 0] self.legendopacity = 1 if not (legend_pic is None or legend_pic.strip() == ''): self.islegendpic = True legend_pics = legend_pic.strip().split(',') if 1 == len(legend_pics): self.legendpic = legend_pics[0].strip() elif 4 == len(legend_pics): self.legendpic = legend_pics[0].strip() self.legendpos = [float(legend_pics[1].strip()), float(legend_pics[2].strip())] self.legendopacity = float(legend_pics[3].strip()) else: self.legendpic = legend_pics[0].strip() # 图例的延展类型:neither,min,max default is neither self.extend = Projection.leaf_to_string(p, 'Extend', 'neither') # 是否取MICAPS数据本身的图例值 self.micapslegendvalue = Projection.leaf_to_bool(p, "MicapsLegendValue", True, 'TRUE') # When micapslegendvalue is true, the setting is working. # if pin the legend values, [begin value, stop value, step] is working.default is None # else use the data self legend values self.pinlegendvalue = Projection.leaf_to_list(p, "PinLegendValue", None) self.valid(self.pinlegendvalue) # NCL colorbar 的别名 self.micapslegendcolor = Projection.leaf_to_string(p, 'MicapsLegendColor', 'ncl_default') # 图例填充样式数组,一般和自定义的legend结合使用,如不够LegendValue数组的长度,则会用最后一个样式自动补齐 self.hatches = Projection.leaf_to_list(p, "Hatches", ['']) self.validhatches(self.hatches) # 图例等级值 self.legendvalue = Projection.leaf_to_list(p, "LegendValue", None) # 实际显示在图例上的值 self.legendvaluealias = Projection.leaf_to_list(p, "LegendValueAlias", None) # 图例颜色值 self.legendcolor = Projection.leaf_to_list(p, "LegendColor", None) # 图例抽稀间隔 self.thinning = Projection.leaf_to_int(p, "Thinning", 1) # 图例字体 self.font = Projection.leaf_to_dict(p, "Font", None) # 图例标题 self.title = Projection.leaf_to_string(p, 'Title', '') # 图例标题字体 self.titlefont = Projection.leaf_to_dict(p, "TitleFont", None) # 图例标题位置 self.titlepos = Projection.leaf_to_dict(p, "TitlePos", {'rotation': 90, 'va': 'top', 'ha': 'center', 'ypercent': 0.5}) # ---------- 无投影时的图例配置 start -------- # 图例放置方式 self.orientation = Projection.leaf_to_string(p, 'Orientation', 'vertical') # 图例离边框位置 self.anchor = Projection.leaf_to_list(p, "Anchor", [0, 0]) # 图例收缩系数 self.shrink = Projection.leaf_to_float(p, "Shrink", 1) self.fraction = Projection.leaf_to_float(p, 'Fraction', 0.15) # ---------- 有投影时的图例配置 start -------- # 图例收缩系数 self.size = Projection.leaf_to_string(leaf=p, code='Size', defvalue='5%') # 图例离边框位置 self.pad = Projection.leaf_to_string(leaf=p, code='Pad', defvalue='2%') # 图例放置位置 self.location = Projection.leaf_to_string(leaf=p, code='Location', defvalue='right')
def Draw(self, products, debug=True): """ 根据产品参数绘制图像 :param debug: :param products: :return: 产品参数 """ # 图例的延展类型 origin = 'lower' if self.title.find(u'降水') >= 0 or self.title.find(u'雨'): extend = 'max' else: extend = 'neither' # 更新绘图矩形区域 # self.UpdateExtents(products) self.UpdateData(products) xmax = products.extents.xmax xmin = products.extents.xmin ymax = products.extents.ymax ymin = products.extents.ymin # 设置绘图画板的宽和高 单位:英寸 h = products.height if products.projection.name == 'sall': # 等经纬度投影时不用配置本身的宽度,直接根据宽高比得到 w = h * np.math.fabs((xmax - xmin) / (ymax - ymin)) * products.widthshrink else: w = products.width # 创建画布 fig = plt.figure(figsize=(w, h), dpi=products.dpi, facecolor="white") # 必须在前面 # ax = fig.add_subplot(111) # 设置绘图区域 plt.xlim(xmin, xmax) plt.ylim(ymin, ymax) # 背景透明 fig.patch.set_alpha(products.opacity) # 坐标系统尽可能靠近绘图区边界 fig.tight_layout(pad=products.pad) # 获得产品投影 from Projection import Projection m = Projection.GetProjection(products) if m is not plt: # 用投影更新经纬度数据 self.X, self.Y = Micaps.UpdateXY(m, self.X, self.Y) # 用投影更新产品参数中涉及经纬度的数据 Micaps.Update(products, m) if products.projection.coastlines: m.drawcoastlines(linewidth=0.25) if products.projection.countries: m.drawcountries(linewidth=0.25) # draw parallels and meridians. if products.projection.axis == 'on': m.drawparallels(np.arange(-80., 81., 10.), labels=products.projection.latlabels, family='DejaVu Sans', fontsize=10) m.drawmeridians(np.arange(-180., 181., 10.), labels=products.projection.lonlabels, family='DejaVu Sans', fontsize=10) if products.projection.lsmask['visible']: m.drawlsmask(land_color=products.projection.lsmask['land_color'], ocean_color=products.projection.lsmask['ocean_color'], resolution='l') else: # 坐标轴 plt.axis(products.projection.axis) # 设置坐标轴刻度值显示格式 if products.projection.axis == 'on': x_majorFormatter = FormatStrFormatter('%d°E') y_majorFormatter = FormatStrFormatter('%d°N') plt.gca().xaxis.set_major_formatter(x_majorFormatter) plt.gca().yaxis.set_major_formatter(y_majorFormatter) xaxis = plt.gca().xaxis for label in xaxis.get_ticklabels(): label.set_fontproperties('DejaVu Sans') label.set_fontsize(10) yaxis = plt.gca().yaxis for label in yaxis.get_ticklabels(): label.set_fontproperties('DejaVu Sans') label.set_fontsize(10) # 绘制裁切区域边界 if products.cutborders[0]['path'] is not None: patch = patches.PathPatch(products.cutborders[0]['path'], linewidth=products.cutborders[0]['linewidth'], facecolor='none', edgecolor=products.cutborders[0]['linecolor']) plt.gca().add_patch(patch) else: patch = None # 绘制地图 Micaps.DrawBorders(m, products) cmap = nclcmaps.cmaps(products.micapslegendcolor) # cm.jet temp_diff_18lev vmax = math.ceil(self.max) vmin = math.floor(self.min) levels = arange(vmin - self.distance, vmax + self.distance + 0.1, self.distance) if products.micapslegendvalue: level = levels else: level = products.legendvalue # 是否绘制等值线 ------ 等值线和标注是一体的 if products.contour['visible']: matplotlib.rcParams['contour.negative_linestyle'] = 'dashed' if products.contour['colorline']: CS1 = m.contour(self.X, self.Y, self.Z, levels=level, linewidths=products.contour['linewidth']) else: CS1 = m.contour(self.X, self.Y, self.Z, levels=level, linewidths=products.contour['linewidth'], colors=products.contour['linecolor']) # 用区域边界裁切等值线图 if not products.cutborders[0]['path'] is None and products.cutborders[0]['using']: for collection in CS1.collections: collection.set_clip_on(True) collection.set_clip_path(patch) # 是否绘制等值线标注 if products.contourlabel['visible']: plt.clabel(CS1, inline=1, fmt=products.contourlabel['fmt'], fontsize=products.contourlabel['fontsize'], colors=products.contourlabel['fontcolor']) # 是否绘制色斑图 ------ 色版图、图例、裁切是一体的 if products.contourfvisible: # 绘制色斑图 if products.micapslegendvalue: CS = m.contourf(self.X, self.Y, self.Z, cmap=cmap, levels=levels, extend=extend, orientation='vertical', origin=origin) else: CS = m.contourf(self.X, self.Y, self.Z, # cax=axins, levels=products.legendvalue, colors=products.legendcolor, extend=extend, orientation='vertical', origin=origin) # 用区域边界裁切色斑图 if products.cutborders[0]['path'] is not None and products.cutborders[0]['using']: for collection in CS.collections: collection.set_clip_on(True) collection.set_clip_path(patch) if m is plt: # 插入一个新坐标系 以使图例在绘图区内部显示 ax2 = plt.gca() axins = inset_axes(ax2, width="100%", height="100%", loc=1, borderpad=0) axins.axis('off') axins.margins(0, 0) axins.xaxis.set_ticks_position('bottom') axins.yaxis.set_ticks_position('left') axins.set_xlim(xmin, xmax) axins.set_ylim(ymin, ymax) # 画图例 if products.islegendpic: # 插入图片 arr_lena = read_png(products.legendpic) image_box = OffsetImage(arr_lena, zoom=products.legendopacity) ab = AnnotationBbox(image_box, products.legendpos, frameon=False) plt.gca().add_artist(ab) else: ticks = fmt = None CB = plt.colorbar(CS, cmap='RdBu', anchor=products.anchor, shrink=products.shrink, ticks=ticks, # fraction=0.15, # products.fraction, drawedges=True, # not products.micapslegendvalue, filled=False, spacing='uniform', use_gridspec=False, orientation=products.orientation, # extendfrac='auto', format=fmt ) else: cb = m.colorbar(CS, location=products.projection.location, size=products.projection.size, pad=products.projection.pad) # 绘制描述文本 Micaps.DrawTitle(m, products, self.title) # 存图 fig.savefig(products.picfile, format='png', transparent=False) print(products.picfile + u'存图成功!') if debug: plt.show()
def __init__(self, xmlfile): self.xmlfile = xmlfile if not os.path.exists(self.xmlfile): return try: tree = ElementTree.parse(self.xmlfile) root = tree.getroot() products = root.getchildren() p = products[0] # M1:站点数据,M4:第4类格点数据,M11:第11类UV数据 self.odatatype = Projection.leaf_to_string(p, "OriginalDataType") # 原始数据文件路径 self.ofile = Projection.leaf_to_string(p, "OriginalFile") if self.odatatype == 'M4': self.micapsdata = Micaps4Data(self.ofile) elif self.odatatype == 'M3': self.micapsdata = Micaps3Data(self.ofile) else: return # 地图投影 self.projection = Projection(p) # 地图边界文件路径,仅用于绘制边界 mapborders = p.find("MapBorders").getchildren() self.mapborders = [] for border in mapborders: mapfile = Projection.leaf_to_string(border, "File") filetype = str.upper( Projection.leaf_to_string(border, "Type", 'shp')) polygonswitch = str.upper( Projection.leaf_to_string(border, "Polygon", 'on')) mbdict = { 'file': mapfile, 'filetype': filetype, 'path': self.readPolygon(mapfile) if filetype != 'SHP' else None, 'polygon': polygonswitch, 'draw': Projection.leaf_to_bool(border, "Draw", False), 'linewidth': Projection.leaf_to_float(border, "LineWidth", 1), 'linecolor': Projection.leaf_to_string(border, "LineColor", 'k') } self.mapborders.append(mbdict) # 裁剪边界文件路径,用于对色斑图进行裁剪 cutborders = p.find("CutBorders").getchildren() self.cutborders = [] for border in cutborders: filehead = Projection.leaf_to_string(border, "File") filetype = Projection.leaf_to_string(border, "Type", 'shp') code = Projection.leaf_to_list(border, "Code", [360000]) drawswitch = str.upper( Projection.leaf_to_string(border, "Draw", 'off')) linecolor = Projection.leaf_to_string( border, "LineColor", 'k') if drawswitch == 'ON' else 'none' mbdict = { 'path': self.getPath(filehead=filehead, code=code, filetype=filetype), 'draw': drawswitch, 'using': Projection.leaf_to_bool(border, "Using", True), 'linewidth': Projection.leaf_to_float(border, "LineWidth", 1), 'linecolor': linecolor } self.cutborders.append(mbdict) # 生成的图片宽度 self.width = Projection.leaf_to_float(p, "PicWidth", 10) # 生成的图片高度 self.height = Projection.leaf_to_float(p, "PicHeight", 10) # dpi self.dpi = Projection.leaf_to_int(p, "Dpi", 72) # 高宽比 self.widthshrink = Projection.leaf_to_float(p, "WidthShrink", 1.0) # 绘图区外延 self.margin = Projection.leaf_to_float(p, "Margin", 0.0) # 绘图区内边距 self.pad = Projection.leaf_to_float(p, "Pad", 0.0) # 绘图区域 extents = p.find("Extents").text.strip() if extents is None or extents == '': if len(self.cutborders ) < 1 or self.cutborders[0]['path'] is None: self.extents = None else: jxextend = self.cutborders[0]['path'].get_extents() delta = self.margin xmax = jxextend.xmax + delta xmin = jxextend.xmin - delta ymax = jxextend.ymax + delta ymin = jxextend.ymin - delta self.extents = Bbox.from_extents(xmin, ymin, xmax, ymax) else: self.extents = Projection.leaf_to_list(p, "Extents", None) # 画布透明度 self.opacity = Projection.leaf_to_float(p, 'Opacity', 1) if self.opacity < 0 or self.opacity > 1: self.opacity = 1 # 生成的图片文件存放路径 self.picfile = Projection.leaf_to_string(p, 'PicFile', 'mytest.png') Products.checkFilename(self.picfile) # 图例图片文件路径,图例叠加到产品图上的位置,为空表示自行生成图例 legend_pic = p.find("LegendPic").text self.islegendpic = False self.legendpic = '' self.legendpos = [0, 0] self.legendopacity = 1 if not (legend_pic is None or legend_pic.strip() == ''): self.islegendpic = True legend_pics = legend_pic.strip().split(',') if 1 == len(legend_pics): self.legendpic = legend_pics[0].strip() elif 4 == len(legend_pics): self.legendpic = legend_pics[0].strip() self.legendpos = [ float(legend_pics[1].strip()), float(legend_pics[2].strip()) ] self.legendopacity = float(legend_pics[3].strip()) else: self.legendpic = legend_pics[0].strip() # 是否取MICAPS数据本身的图例值 self.micapslegendvalue = Projection.leaf_to_bool( p, "MicapsLegendValue", True, 'TRUE') # 第三类数据等值线步长 self.step = Projection.leaf_to_float(p, 'Step', 2.) # NCL colorbar 的别名 self.micapslegendcolor = Projection.leaf_to_string( p, 'MicapsLegendColor', 'ncl_default') # 图例等级值 self.legendvalue = Projection.leaf_to_list(p, "LegendValue", None) # 图例颜色值 self.legendcolor = Projection.leaf_to_list(p, "LegendColor", None) # 图例放置方式 self.orientation = Projection.leaf_to_string( p, 'Orientation', 'vertical') # 图例离边框位置 self.anchor = Projection.leaf_to_list(p, "Anchor", [0, 0]) # 图例收缩系数 self.shrink = Projection.leaf_to_float(p, "Shrink", 1) self.fraction = Projection.leaf_to_float(p, 'Fraction', 0.15) # 是否按Micaps数据的标题写产品描述 self.mtitleposition = Projection.leaf_to_list( p, "MTitlePosition", None) # 经纬方向上的插值格点数 self.grid = Projection.leaf_to_list(p, "Grid", [195, 216]) if len(self.grid) != 2: self.grid = [195, 216] else: self.grid = [parseInt(str(g)) for g in self.grid] # 等值线参数 # self.contourvisible = Projection.leaf_to_bool(p, "ContourVisible", False, 'TRUE') contourleaf = p.find("Contour") if contourleaf is None: self.contour = { 'visible': False, 'linewidth': 1.0, 'linecolor': 'k', 'colorline': False } else: self.contour = { 'visible': Projection.leaf_to_bool(contourleaf, "Visible", False, 'TRUE'), 'linewidth': Projection.leaf_to_float(contourleaf, 'LineWidth', 1.0), 'linecolor': Projection.leaf_to_string(contourleaf, 'LineColor', 'k'), 'colorline': Projection.leaf_to_bool(contourleaf, "ColorLine", False, 'TRUE') } # 是否显示色斑图 self.contourfvisible = Projection.leaf_to_bool( p, "ContourfVisible", False, 'TRUE') # 等值线标注参数 # self.contourlabelvisible = Projection.leaf_to_bool(p, "ContourLabelVisible", False, 'TRUE') leaf = p.find("ContourLabel") if leaf is None: self.contourlabel = { 'visible': False, 'fmt': '%1.0f', 'fontsize': 12, 'fontcolor': 'k' } else: self.contourlabel = { 'visible': Projection.leaf_to_bool(leaf, "Visible", False, 'TRUE'), 'fmt': Projection.leaf_to_string(leaf, 'Fmt', '%1.0f'), 'fontsize': Projection.leaf_to_float(leaf, 'FontSize', 12), 'fontcolor': Projection.leaf_to_string(leaf, 'FontColor', 'k') } # 产品图片文字描述(可能多个) descs = p.find("Descs").getchildren() self.descs = [] for desc in descs: txt = Projection.leaf_to_string(desc, 'Text', u'测试数据') pos = Projection.leaf_to_list(desc, "Position", [113.2, 30.5]) fonts = desc.find("Font").text.strip().split(',') font = { 'family': 'monospace', 'weight': 'bold', 'fontsize': 12, 'color': 'k' } if len(fonts) == 4: font['fontsize'] = parseInt(fonts[0].strip()) font['family'] = fonts[1] font['weight'] = fonts[2] font['color'] = fonts[3] self.descs.append(HeadDesc(txt, pos, font)) except Exception as err: print(u'【{0}】{1}-{2}'.format(self.xmlfile, err, datetime.now())) return None
class InputData(): def __init__(self, response_file_path, capabilities_path): with open(response_file_path) as source: requests = json.load(source) self.layer_key = requests['layerKey'] self.responses = requests['results'] self.crs = Projection(self.layer_key['crs'], "EPSG:4326") # TODO: Move output crs to config self.request_url = self.responses[0]['url'].split("?")[0] self.capabilities = Capabilities(capabilities_path, self.get_layer_name(), self.crs) self.bbox = self.capabilities.bbox try: self.service_version = self.responses[0]['url'].split( "VERSION=")[1].split("&")[0] except: self.service_version = None def get_crs_name(self): return self.layer_key['crs'] def get_layer_name(self): return self.layer_key['layerName'] def get_service_type(self): return self.capabilities._get_service() def get_bboxes_as_geojson(self): ''' This method converts response file to geojson geometries. imageAnalysisResult is included to the geojson features. returns: list of geojson elements ''' features = [] extent = self.bbox invalid_request_count = 0 bbox_out_count = 0 count = 0 coords_min = [float('inf'), float('inf')] coords_max = [float('-inf'), float('-inf')] logging.info("Creating geojson objects.") for res in self.responses: count += 1 if count % 1000 == 0: logging.debug("Result no. {}".format(count)) # Filter out invalid test results if ('imageAnalysisResult' not in res.keys() or 'testResult' not in res.keys() or res['testResult'] != 0): invalid_request_count += 1 continue # Convert bbox as a list. bbox = list(map(float, res['bBox'].split(','))) if not self.crs.is_first_axis_east(): bbox = change_bbox_axis_order(bbox) # Tolerance helps to handle rounding problems in the border areas. unit = self.crs.get_coordinate_unit().lower() tolerance = 1 if unit == 'metre' else 0.000001 inside = [ bbox[0] >= extent[0] - tolerance, bbox[1] >= extent[1] - tolerance, bbox[2] <= extent[2] + tolerance, bbox[3] <= extent[3] + tolerance, ] # Filter out requests out of the interest area if not all(inside): bbox_out_count += 1 continue if bbox_out_count == 0: for i in range(len(coords_min)): if bbox[i] < coords_min[i]: coords_min[i] = bbox[i] for i in range(len(coords_max)): if bbox[i + len(coords_max)] > coords_max[i]: coords_max[i] = bbox[i + len(coords_max)] # Create a closed Polygon following the edges of the bbox. g = Polygon([[(bbox[0], bbox[1]), (bbox[0], bbox[3]), (bbox[2], bbox[3]), (bbox[2], bbox[1]), (bbox[0], bbox[1])]]) # Save other data props = { 'imageAnalysisResult': res['imageAnalysisResult'], 'testResult': res['testResult'], 'requestTime': res['requestTime'] } feat = Feature(geometry=g, properties=props) features.append(feat) if invalid_request_count > 0: logging.info( "Filtered {} requests away due to failed request.".format( invalid_request_count)) if bbox_out_count > 0: logging.info( "Filtered {} requests way because request bbox was not completely within layer bbox" .format(bbox_out_count)) #TODO: this needs to be a square; now it isn't '''else: self.bbox = coords_min + coords_max logging.info("Bounding box set to the extent of all requests to {}".format(self.bbox))''' feat_c = FeatureCollection(features) return feat_c
Miner(hashRate=3450, startDate='6/4/2018', days=90), Miner(hashRate=1000, startDate='6/5/2018', days=90), Miner(hashRate=1270, startDate='6/7/2018', days=90), Miner(hashRate=1900, startDate='6/9/2018', days=90), Miner(hashRate=1540, startDate='6/11/2018', days=90), Miner(hashRate=1300, startDate='6/13/2018', days=90), Miner(hashRate=1070, startDate='6/14/2018', days=90), Miner(hashRate=3000, startDate='6/17/2018', days=90), Miner(hashRate=4800, startDate='6/27/2018', days=90), Miner(hashRate=6500, startDate='7/3/2018', days=90), Miner(hashRate=3700, startDate='7/7/2018', days=90), Miner(hashRate=11950, startDate='7/9/2018', days=90) ] print "End Date Main Referral Total Profit % Min Buy (GHS)" projection = Projection(startDate=miners[-1].startDate, miners=miners) referralProjection = projection.clone(True) printProjection(projection, referralProjection, totalInvested) bestProfit = 0 best = None for i in range(10): print "\n============= week " + str(i) + " =============" for minGHS in np.arange(1, 7.5, 0.05): clone = projection.clone() reinvestiment = Reinvestment( projection=clone, days=7*(i+1), minWait=0, minBuy=minGHS,
def init_dims(self): a_stationlist = os.path.join(self.install.A_IN_DATA_DIR, str(self.sim_id), self.station_file) if not os.path.isfile(a_stationlist): a_stationlist = os.path.join(os.getcwd(), self.station_file) if not os.path.isfile(a_stationlist): print("Error (plot_value_map): Unable to locate station file: " "%s!" % self.station_file) sys.exit() self.station_file = a_stationlist print("Using Station File: %s" % (self.station_file)) # a_statfile = (self.install.A_IN_DATA_DIR + # "/%d/%s"%(self.sim_id,self.station_file)) slo = StationList(self.station_file) site_list = slo.getStationList() w_lon = 0.0 e_lon = 0.0 n_lat = 0.0 s_lat = 0.0 for sites in site_list: slon = float(sites.lon) slat = float(sites.lat) if w_lon == 0.0: w_lon = slon elif slon < w_lon: w_lon = slon if e_lon == 0.0: e_lon = slon elif slon > e_lon: e_lon = slon if n_lat == 0.0: n_lat = slat elif slat > n_lat: n_lat = slat if s_lat == 0.0: s_lat = slat elif slat < s_lat: s_lat = slat self.rbounds = [(n_lat + 0.1), (s_lat - 0.1), (e_lon + 0.1), (w_lon - 0.1)] print("Region Bounds: ", self.rbounds) self.nw = (self.rbounds[3], self.rbounds[0]) self.sw = (self.rbounds[3], self.rbounds[1]) self.se = (self.rbounds[2], self.rbounds[1]) self.ne = (self.rbounds[2], self.rbounds[0]) self.PLOT_MAP_LOC = [0.10, 0.15, 0.8, 0.8] self.origin = self.nw # North - West Corner self.x_invert = False self.y_invert = True rzone = 11 # if self.region != None: # if self.region.getName() == "Northern California": # rzone = 10 # print "Region : %s, UTM Zone: %d" % (self.region.getName(), rzone) # else: print("Region : None, UTM Zone: %d" % (rzone)) pobj = Proj(proj='utm', zone=rzone, ellps='WGS84') self.offset = map(round, pobj(self.origin[0], self.origin[1])) #Calculate region dimension in km dim_y = math.ceil(GS.get_distance(self.nw, self.sw)) * ( 1000.0 / self.dx) #(KM*1000/dx) dim_x = math.ceil(GS.get_distance(self.sw, self.se)) * (1000.0 / self.dx) dim_z = 1.0 * (1000.0 / self.dx ) #Just want to plot surface so we use 1 KM for Z self.dim = [int(dim_x), int(dim_y), int(dim_z)] # print "Self.dx, self.offset, self.dim:", self.dx, self.offset, self.dim self.projobj = Projection(self.dx, self.dim, self.offset, "utm", rzone) self.build_station_list(self.station_file) self.boundfile = self.build_coastline(self.coast_file, self.projobj, self.offset, self.dx, self.dim, self.x_invert, self.y_invert) return
def __init__(self, root): p = root.find("Contour") # 是否用彩色圆点标注格点或站点 self.scatter = Projection.leaf_to_bool(p, 'Scatter', False) # 圆点的透明度 self.alpha = Projection.leaf_to_float(p, 'Alpha', 1) # 圆点半径 default is 10 self.radius = Projection.leaf_to_float(p, 'Radius', 10) # 第三类数据等值线步长 self.step = Projection.leaf_to_float(p, 'Step', 2.) # 经纬方向上的插值格点数 self.grid = Projection.leaf_to_list(p, "Grid", [195, 216]) if len(self.grid) != 2: self.grid = [195, 216] else: self.grid = [parseInt(str(g)) for g in self.grid] # 等值线参数 contourleaf = p.find("Contour") if contourleaf is None: self.contour = { 'visible': False, 'linewidth': 1.0, 'linecolor': 'k', 'colorline': False } else: self.contour = { 'visible': Projection.leaf_to_bool(contourleaf, "Visible", False, 'TRUE'), 'linewidth': Projection.leaf_to_float(contourleaf, 'LineWidth', 1.0), 'linecolor': Projection.leaf_to_string(contourleaf, 'LineColor', 'k'), 'colorline': Projection.leaf_to_bool(contourleaf, "ColorLine", False, 'TRUE') } # 是否显示色斑图 self.contourfvisible = Projection.leaf_to_bool(p, "ContourfVisible", False, 'TRUE') # 等值线标注参数 leaf = p.find("ContourLabel") if leaf is None: self.contourlabel = { 'visible': False, 'fmt': '%1.0f', 'fontsize': 12, 'fontcolor': 'k', 'inlinespacing': 2 } else: self.contourlabel = { 'visible': Projection.leaf_to_bool(leaf, "Visible", False, 'TRUE'), 'fmt': Projection.leaf_to_string(leaf, 'Fmt', '%1.0f'), 'fontsize': Projection.leaf_to_float(leaf, 'FontSize', 12), 'fontcolor': Projection.leaf_to_string(leaf, 'FontColor', 'k'), 'inlinespacing': Projection.leaf_to_float(leaf, 'InlineSpacing', 2) }
def __init__(self, root): leaf = root.find("UV") if leaf is None: return self.stream = Projection.leaf_to_bool(leaf, 'Stream', False) self.density = Projection.leaf_to_list(leaf, 'Density', [1, 1]) self.barbsgrid = Projection.leaf_to_list(leaf, 'BarbsGrid', [31, 31]) self.color = Projection.leaf_to_string(leaf, 'Color', 'k') self.onspeed = Projection.leaf_to_bool(leaf, 'OnSpeed', False) self.wholecilp = Projection.leaf_to_bool(leaf, 'WholeClip', False) self.oncolor = Projection.leaf_to_bool(leaf, 'OnColor', False) self.linewidth = Projection.leaf_to_float(leaf, 'LineWidth', 1.) self.scale = Projection.leaf_to_int(leaf, 'Scale', 700) self.markscalelength = Projection.leaf_to_float(leaf, 'MarkScaleLength', 12.) self.barbs = Projection.leaf_to_bool(leaf, 'Barbs', False) self.length = Projection.leaf_to_int(leaf, 'Length', 1)
def __init__(self, root): p = root.find("Contour") # 是否用彩色圆点标注格点或站点 self.scatter = Projection.leaf_to_bool(p, 'Scatter', False) # 圆点的透明度 self.alpha = Projection.leaf_to_float(p, 'Alpha', 1) # 圆点半径 default is 10 self.radius = Projection.leaf_to_float(p, 'Radius', 10) # 第三类数据等值线步长 self.step = Projection.leaf_to_float(p, 'Step', 2.) # 经纬方向上的插值格点数 self.grid = Projection.leaf_to_list(p, "Grid", [195, 216]) if len(self.grid) != 2: self.grid = [195, 216] else: self.grid = [parseInt(str(g)) for g in self.grid] # 等值线参数 contourleaf = p.find("Contour") if contourleaf is None: self.contour = {'visible': False, 'linewidth': 1.0, 'linecolor': 'k', 'colorline': False} else: self.contour = { 'visible': Projection.leaf_to_bool(contourleaf, "Visible", False, 'TRUE'), 'linewidth': Projection.leaf_to_float(contourleaf, 'LineWidth', 1.0), 'linecolor': Projection.leaf_to_string(contourleaf, 'LineColor', 'k'), 'colorline': Projection.leaf_to_bool(contourleaf, "ColorLine", False, 'TRUE') } # 是否显示色斑图 self.contourfvisible = Projection.leaf_to_bool(p, "ContourfVisible", False, 'TRUE') # 等值线标注参数 leaf = p.find("ContourLabel") if leaf is None: self.contourlabel = {'visible': False, 'fmt': '%1.0f', 'fontsize': 12, 'fontcolor': 'k', 'inlinespacing': 2} else: self.contourlabel = { 'visible': Projection.leaf_to_bool(leaf, "Visible", False, 'TRUE'), 'fmt': Projection.leaf_to_string(leaf, 'Fmt', '%1.0f'), 'fontsize': Projection.leaf_to_float(leaf, 'FontSize', 12), 'fontcolor': Projection.leaf_to_string(leaf, 'FontColor', 'k'), 'inlinespacing': Projection.leaf_to_float(leaf, 'InlineSpacing', 2) }
0.05 * x[10] + 5 + x[18] - x[21], 0.05 * x[11] + 5 + x[17] - x[22], 0.05 * x[12] + 5 + x[18] - x[22], 0.05 * x[13] + 5 + x[19] - x[23], 0.05 * x[14] + 5 + x[20] - x[23], 0.05 * x[15] + 5 + x[19] - x[24], 0.05 * x[16] + 5 + x[20] - x[24], x[1] + x[2] - x[9] - x[11], x[3] + x[4] - x[10] - x[12], x[5] + x[6] - x[13] - x[15], x[7] + x[8] - x[14] - x[16], x[9] + x[10] + 2 * x[21] - 1000, x[11] + x[12] + 2 * x[22] - 1000, x[13] + x[14] + 2 * x[23] - 1000, x[15] + x[16] + 2 * x[24] - 1000, )) return ret from Projection import Projection import pickle algo = Projection(0.5, 0.5, max_iter=1e5) start = np.zeros(25) print(algo.run(F, start)) print(algo.step) algo.dump() # # algo = Projection(0.5, 0.5, max_iter=1e4) # start = np.zeros(25) # print(algo.run(F, start))
def __init__(self, root): p = root.find("Legend") if p is None: print(u'没有图例节点') return # 图例图片文件路径,图例叠加到产品图上的位置,为空表示自行生成图例 legend_pic = p.find("LegendPic").text self.islegendpic = False self.legendpic = '' self.legendpos = [0, 0] self.legendopacity = 1 if not (legend_pic is None or legend_pic.strip() == ''): self.islegendpic = True legend_pics = legend_pic.strip().split(',') if 1 == len(legend_pics): self.legendpic = legend_pics[0].strip() elif 4 == len(legend_pics): self.legendpic = legend_pics[0].strip() self.legendpos = [float(legend_pics[1].strip()), float(legend_pics[2].strip())] self.legendopacity = float(legend_pics[3].strip()) else: self.legendpic = legend_pics[0].strip() # 图例的延展类型:neither,min,max default is neither self.extend = Projection.leaf_to_string(p, 'Extend', 'neither') # 是否取MICAPS数据本身的图例值 self.micapslegendvalue = Projection.leaf_to_bool(p, "MicapsLegendValue", True, 'TRUE') # When micapslegendvalue is true, the setting is working. # if pin the legend values, [begin value, stop value, step] is working.default is None # else use the data self legend values self.pinlegendvalue = Projection.leaf_to_list(p, "PinLegendValue", None) self.valid(self.pinlegendvalue) # NCL colorbar 的别名 self.micapslegendcolor = Projection.leaf_to_string(p, 'MicapsLegendColor', 'ncl_default') # 图例填充样式数组,一般和自定义的legend结合使用,如不够LegendValue数组的长度,则会用最后一个样式自动补齐 self.hatches = Projection.leaf_to_list(p, "Hatches", ['']) self.validhatches(self.hatches) # 图例等级值 self.legendvalue = Projection.leaf_to_list(p, "LegendValue", None) # 实际显示在图例上的值 self.legendvaluealias = Projection.leaf_to_list(p, "LegendValueAlias", None) # 图例颜色值 self.legendcolor = Projection.leaf_to_list(p, "LegendColor", None) # 图例抽稀间隔 self.thinning = Projection.leaf_to_int(p, "Thinning", 1) # 图例字体 self.font = Projection.leaf_to_dict(p, "Font", None) # 图例标题 self.title = Projection.leaf_to_string(p, 'Title', '') # 图例标题字体 self.titlefont = Projection.leaf_to_dict(p, "TitleFont", None) # 图例标题位置 self.titlepos = Projection.leaf_to_dict(p, "TitlePos", { 'rotation': 90, 'va': 'top', 'ha': 'center', 'ypercent': 0.5 }) # ---------- 无投影时的图例配置 start -------- # 图例放置方式 self.orientation = Projection.leaf_to_string(p, 'Orientation', 'vertical') # 图例离边框位置 self.anchor = Projection.leaf_to_list(p, "Anchor", [0, 0]) # 图例收缩系数 self.shrink = Projection.leaf_to_float(p, "Shrink", 1) self.fraction = Projection.leaf_to_float(p, 'Fraction', 0.15) # ---------- 有投影时的图例配置 start -------- # 图例收缩系数 self.size = Projection.leaf_to_string(leaf=p, code='Size', defvalue='5%') # 图例离边框位置 self.pad = Projection.leaf_to_string(leaf=p, code='Pad', defvalue='2%') # 图例放置位置 self.location = Projection.leaf_to_string(leaf=p, code='Location', defvalue='right')
def add_projection(self, movie_id, type, date, time): session.add( Projection(movie_id=movie_id, type=type, date=date, time=time)) session.commit()