我正在尝试计算一个时间条件的值。矢量/系列是给定小时的净太阳辐射和数据被收集的时间。当在白天获得该值时,我必须将所述值乘以.1,并且当在夜间获得该值时,我将该值乘以.5。问题是日光时间逐月变化(逐周变化),日光字典如下所示:
我正在尝试创建一个布尔掩码(withindaylight),它可以帮助我在'time'向量中的每个值上使用for循环来应用计算/乘法而不是在日光字典中检查它,这就是我我正在做的事情:
def Ghr(time, Rn):
#soil heatflux cal
#time is a single vale of the time vector
mon = time.strftime('%b') #strips the month
#sunrise -sunset hours from 1st of the month (sr,ss) to end of the month
#Jan-1st SR 8:17, Jan-31st SR 07:47
#Jan-1st SS 16:03, Jan-31st SS 16:52
daylight = {'Jan':('08:00', '16:25'),
'Feb':('07:20', '17:20'),
'Mar':('06:45', '18:40'),
'Apr':('06:05', '20:05'),
'May':('05:10', '20:55'),
'Jun':('04:50', '21:25'),
'Jul':('05:10', '21:15'),
'Aug':('05:50', '20:30'),
'Sep':('06:45', '19:25'),
'Oct':('07:00', '17:30'),
'Nov':('07:25', '16:15'),
'Dec':('08:05', '16:00')}
#strips the hour and minute from the daylight dictionary
#then withindaylight is the boolean after checking the
#time the data was collected against the these stripped values
daybegin = dt.strptime(daylight[mon][0], '%H:%M').time()
dayend= dt.strptime(daylight[mon][1], '%H:%M').time()
withindaylight = daybegin <= time.time() <= dayend
#I want to apply the boolean mask such that it produces the following,
#but returns a vector and not just a single value
if withindaylight:
return .1*Rn #I want to return a series and not just a single value
else:
return .5*Rn
答案 0 :(得分:1)
我的代码需要做几件事:
如何确保我的“时间”的每个实例都是&#39;被映射到正确的月份作为日光的关键&#39; ...
如何将元组提取到单独的列表
将包含字符串的元组转换为pd.Series中的时间对象
转换为蒙版并应用乘法
我使用以下代码解决了这些问题:
/* Set profile pic in registration */
@Headers("Accept:application/json")
@POST("/api/mbrphotos/prfImgIU/{memberId}/{actionType}")
public void sendMultiImages(@Path("memberId") String memberId,
@Path("actionType") String actionType,
@Body MultipartTypedOutput multipartTypedOutput, Callback<JsonObject> callback);