python calu_python自动重采样数据
假设我有以下数据(测量值):
如您所见,有很多尖点(即坡度变化很大的地方).因此,最好在这些点周围再进行一些测量.为此,我编写了一个脚本:
…然后迭代直到平均曲率下降…但是它不起作用,因为它上升了.你知道为什么吗 ?
这是完整的代码(在x值的长度达到60后停止它):
import numpy as np
import matplotlib.pyplot as plt
def curvature(A,B,C):
"""Calculates the Menger curvature fro three Points,given as numpy arrays.
Sources:
Menger curvature: https://en.wikipedia.org/wiki/Menger_curvature#Definition
Area of a triangle given 3 points: https://math.stackexchange.com/questions/516219/finding-out-the-area-of-a-triangle-if-the-coordinates-of-the-three-vertices-are
"""
# Pre-check: Making sure that the input points are all numpy arrays
if any(x is not np.ndarray for x in [type(A),type(B),type(C)]):
print("The input points need to be a numpy array,currently it is a ",type(A))
# Augment Columns
A_aug = np.append(A,1)
B_aug = np.append(B,1)
C_aug = np.append(C,1)
# Caclulate Area of Triangle
matrix = np.column_stack((A_aug,B_aug,C_aug))
area = 1/2*np.linalg.det(matrix)
# Special case: Two or more points are equal
if np.all(A == B) or np.all(B == C):
curvature = 0
else:
curvature = 4*area/(np.linalg.norm(A-B)*np.linalg.norm(B-C)*np.linalg.norm(C-A))
# Return Menger curvature
return curvature
def values_to_calulate(x,curvature_list,max_curvature):
"""Calculates the new x values which need to be calculated
Middle point between the three points that were used to calculate the curvature """
i = 0
new_x = np.empty(0)
for curvature in curvature_list:
if curvature > max_curvature:
new_x = np.append(new_x,x[i]+(x[i+2]-x[i])/3 )
i = i+1
return new_x
def plot(x,y,title,xLabel,yLabel):
"""Just to visualize"""
# Plot
plt.scatter(x,y)
plt.plot(x,'-o')
# Give a title for the sine wave plot
plt.title(title)
# Give x axis label for the sine wave plot
plt.xlabel(xLabel)
# Give y axis label for the sine wave plot
plt.ylabel(yLabel)
plt.grid(True,which='both')
plt.axhline(y=0,color='k')
# Display the sine wave
plt.show
plt.pause(0.05)
### STARTS HERE
# Get x values of the sine wave
x = np.arange(0,10,1);
# Amplitude of the sine wave is sine of a variable like time
def function(x):
return 1+np.sin(x)*np.cos(x)**2
y = function(x)
# Plot it
plot(x,title='Data',xLabel='Time',yLabel='Amplitude')
continue_Loop = True
while continue_Loop == True :
curvature_list = np.empty(0)
for i in range(len(x)-2):
# Get the three points
A = np.array([x[i],y[i]])
B = np.array([x[i+1],y[i+1]])
C = np.array([x[i+2],y[i+2]])
# Calculate the curvature
curvature_value = abs(curvature(A,C))
curvature_list = np.append(curvature_list,curvature_value)
print("len: ",len(x) )
print("average curvature: ",np.average(curvature_list))
# Calculate the points that need to be added
x_new = values_to_calulate(x,max_curvature=0.3)
# Add those values to the current x list:
x = np.sort(np.append(x,x_new))
# STOPED IT AFTER len(x) == 60
if len(x) >= 60:
continue_Loop = False
# Amplitude of the sine wave is sine of a variable like time
y = function(x)
# Plot it
plot(x,yLabel='Amplitude')
它应该是这样的:
编辑:
如果让它继续运行…:
python calu_python自动重采样数据相关推荐
- 用python做生物信息数据分析_基于Python的自动获取生物信息数据的软件设计
基于 Python 的自动获取生物信息数据的软件设计 * 周斯涵,刘月兰 ** [摘 要] [摘 要] 从国际生物信息学数据库中采集数据来进行相关领域的分析, 但随着数据库规模不断扩大 , 数据来源种 ...
- python脚本实现GNSS数据自动下载
python脚本实现GNSS数据自动下载 本文代码思路参考了博文[https://blog.csdn.net/weixin_39672353/article/details/1098525] 在此基础 ...
- python怎么写excel数据透视自动报表_使用Python生成自动报表(E
使用Python生成自动报表(Excel)以邮件发送 数据分析师肯定每天都被各种各样的数据数据报表搞得焦头烂额,老板的,运营的.产品的等等.而且大部分报表都是重复性的工作,这篇文章就是帮助大家如何用P ...
- 用Python自动生成数据日报!
今天聊聊怎么用Python自动生成数据日报! 其实我觉得蛮简单,核心就是你组装好日报的内容模板,然后将变化的量交给python去填充,需要用到的基本就是python处理excel.word和ppt等相 ...
- Python自动生成数据日报
对于一个企业来说,高层看意义,中层看结论,基层看落地,数据日报.周报.月报可以监控销售个人在实际执行过程中的销售动态,而数据季度报.年报可以反映一个销售策略是否与实际的业务场景切合. 可见数据日报在我 ...
- 抓取安居客二手房经纪人数据,python爬虫自动翻页
为什么80%的码农都做不了架构师?>>> 和链接不一样,安居客网站里面没有找到总页数,可能在json里面有,只是我没有找到. 基于此能不能做网页的循环爬取呢. 能否判断页面读取 ...
- 使用python 处理表格生成图表_教你用Python自动读取数据生成图表,产生的效益很可观...
厌烦了每次都要在Excel里拖动数据来生成图形吧,这篇文章里,教你用Python自动读取Excel数据生成图表,然后Python 使用XlsxWriter模块在Excel工作表中绘制带有数据表的柱形图 ...
- python图片自动校正流量_案例:基于自动节点树的数据异常原因下探分析(python_029)...
在流量数据化运营中,数据异常波动时,就需要分析师找到主要影响因素,并分析原因.这种异常数据检测的场景包括:监测网站平均订单价值.订单量.订单转化率波动:注册或登录的异常变化:某个登录页面浏览量趋势:正 ...
- gdb -iex_如何使用IEX Cloud,Matplotlib和AWS在Python中创建自动更新数据可视化
gdb -iex Python is an excellent programming language for creating data visualizations. Python是用于创建数据 ...
最新文章
- 来自数据源的 String 类型的给定值不能转换为指定目标列的类型 nvarchar。
- Linux系统查看系统是32位还是64位方法总结 in 创新实训
- nginx日志问题解决方法记录
- Drop Down Menu
- [转]学习Objective-C: 入门教材
- mysql源码如何解析where字句_MySQL解析器源码分析--对select语句中子查询处理逻辑的分析(一)...
- 指定类型的成员XX”不支持实体LINQ。只有初始化,成员单位,和实体导航性能的支持。...
- C#序列化与反序列化以及深拷贝浅拷贝方法
- 切洋葱怎么才不流泪?
- python接口 同花顺_利用python探索股票市场数据指南
- 条件队列java_Java并发系列(4)AbstractQueuedSynchronizer源码分析之条件队列
- linux 移出权限,一起学习在 Ubuntu 上授予和移除 sudo 权限
- SpringBoot------定时任务
- requirejs教程(一):基本用法
- 网络QoS原理与实现
- 青花瓷音乐的单片机c语言程序,单片机蜂鸣器演奏青花瓷的程序
- cisco下模拟Linux防火墙,linux下配置cisco防火墙日志服务器
- python正则匹配日期2019-03-11_正则表达式验证日期(多种日期格式)——转载
- 数据结构算法学习 之 红黑树
- 阿里云服务器被挖矿的解决方法
热门文章
- 多WAN口宽带路由器到底几个口才算合理(转)
- 5 6c语言上机作业答案,C语言第五次上机作业参考答案
- 大话西游2服务器维护公告,大话西游2经典版:2019年05月09日停机维护公告
- windows版Transporter使用方法
- R语言ggplot绘制地图-报错汇总(一)
- 林纳斯·托瓦兹 Linus Torvalds
- 今年的目标 --还有两个月 我的21天计划
- 马克思主义与社会科学方法论
- Excel多个工作表合并,如何去除每个工作表中的表头,只保留一个表头
- 众筹系统源码 java_基于JavaWeb的创意众筹网站系统的设计与实现 毕业论文+任务书+开题报告+外文翻译+设计源码+mysql文件...