-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple bugfixes for CARQ
correction of OFCL
track
#68
Conversation
forecast.loc[ | ||
mslp_missing, "central_pressure" | ||
] = relation.central_pressure( | ||
max_sustained_wind_speed=forecast.loc[ | ||
mslp_missing, "max_sustained_wind_speed" | ||
], | ||
background_pressure=forecast.loc[ | ||
mslp_missing, "background_pressure" | ||
], | ||
holland_b=holland_b, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to the fixes in this pull, this update forecast
data frame was not stored anywhere and the corrections were discarded. #66
holland_b=holland_b, | ||
) | ||
|
||
corr_ofcl_tracks[initial_time] = forecast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the correction is stored in the corr_ofcl_tracks
which replaces the values in the original forecast track. #66
holland_b=holland_b, | ||
) | ||
if all(adv in tracks for adv in ["OFCL", "CARQ"]): | ||
tracks = correct_ofcl_based_on_carq_n_hollandb(tracks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for CARQ
correction is now moved to a standalone function
) | ||
if all(adv in tracks for adv in ["OFCL", "CARQ"]): | ||
tracks = correct_ofcl_based_on_carq_n_hollandb(tracks) | ||
dataframe = combine_tracks(tracks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The corrected tracks are now converted back into a dataframe which replaces the original one #66
mrd_missing = pandas.isna(forecast["radius_of_maximum_winds"]) | ||
mslp_missing = pandas.isna(forecast["central_pressure"]) | ||
radp_missing = pandas.isna(forecast["background_pressure"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original values for these variables from the ATCF file were not empty, but they were 0
instead. So, the correction logic would ignore them and didn't fix the incorrect 0
value. #64
columns_of_interest[columns_of_interest == 0] = pandas.NA | ||
missing = columns_of_interest.isna() | ||
# Order of columns is the same as columns_of_interest | ||
mrd_missing = missing.iloc[:, 0] | ||
mslp_missing = missing.iloc[:, 1] | ||
radp_missing = missing.iloc[:, 2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The values are now checked for both NA
as well as 0
to indicate the missing data. #64
@@ -1175,6 +1129,7 @@ def separate_tracks(data: DataFrame) -> Dict[str, Dict[str, DataFrame]]: | |||
tracks = {} | |||
for advisory in pandas.unique(data["advisory"]): | |||
advisory_data = data[data["advisory"] == advisory] | |||
advisory_data["forecast_hours"] = advisory_data.forecast_hours.astype(int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The forecast_hours
data is used for sorting the dataframe. Because the data was originally of string
type, the sort used to happen at character level (i.e. first 1
s and then 2
s, etc. so that 120
would come before 24
). Now this issue is fixed by using int
type #67
holland_b = numpy.nanmean(holland_b) | ||
|
||
# Get CARQ from forecast hour 0 and isotach 34kt (i.e. the first item) | ||
carq_ref = carq_forecast.loc[carq_forecast.forecast_hours == 0].iloc[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CARQ
track entry to be used is now the first entry of hour-0 forecast (i.e. 34 kt
) #65
# fill OFCL maximum wind radius with the first entry from the CARQ advisory | ||
forecast.loc[ | ||
mrd_missing, "radius_of_maximum_winds" | ||
] = carq_forecast["radius_of_maximum_winds"].iloc[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first CARQ
track could be a -24
hour "forecast", which has missing values for variables of interest. iloc[0]
just gets the first entry of carq_forecast
dataframe instead of getting the first hour-0 entry
def test_carq_autofix_ofcl(): | ||
track = VortexTrack.from_storm_name( | ||
"Florence", 2018, advisories=["OFCL"], file_deck="a" | ||
) | ||
|
||
variables_of_interest = [ | ||
"central_pressure", | ||
"background_pressure", | ||
"radius_of_maximum_winds", | ||
] | ||
|
||
assert not (track.data[variables_of_interest] == 0).any(axis=None) | ||
assert not (track.data[variables_of_interest].isna()).any(axis=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for CARQ
correction of OFCL
functionality
Codecov Report
@@ Coverage Diff @@
## main #68 +/- ##
==========================================
+ Coverage 90.89% 91.01% +0.11%
==========================================
Files 18 18
Lines 1857 1880 +23
==========================================
+ Hits 1688 1711 +23
Misses 169 169
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -184,7 +184,7 @@ def test_vortex_track_distances(): | |||
track_1.distances["BEST"]["20180830T060000"], 8725961.838567913 | |||
) | |||
assert numpy.isclose( | |||
track_2.distances["OFCL"]["20180831T000000"], 8882602.389540724 | |||
track_2.distances["OFCL"]["20180831T000000"], 3499027.5307995058 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old value was wrong as the order of track points was incorrect due to #67. It used to be:
[(-20.2, 13.1), (-22.3, 13.7), (-44.0, 21.5), (-47.0, 24.0), (-48.5, 27.0), (-24.9, 14.5), (-20.9, 13.2), (-27.7, 15.3), (-30.4, 16.0), (-35.5, 17.5), (-40.0, 19.0)]
while it should be
[(-20.2, 13.1), (-20.9, 13.2), (-22.3, 13.7), (-24.9, 14.5), (-27.7, 15.3), (-30.4, 16.0), (-35.5, 17.5), (-40.0, 19.0), (-44.0, 21.5), (-47.0, 24.0), (-48.5, 27.0)]
This wrong order results in the large difference between the distance values prior to the fix of #67
Ideally I'd like to merge this by mid-week next week. I'd appreciate it if you could please review it by then. Especially since you're more familiar with the code @zacharyburnett and @WPringle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, good catch for the issues
@SorooshMani-NOAA What is the function call you were using for this work? |
Thank you for your quick response @zacharyburnett |
@WPringle do mean for the correction? StormEvents/stormevents/nhc/track.py Lines 980 to 987 in 2895957
Now I moved all of that logic to a function at the end of the StormEvents/stormevents/nhc/track.py Lines 1167 to 1169 in 2ebcc72
Does that answer your question? |
@SorooshMani-NOAA I mean what is the example? Like the command from CLI or main python script? So I can repeat and check on my system and try with other advisories too. |
import stormevents
my_track = stormevents.nhc.VortexTrack('al062018', file_deck='a')
my_track.to_file("path/to/output/file.dat") and then look at
and inspect the entries of the It only automatically applies this on Please let me know if this is useful to add or not, thanks! Update
|
@SorooshMani-NOAA I think there is something going wrong with getting pressure from CARQ.
|
@SorooshMani-NOAA The Rmax seems to be correct. |
@SorooshMani-NOAA How is the |
@SorooshMani-NOAA I think we are very close to be able to get single advisory, all you need to do is use Using the following I could get the file with only OFCL inside correctly: |
@SorooshMani-NOAA Then we may add another capability in another PR for a variable called Or we could have a variable called |
@WPringle Thanks for testing
This is the logic: StormEvents/stormevents/nhc/track.py Lines 1189 to 1227 in 2ebcc72
So the radius of max wind is picked up from the StormEvents/stormevents/nhc/track.py Lines 1213 to 1215 in 2ebcc72
but forecast's StormEvents/stormevents/nhc/track.py Line 1218 in 2ebcc72
and the forecast's StormEvents/stormevents/nhc/track.py Lines 1221 to 1227 in 2ebcc72
I assumed this correction was reviewed between you and @zacharyburnett so I didn't touch it. Please let me know if it needs to change. |
@SorooshMani-NOAA I can go in and make the changes in the code for the correct pressures if you think that's OK? |
I'm not sure if I fully understand what you mean, may be it will be covered by this: #70 If it does, please add the description of your use-case in that ticket, if not please either create a new Issue, or let me know so that I can create a new one and copy your description from above. We can then discuss the details on that separate ticket. |
@WPringle sure, please feel free to do so, then please push it to the same branch or create a new branch and I'll merge. |
I think all they do is to filter track entries returned by Let's discuss the details of the expected behavior in the new ticket. Updated |
@SorooshMani-NOAA yeah but I still don't understand why entries that have datetimes before the |
…und pressure, correcting comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's working correctly to replace OFCL central pressure, background pressure, and Rmax from the 0-hr CARQ. So can merge this PR and work on the datetime issue in PR #70
Fixes #64, #65, #66, #67