我想从VTK文件中提取一些数据(例如标量)以及它们在网格上的坐标,然后在Matplotlib中处理它.问题是我不知道如何从VTK文件中获取点/单元数据(例如,通过给出标量的名称)并使用vtk_to_numpy将它们加载到numpy数组中
我的代码应如下所示:
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
import numpy as np
from vtk import *
from vtk.util.numpy_support import vtk_to_numpy
# load input data
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName("my_input_data.vtk")
reader.Update()
(...missing steps)
# VTK to Numpy
my_numpy_array = vtk_to_numpy(...arguments ?)
#Numpy to Matplotlib (after converting my_numpy_array to x,y and z)
CS = plt.contour(x,y,z,NbLevels)
...
Run Code Online (Sandbox Code Playgroud)
PS:我知道Paraview可以完成任务,但我正在尝试发布一些数据而无需打开Paraview.任何帮助表示赞赏
编辑1
我发现这个pdf教程对于学习处理VTK文件的基础知识非常有用
attrs是减少样板的有用方法.例:
class SomeClass(object):
a_number = attr.ib(default=42)
list2_of_numbers = attr.ib(default=attr.Factory(list))
Run Code Online (Sandbox Code Playgroud)
PyCharm不为生成的__init__方法提供代码完成,是否有插件可以执行此操作?还是其他一些工作?
我很惊讶地发现在nginx访问日志中找不到有关记录请求协议的任何信息.我通常共享HTTP(80)和HTTPS(443)流量的服务器块,并使用组合访问日志.我想在访问日志的每一行中指明请求是通过HTTP还是HTTPS.
这是可能的,还是我需要为HTTPS使用单独的服务器块并为SSL指定单独的访问日志?
我有一些数据,每行有两列.在我的情况下,工作提交时间和地区.
我已经使用了matplotlib的hist函数来生成一个图表,该图表在x轴上按天分箱,在y轴上每天计数:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import datetime as dt
def timestamp_to_mpl(timestamp):
return mpl.dates.date2num(dt.datetime.fromtimestamp(timestamp))
nci_file_name = 'out/nci.csv'
jobs = np.genfromtxt(nci_file_name, dtype=int, delimiter=',', names=True, usecols(1,2,3,4,5))
fig, ax = plt.subplots(2, 1, sharex=True)
vect_timestamp_to_mpl = np.vectorize(timestamp_to_mpl)
qtime = vect_timestamp_to_mpl(jobs['queued_time'])
start_date = dt.datetime(2013, 1, 1)
end_date = dt.datetime(2013, 4, 1)
bins = mpl.dates.drange(start_date, end_date, dt.timedelta(days=1))
ax[0].hist(qtime[jobs['charge_rate']==1], bins=bins, label='Normal', color='b')
ax[1].hist(qtime[jobs['charge_rate']==3], bins=bins, label='Express', color='g')
ax[0].grid(True)
ax[1].grid(True)
fig.suptitle('NCI Workload Submission Daily Rate')
ax[0].set_title('Normal Queue')
ax[1].set_title('Express Queue')
ax[1].xaxis.set_major_locator(mpl.dates.AutoDateLocator())
ax[1].xaxis.set_major_formatter(mpl.dates.AutoDateFormatter(ax[1].xaxis.get_major_locator())) …Run Code Online (Sandbox Code Playgroud) 我尝试使用cordova Background Geolocation将我的位置发送到后台的服务器.但是当我在一段时间后将我的应用程序放在后台时它停止工作.所以我尝试了BackgroundFetch服务https://github.com/christocracy/cordova-plugin-background-fetch但是不起作用:错误是:
You've implemented -[<UIApplicationDelegate> application:performFetchWithCompletionHandler:], but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.
Run Code Online (Sandbox Code Playgroud)
如何在我的Info.plist中将fetch添加到支持的UIBackgroundModes列表中?
Kafka org.apache.kafka.clients.producer.internals.DefaultPartitioner实现中有一个非常小但非常强大的细节,这让我很烦恼.
正是这行代码:
return DefaultPartitioner.toPositive(Utils.murmur2(keyBytes)) % numPartitions;
Run Code Online (Sandbox Code Playgroud)
更确切地说,是最后一个% numPartitions.我一直在问自己,通过使分区ID成为现有分区数量的函数,引入如此巨大约束的原因是什么?只是为了方便小数字(人类可读/可追踪?!)与分区总数相比?这里有没有人对这个问题有更广泛的了解?
我问这个是因为在我们的实现中,我们用来在kafka中存储数据的密钥是域敏感的,我们使用它来基于kafka从kafka中检索信息.例如,我们的消费者只需要订阅那些对他们感兴趣的分区,而我们进行链接的方式就是使用这些密钥.
使用不进行模数操作的自定义分区程序会安全吗?我们是否应该注意到性能下降 这对生产者和/或消费者方面有什么影响吗?
欢迎任何想法和意见.
我正在尝试使用 matplotlib 绘制二进制时间线(不过,我可能可以考虑替代库)。
现在,“二进制时间线”是指“按时间顺序显示的事件,其中事件空间由两个相反的事件组成”。这种事件空间的一个例子可能是{no_one_in_the_team_is_sick, at_least_one_person_in_the_team_is_sick}。
我曾尝试探索使用堆叠的水平条,但它显然不是适合这项工作的工具。
是否有更简单和/或更正确的方法来实现该结果?
我不想使用此功能,因为出于安全原因它在某些服务器上不可用,我如何用cURL替换file_get_content()?
以下行导致我的服务器出现问题:
$response = file_get_contents('http://images.google.com/images?hl=en&q=' . urlencode ($query) . '&imgsz=' . $size . '&imgtype=' . $type . '&start=' . (($page - 1) * 21));
Run Code Online (Sandbox Code Playgroud)
如何用另一个使用curl的线替换该线,以便它可以在每个服务器上运行?
我正在使用Xcode 11.1,我的部署目标是iOS 10.0
我无法像以前那样实例化视图控制器。这是其中的代码
func application(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?)->布尔
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(identifier: "TabBarController")
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
'instantiateViewController(identifier:creator :)'仅在iOS 13.0或更高版本中可用
在Xcode 11.1上以编程方式实例化视图控制器的可能性如何。还有其他方法吗?
我正在使用一个我无法控制HTML的电子商务页面.我正在尝试为每个列表项(swatch)添加价格.
// This is some hidden HTML being displayed on the page that has altered prices in it.
const superAttributesRaw = [...document.querySelectorAll('.super-attribute-select option')];
const superAttributes = superAttributesRaw.filter(newValue => Object.keys(newValue).length !== 0);
// This is the shown HTML swatch I need to add the altered prices to.
const swatchUl = [...document.querySelectorAll('.swatchesContainer ul li')];
// Pulling out the altered prices and putting them into an array.
prices = [];
for (let value of superAttributes) {
prices.push(value.config.price);
}
// This adds the sample …Run Code Online (Sandbox Code Playgroud) 我正在尝试为此字符串生成正则表达式:
我需要的是一种只从9个数字中获取最后5个数字的方法
到目前为止我这样做了:
case.match(/\d{5}$/)
Run Code Online (Sandbox Code Playgroud)
它适用于前两种情况,但不适用于最后一种情况