The class WindShift has a simplified initialization to accomodate custom built and autogenerated wind fields. The initialization function now takes in an entire list of times instead of a start time and shift interval. This was done since the calc_normal_windfield function was taking in these values anyways. The SENSOR_HEIGHT variable was also changed to not have an inital value since again the calc_normal_windfield asks for this. Common variables between building and custom windfields were moved outside the if statement and the if statement was updated to handle data correctly between the two options.
The calc_normal_windfield function now allows for a custom start_time and SENSOR_HEIGHT. It also calculates the times list before creating a new WindShift object. The inputted start direction and speed are now checked to see if they are in range.
The custom_windfield is a new function and the main attraction of this update. It is very similar to the calc_normal_windfield function in variables with the exception of using entire lists for the speeds and directions. These lists can be manually typed in or imported from a csv to a list and passed in.
The times list is also created automatically within this function. After this, several conditions are checked. The speeds and directions are checked to be in range ((0, 20] and [0, 360) respectively). Additionally, the length of the two lists are compared to the times list to ensure they are of the same length.
New File exceptions.py
The exceptions.py file is meant to store any custom exceptions for the library. This allows easy access to excpetions across library files. Three exceptions were created with this initial creation:
WindDirOutOfRange - Used to express when a wind direction is out of range. Takes a direction and allows for a custom range or message.
WindSpeedOutOfRange - Used to express when a wind speed is out of range. Takes a speed and allows for a custom range or message.
DataLengthMismatch - Used to express when two lists of data are not the same length. Takes a data name and length for two lists of data and allows for a custom message.
Motivation and Context
These changes make creating windfields more intuitive and customizable, regardless of whether the user is generating them or passing in custom data. Custom generation is more customizable with the addition of simulation start times and sensor height manipulation. Custom data has been fully implemented with the same options as the custom generation in addition to the ability to pass in wind directions and speeds directly.
This build comes with the added bonus of an exceptions file that will allow development to becomes easier in regards to handling run breaking errors.
Test Cases
To test the new custom wind field generation. I used the following snippet of code at the end of main.py
This allowed for easy manipulation of the data to test edge cases. For starters, here is a couple example exceptions from wind directions and speeds that are not in range:
Traceback (most recent call last):
File "main.py", line 53, in <module>
qf_arrs.custom_windfield(speeds, directions)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ttrs_quicfire/quic_fire.py", line 227, in custom_windfield
raise WindDirOutOfRange(dir)
ttrs_quicfire.exceptions.WindDirOutOfRange: 360 -> Wind Direction is Not in Range [0, 360)
Traceback (most recent call last):
File "main.py", line 53, in <module>
qf_arrs.custom_windfield(speeds, directions)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ttrs_quicfire/quic_fire.py", line 224, in custom_windfield
raise WindSpeedOutOfRange(speed)
ttrs_quicfire.exceptions.WindSpeedOutOfRange: 0 -> Wind Speed is Not in Range (0,20]
Here is an example of what happens when I add an additional datapoint to the directions list:
Traceback (most recent call last):
File "main.py", line 53, in <module>
qf_arrs.custom_windfield(speeds, directions)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ttrs_quicfire/quic_fire.py", line 221, in custom_windfield
raise DataLengthMismatch('Wind Directions', len(dirs), 'Wind Times', len(times))
ttrs_quicfire.exceptions.DataLengthMismatch: Wind Directions (13), Wind Times (12) -> Data Lengths Do Not Match
The calc_normal_windfield function was double checked and still works as intended with the added benefit of error handling like the custom_windfield function.
Checklist
[X] I have performed a self-review of my code
[X] I have commented my code, particularly in hard-to-understand areas
Issue #8
Description
Changes to Class
WindShift
The class
WindShift
has a simplified initialization to accomodate custom built and autogenerated wind fields. The initialization function now takes in an entire list of times instead of a start time and shift interval. This was done since thecalc_normal_windfield
function was taking in these values anyways. TheSENSOR_HEIGHT
variable was also changed to not have an inital value since again thecalc_normal_windfield
asks for this. Common variables between building and custom windfields were moved outside the if statement and the if statement was updated to handle data correctly between the two options.https://github.com/QUIC-Fire-TT/ttrs_quicfire/blob/232b4bd1b834c310eaaefd913f2041eaa06cc3fb/ttrs_quicfire/quic_fire.py#L235
Changes to Function
calc_normal_windfield
The
calc_normal_windfield
function now allows for a customstart_time
andSENSOR_HEIGHT
. It also calculates the times list before creating a newWindShift
object. The inputted start direction and speed are now checked to see if they are in range.https://github.com/QUIC-Fire-TT/ttrs_quicfire/blob/232b4bd1b834c310eaaefd913f2041eaa06cc3fb/ttrs_quicfire/quic_fire.py#L212-L213
New Function
custom_windfield
The
custom_windfield
is a new function and the main attraction of this update. It is very similar to thecalc_normal_windfield
function in variables with the exception of using entire lists for the speeds and directions. These lists can be manually typed in or imported from a csv to a list and passed in.https://github.com/QUIC-Fire-TT/ttrs_quicfire/blob/232b4bd1b834c310eaaefd913f2041eaa06cc3fb/ttrs_quicfire/quic_fire.py#L216
The times list is also created automatically within this function. After this, several conditions are checked. The speeds and directions are checked to be in range ((0, 20] and [0, 360) respectively). Additionally, the length of the two lists are compared to the times list to ensure they are of the same length.
New File
exceptions.py
The
exceptions.py
file is meant to store any custom exceptions for the library. This allows easy access to excpetions across library files. Three exceptions were created with this initial creation:WindDirOutOfRange
- Used to express when a wind direction is out of range. Takes a direction and allows for a custom range or message.WindSpeedOutOfRange
- Used to express when a wind speed is out of range. Takes a speed and allows for a custom range or message.DataLengthMismatch
- Used to express when two lists of data are not the same length. Takes a data name and length for two lists of data and allows for a custom message.Motivation and Context
These changes make creating windfields more intuitive and customizable, regardless of whether the user is generating them or passing in custom data. Custom generation is more customizable with the addition of simulation start times and sensor height manipulation. Custom data has been fully implemented with the same options as the custom generation in addition to the ability to pass in wind directions and speeds directly.
This build comes with the added bonus of an exceptions file that will allow development to becomes easier in regards to handling run breaking errors.
Test Cases
To test the new custom wind field generation. I used the following snippet of code at the end of
main.py
This allowed for easy manipulation of the data to test edge cases. For starters, here is a couple example exceptions from wind directions and speeds that are not in range:
Here is an example of what happens when I add an additional datapoint to the directions list:
The
calc_normal_windfield
function was double checked and still works as intended with the added benefit of error handling like thecustom_windfield
function.Checklist