Skip to content

Commit

Permalink
style fixes by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander0042 authored and github-actions[bot] committed Nov 25, 2024
1 parent 93ccb73 commit dde4656
Showing 1 changed file with 74 additions and 62 deletions.
136 changes: 74 additions & 62 deletions API/responseLocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2541,8 +2541,8 @@ async def PW_Forecast(
if "gfs" in sourceList:
WindSpeedHour[:, 2] = np.sqrt(GFS_Merged[:, 8] ** 2 + GFS_Merged[:, 9] ** 2)

InterPhour[:, 10] = (
np.choose(np.argmin(np.isnan(WindSpeedHour), axis=1), WindSpeedHour.T)
InterPhour[:, 10] = np.choose(
np.argmin(np.isnan(WindSpeedHour), axis=1), WindSpeedHour.T
)

# Clip between 0 and 400
Expand All @@ -2556,11 +2556,11 @@ async def PW_Forecast(
WindGustHour[:, 1] = HRRR_Merged[:, 2]
if "gfs" in sourceList:
WindGustHour[:, 2] = GFS_Merged[:, 2]
InterPhour[:, 11] = (
np.choose(np.argmin(np.isnan(WindGustHour), axis=1), WindGustHour.T)
InterPhour[:, 11] = np.choose(
np.argmin(np.isnan(WindGustHour), axis=1), WindGustHour.T
)
# Clip between 0 and 400
InterPhour[:, 11] = np.clip(InterPhour[:, 11], 0, 120)* windUnit
InterPhour[:, 11] = np.clip(InterPhour[:, 11], 0, 120) * windUnit

### Wind Bearing
WindBearingHour = np.full((len(hour_array_grib), 3), np.nan)
Expand Down Expand Up @@ -3437,8 +3437,6 @@ async def PW_Forecast(
# Clip between 0 and 1
InterPcurrent[7] = np.clip(InterPcurrent[7], 0, 1)



# Pressure from HRRR, then GFS
if ("hrrr_0-18" in sourceList) and ("hrrr_18-48" in sourceList):
InterPcurrent[8] = (
Expand All @@ -3453,36 +3451,31 @@ async def PW_Forecast(

# Clip between 800 and 1100
InterPcurrent[8] = np.clip(InterPcurrent[8], 800, 1100) * pressUnits


# WindSpeed from subH, then NBM, the GFS
if "hrrrsubh" in sourceList:
InterPcurrent[9] = (
math.sqrt(
hrrrSubHInterpolation[0, 5] ** 2 + hrrrSubHInterpolation[0, 6] ** 2
)
InterPcurrent[9] = math.sqrt(
hrrrSubHInterpolation[0, 5] ** 2 + hrrrSubHInterpolation[0, 6] ** 2
)
elif "nbm" in sourceList:
InterPcurrent[9] = (
NBM_Merged[currentIDX_hrrrh - 1, 6] * interpFac1
+ NBM_Merged[currentIDX_hrrrh, 6] * interpFac2
)
else:
InterPcurrent[9] = (
math.sqrt(
(
GFS_Merged[currentIDX_hrrrh - 1, 8] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 8] * interpFac2
)
** 2
+ (
GFS_Merged[currentIDX_hrrrh - 1, 9] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 9] * interpFac2
)
** 2
InterPcurrent[9] = math.sqrt(
(
GFS_Merged[currentIDX_hrrrh - 1, 8] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 8] * interpFac2
)
** 2
+ (
GFS_Merged[currentIDX_hrrrh - 1, 9] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 9] * interpFac2
)
** 2
)
InterPcurrent[9] = np.clip(InterPcurrent[9], 0, 120)* windUnit
InterPcurrent[9] = np.clip(InterPcurrent[9], 0, 120) * windUnit

# Guest from subH, then NBM, the GFS
if "hrrrsubh" in sourceList:
Expand All @@ -3499,7 +3492,7 @@ async def PW_Forecast(
)

# Clip between 0 and 400
InterPcurrent[10] = np.clip(InterPcurrent[10], 0, 120)* windUnit
InterPcurrent[10] = np.clip(InterPcurrent[10], 0, 120) * windUnit

# WindDir from subH, then NBM, the GFS
if "hrrrsubh" in sourceList:
Expand Down Expand Up @@ -3540,8 +3533,8 @@ async def PW_Forecast(
+ GFS_Merged[currentIDX_hrrrh, 17] * interpFac2
) * 0.01

# Clip
InterPcurrent[12] = np.clip(InterPcurrent[12], 0 ,15)
# Clip
InterPcurrent[12] = np.clip(InterPcurrent[12], 0, 15)

# UV Index from subH, then NBM, the GFS
InterPcurrent[13] = np.clip(
Expand All @@ -3556,49 +3549,56 @@ async def PW_Forecast(
# VIS, NBM then HRRR, then GFS
if "nbm" in sourceList:
InterPcurrent[14] = (
(
NBM_Merged[currentIDX_hrrrh - 1, 10] * interpFac1
+ NBM_Merged[currentIDX_hrrrh, 10] * interpFac2
)
NBM_Merged[currentIDX_hrrrh - 1, 10] * interpFac1
+ NBM_Merged[currentIDX_hrrrh, 10] * interpFac2
)
elif ("hrrr_0-18" in sourceList) and ("hrrr_18-48" in sourceList):
InterPcurrent[14] = (
(
HRRR_Merged[currentIDX_hrrrh - 1, 1] * interpFac1
+ HRRR_Merged[currentIDX_hrrrh, 1] * interpFac2
)
HRRR_Merged[currentIDX_hrrrh - 1, 1] * interpFac1
+ HRRR_Merged[currentIDX_hrrrh, 1] * interpFac2
)
else:
InterPcurrent[14] = (
(
GFS_Merged[currentIDX_hrrrh - 1, 1] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 1] * interpFac2
)
GFS_Merged[currentIDX_hrrrh - 1, 1] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 1] * interpFac2
)

InterPcurrent[14] = np.clip(InterPcurrent[14], 0, 16090) * visUnits

# Ozone from GFS
InterPcurrent[15] = np.clip(
GFS_Merged[currentIDX_hrrrh - 1, 16] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 16] * interpFac2
, 0, 500) # " "ozone"
+ GFS_Merged[currentIDX_hrrrh, 16] * interpFac2,
0,
500,
) # " "ozone"

# Storm Distance from GFS
InterPcurrent[16] = np.maximum((
GFS_Merged[currentIDX_hrrrh - 1, 19] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 19] * interpFac2
) * visUnits, 0)
InterPcurrent[16] = np.maximum(
(
GFS_Merged[currentIDX_hrrrh - 1, 19] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 19] * interpFac2
)
* visUnits,
0,
)

# Storm Bearing from GFS
InterPcurrent[17] = GFS_Merged[currentIDX_hrrrh, 20]

# Smoke from HRRR
if ("hrrr_0-18" in sourceList) and ("hrrr_18-48" in sourceList):
InterPcurrent[18] = np.clip(((
HRRR_Merged[currentIDX_hrrrh - 1, 16] * interpFac1
+ HRRR_Merged[currentIDX_hrrrh, 16] * interpFac2
) * 1e9), 0, 200)
InterPcurrent[18] = np.clip(
(
(
HRRR_Merged[currentIDX_hrrrh - 1, 16] * interpFac1
+ HRRR_Merged[currentIDX_hrrrh, 16] * interpFac2
)
* 1e9
),
0,
200,
)
else:
InterPcurrent[18] = -999

Expand All @@ -3614,24 +3614,35 @@ async def PW_Forecast(
)
)

InterPcurrent[5] = np.clip(((
(InterPcurrent[4] - 273.15)
+ 0.33 * eCurrent
- 0.70 * (InterPcurrent[9] / windUnit)
- 4.00
) + 273.15), -183, 333)
InterPcurrent[5] = np.clip(
(
(
(InterPcurrent[4] - 273.15)
+ 0.33 * eCurrent
- 0.70 * (InterPcurrent[9] / windUnit)
- 4.00
)
+ 273.15
),
-183,
333,
)

# Where Ta is the ambient temperature in °C
# e is the water vapor pressure in hPa
# ws is the wind speed in m/s
# Q is the solar radiation per unit area of body surface in w/m²
if "nbm" in sourceList:
InterPcurrent[20] = (NBM_Merged[currentIDX_hrrrh - 1, 3] * interpFac1
+ NBM_Merged[currentIDX_hrrrh, 3] * interpFac2)
InterPcurrent[20] = (
NBM_Merged[currentIDX_hrrrh - 1, 3] * interpFac1
+ NBM_Merged[currentIDX_hrrrh, 3] * interpFac2
)
else:
InterPcurrent[20] = (GFS_Merged[currentIDX_hrrrh - 1, 7] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 7] * interpFac2)

InterPcurrent[20] = (
GFS_Merged[currentIDX_hrrrh - 1, 7] * interpFac1
+ GFS_Merged[currentIDX_hrrrh, 7] * interpFac2
)

# Clip
InterPcurrent[20] = np.clip(InterPcurrent[20], -183, 333)

Expand All @@ -3642,7 +3653,8 @@ async def PW_Forecast(
NBM_Fire_Merged[currentIDX_hrrrh - 1, 1] * interpFac1
+ NBM_Fire_Merged[currentIDX_hrrrh, 1] * interpFac2
),
0, 15
0,
15,
)
else:
InterPcurrent[19] = -999
Expand Down

0 comments on commit dde4656

Please sign in to comment.