oceanmodeling / StormEvents

Python interfaces for observational data surrounding named storm events, born from @jreniel's ADCIRCpy
https://stormevents.readthedocs.io
GNU General Public License v3.0
24 stars 8 forks source link

Add functionality to pick advisory by date #69

Closed SorooshMani-NOAA closed 1 year ago

SorooshMani-NOAA commented 1 year ago

Feature request by @WPringle: An API to choose a specific advisory based on the track start date.

SorooshMani-NOAA commented 1 year ago

@WPringle I just noticed that separate_tracks is doing most of the work. It creates a dictionary of dictionary of dataframes. The outer dictionary keys are advisory names, e.g. OFCL, CARQ, HWRF, etc. the inner dictionary keys are track_start_times (or best_track_time for best track). This means that if you get the full atcf-file dataframe and then call separate_tracks on it, you can get a track with specific advisory_name and track_start_time. For example

import stormevents

track = stormevents.nhc.VortexTrack.from_storm_name('harvey', 2017, file_deck='a')
track_dict = stormevents.nhc.track.separate_tracks(track.data)
track_of_interest = track_dict['OFCL']['20170824T060000']

This covers the use-case, but maybe we can make it easier by adding an API like:

track_of_interest = track.get_track(advisory_name, datetime)

which basically executes the steps above, but can, for example, accept datetime object instead of string formatted time. What do you think?

Update calling track.tracks already takes care of calling stormevents.nhc.track.separate_tracks(track.data) and returns the track_dict

WPringle commented 1 year ago

@SorooshMani-NOAA Interesting. We could just use this but then need think about start_time and end_time. It could be fine to just say that is only relevant for best_track? Then still need to add capability to fill in CARQ from previous times if we want to spin up.

WPringle commented 1 year ago

@SorooshMani-NOAA I tried doing this and it works to get back a dataframe but now I can't write out to .to_file as a fort.22/ATCF .dat.

SorooshMani-NOAA commented 1 year ago

@WPringle, you need to create a new VortexTrack object now using this dataframe. You can just pass it like filtered_track = VortexTrack(my_filtered_df, file_deck=THESAMEASBEFORE, advisories=THESAMEASBEFORE) and then call to_file on the new object.

WPringle commented 1 year ago

@SorooshMani-NOAA Interesting thanks. So this is my working example (that works):

from stormevents.nhc import VortexTrack

if __name__ == '__main__':

    event = VortexTrack(
        storm='al062018',
        advisories='OFCL',
        file_deck='a',
    )
    tracks = event.tracks
    track = tracks['OFCL']['20180912T180000']
    track = VortexTrack(track, file_deck='a', advisories='OFCL')
    track.to_file('stormevents_adv54.dat',overwrite=True)
WPringle commented 1 year ago

@SorooshMani-NOAA Maybe if we can make this into a single function could be good!

SorooshMani-NOAA commented 1 year ago

Fixed by #82