首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Heat_Index_calculator: RecursionError:调用Python时超过了最大递归深度

Heat_Index_calculator: RecursionError:调用Python时超过了最大递归深度
EN

Stack Overflow用户
提问于 2021-03-16 16:49:16
回答 1查看 88关注 0票数 0

我有以下数据:

代码语言:javascript
复制
 {'RH': {0: 58.9289, 1: 50.3455, 2: 50.8142, 3: 53.0112, 4: 55.4512, 5: 57.5399, 6: 59.4835, 
 7: 67.8222, 8: 70.6624, 9: 72.2602, 10: 73.3083, 11: 74.5302, 12: 75.4472, 13: 76.3634, 14: 
 77.0452, 15: 77.1069, 16: 77.0966, 17: 76.9039, 18: 72.3328, 19: 66.2169, 20: 62.0029, 21: 
 59.2981, 22: 57.6574, 23: 56.8761, 24: 56.6011, 25: 45.0752, 26: 43.0393, 27: 43.7027, 28: 
 45.9743, 29: 48.4454, 30: 49.8465, 31: 62.2785, 32: 66.3982, 33: 68.8178, 34: 69.8033, 35: 
 70.7879, 36: 71.8861, 37: 74.6885, 38: 75.5149, 39: 75.8017, 40: 75.8211, 41: 74.3816, 42: 
 70.3053, 43: 63.7589, 44: 59.6312, 45: 56.7952, 46: 54.9899, 47: 53.9745, 48: 53.5251, 49: 
 48.9537, 50: 49.2989, 51: 50.7327, 52: 52.5816, 53: 53.8873, 54: 55.1234, 55: 64.6119, 56: 
 66.6161, 57: 68.7152, 58: 70.1556, 59: 71.3258, 60: 72.2003, 61: 73.5831, 62: 74.1941, 63: 
 74.6312, 64: 74.9443, 65: 73.4724, 66: 68.891, 67: 61.5091, 68: 57.6684, 69: 55.2309, 70:      
 53.8839, 71: 53.1925, 72: 52.9267}, 'T': {0: 304.755, 1: 305.997, 2: 305.85, 3: 305.34, 4: 
 304.935, 5: 304.655, 6: 304.422, 7: 302.804, 8: 302.267, 9: 301.937, 10: 301.72, 11: 
 301.475, 12: 301.269, 13: 300.546, 14: 300.24, 15: 300.179, 16: 300.15, 17: 300.168, 18: 
 301.02, 19: 302.265, 20: 303.089, 21: 303.655, 22: 304.01, 23: 304.197, 24: 304.256, 25: 
 306.707, 26: 307.188, 27: 306.993, 28: 306.475, 29: 306.099, 30: 305.874, 31: 303.362, 32:      
 302.58, 33: 302.204, 34: 302.066, 35: 301.905, 36: 301.706, 37: 300.863, 38: 300.518, 39:      
 300.352, 40: 300.292, 41: 300.567, 42: 301.396, 43: 302.653, 44: 303.482, 45: 304.086, 46: 
 304.482, 47: 304.721, 48: 304.827, 49: 306.306, 50: 306.318, 51: 306.082, 52: 305.801, 53: 
 305.52, 54: 305.187, 55: 302.647, 56: 301.996, 57: 301.505, 58: 301.202, 59: 300.952, 60: 
 300.741, 61: 300.152, 62: 299.988, 63: 299.885, 64: 299.82, 65: 300.083, 66: 300.945, 67:      
 302.507, 68: 303.485, 69: 304.133, 70: 304.505, 71: 304.71, 72: 304.799}, 'T_V2': {0: 
 31.605000000000018, 1: 32.84700000000004, 2: 32.700000000000045, 3: 32.19, 4: 
 31.785000000000025, 5: 31.504999999999995, 6: 31.272000000000048, 7: 29.653999999999996, 8: 
 29.11700000000002, 9: 28.787000000000035, 10: 28.57000000000005, 11: 28.325000000000045, 
 12: 28.119000000000028, 13: 27.396000000000015, 14: 27.090000000000032, 15: 
 27.028999999999996, 16: 27.0, 17: 27.01800000000003, 18: 27.870000000000005, 19: 
 29.11500000000001, 20: 29.93900000000002, 21: 30.504999999999995, 22: 30.860000000000014, 
 23: 31.047000000000025, 24: 31.105999999999995, 25: 33.557000000000016, 26: 
 34.03800000000001, 27: 33.84300000000002, 28: 33.325000000000045, 29: 32.94900000000001, 
 30: 32.724000000000046, 31: 30.212000000000046, 32: 29.430000000000007, 33: 
 29.05400000000003, 34: 28.915999999999997, 35: 28.754999999999995, 36: 28.55600000000004, 
 37: 27.713000000000022, 38: 27.367999999999995, 39: 27.201999999999998, 40: 
 27.141999999999996, 41: 27.41700000000003, 42: 28.246000000000038, 43: 29.503000000000043, 
 44: 30.33200000000005, 45: 30.936000000000035, 46: 31.33200000000005, 47: 
 31.571000000000026, 48: 31.67700000000002, 49: 33.156000000000006, 50: 33.168000000000006, 
 51: 32.932000000000016, 52: 32.65100000000001, 53: 32.370000000000005, 54: 
 32.037000000000035, 55: 29.497000000000014, 56: 28.846000000000004, 57: 28.355000000000018, 
 58: 28.05200000000002, 59: 27.80200000000002, 60: 27.591000000000008, 61: 
 27.00200000000001, 62: 26.838000000000022, 63: 26.735000000000014, 64: 26.670000000000016, 
 65: 26.93300000000005, 66: 27.795000000000016, 67: 29.357000000000028, 68: 
 30.335000000000036, 69: 30.983000000000004, 70: 31.355000000000018, 71: 31.560000000000002, 
 72: 31.649}}

我试着用python计算热应力指数。以上数据有RH、T、T_V2三列。

我将只使用RH和T_V2。

我有以下脚本:

代码语言:javascript
复制
def calculate_heat_index(t,rh):

t_fahrenheit = t * (9./5.) + 32

heat_index_fahrenheit = -42.379 + (2.04901523 * t_fahrenheit) + (10.14333127 * rh) + \
    (-0.22475541 * t_fahrenheit * rh) + (-0.006837837 * t_fahrenheit * t_fahrenheit) + \
    (-0.05481717 * rh * rh) + (0.001228747 * t_fahrenheit * t_fahrenheit * rh) + \
    (0.00085282 * t_fahrenheit * rh * rh) + (-0.00000199 * t_fahrenheit * t_fahrenheit * rh * rh)
locs = np.ma.where(np.ma.logical_and((rh < 13), (t_fahrenheit > 80), (t_fahrenheit < 112)))
if len(locs[0]) > 0:
    heat_index_fahrenheit[locs] = heat_index_fahrenheit[locs] - (((13.- rh[locs]) / 4.) * np.ma.sqrt((17. - np.ma.abs(t_fahrenheit[locs] - 95.)) / 17.))
    locs = np.ma.where(np.ma.logical_and((rh > 85), (t_fahrenheit > 80), (t_fahrenheit < 87)))
if len(locs[0]) > 0:
    heat_index_fahrenheit[locs] = heat_index_fahrenheit[locs] - (((rh[locs ] - 85) / 10.) * ((87. - t_fahrenheit[locs]) / 5.))

locs = np.ma.where(heat_index_fahrenheit < 80)
if len(locs[0]) > 0:
    heat_index_fahrenheit[locs] = 0.5 * (t_fahrenheit[locs] + 61. + ((t_fahrenheit[locs] - 68.) * 1.2) + (rh[locs] * 0.094))

heat_index = (heat_index_fahrenheit - 32) / (9./5.)

locs = np.ma.where(t < 26.6667) # 80F
if len(locs[0]) > 0:
    heat_index[locs] = -99
locs = np.ma.where(rh < 40.0)
if len(locs[0]) > 0:
    heat_index[locs] = -99
return heat_index

当我打字的时候:

代码语言:javascript
复制
HI=calculate_heat_index(df['T_V2'],df['RH'])

我得到以下错误:

代码语言:javascript
复制
RecursionError: maximum recursion depth exceeded while calling a Python object

这是方程的起源:

代码语言:javascript
复制
 Rothfusz LP. 1990. The Heat Index Equation, SR Technical Attachment, 94-19, pp 6.
 http://www.hpc.ncep.noaa.gov/html/heatindex_equation.shtml

我只想要一个包含以下列的数据框架:

代码语言:javascript
复制
RH, T_V2, HI

附件:

这是数据和脚本的链接。

https://www.dropbox.com/sh/t88oab9txej73u1/AAAkDCcsTC3_eHg8uBc0vhtda?dl=0

对如何解决这个问题有什么建议吗?我会感谢你的帮助。

对不起,我对python并不熟悉。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-16 18:19:24

logical_and似乎只接受两个论点。纠正这一错误导致了另一个对我来说非常奇怪的错误,SingleBlockManager has no method view,这听起来像是熊猫布尔序列和numpy数组之间的兼容性错误。

所以,以下的改变似乎解决了这个问题-

代码语言:javascript
复制
    locs = np.ma.where(np.ma.logical_and(np.ma.logical_and(np.array((rh < 13)), np.array((t_fahrenheit > 80))), np.array(t_fahrenheit < 112)))
    if len(locs[0]) > 0:
        heat_index_fahrenheit[locs] = heat_index_fahrenheit[locs] - (
                    ((13. - rh[locs]) / 4.) * np.ma.sqrt((17. - np.ma.abs(t_fahrenheit[locs] - 95.)) / 17.))
        locs = np.ma.where(np.ma.logical_and(np.ma.logical_and(np.aaray(rh > 85), np.aaray(t_fahrenheit > 80)), np.array(t_fahrenheit < 87)))

如果对你有用,请告诉我。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66659702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档