Cannot create `VortexTrack` from it's output dataframe
SorooshMani-NOAA opened this issue · comments
A standardized dataframe can be obtained by calling .fort_22()
for .atcf()
of a VortexTrack
object. If we pass this obtained Dataframe
back as storm
to create a new VotexTrack
, it fails, because it expects a datetime
object for the column with the same name.
In [1]: storm = stormevents.StormEvent('Florence', 2018)
In [2]: track = storm.track()
In [3]: new_track = stormevents.nhc.track.VortexTrack(storm=track.atcf())
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [3], line 1
----> 1 new_track = stormevents.nhc.track.VortexTrack(storm=track.atcf())
File ~/miniconda3/envs/ensemble/lib/python3.9/site-packages/stormevents/nhc/track.py:100, in VortexTrack.__init__(self, storm, start_date, end_date, file_deck, advisories)
97 self.advisories = advisories
98 self.file_deck = file_deck
--> 100 self.__previous_configuration = self.__configuration
102 # use start and end dates to mask dataframe here
103 self.start_date = start_date
File ~/miniconda3/envs/ensemble/lib/python3.9/site-packages/stormevents/nhc/track.py:997, in VortexTrack.__configuration(self)
994 @property
995 def __configuration(self) -> Dict[str, Any]:
996 return {
--> 997 'id': self.nhc_code,
998 'file_deck': self.file_deck,
999 'advisories': self.advisories,
1000 'filename': self.filename,
1001 }
File ~/miniconda3/envs/ensemble/lib/python3.9/site-packages/stormevents/nhc/track.py:240, in VortexTrack.nhc_code(self)
235 if self.__nhc_code is None and not self.__invalid_storm_name:
236 if self.__unfiltered_data is not None:
237 nhc_code = (
238 f'{self.__unfiltered_data["basin"].iloc[-1]}'
239 f'{self.__unfiltered_data["storm_number"].iloc[-1]}'
--> 240 f'{self.__unfiltered_data["datetime"].iloc[-1].year}'
241 )
242 try:
243 self.nhc_code = nhc_code
AttributeError: 'str' object has no attribute 'year'
The usecase for doing this is to get the storm track, then modify its data (e.g. perturb half of it, but not the other half then concatenate the two halves) and then create a new VortexTrack
from the modified data.
In my specific use case, I perturbed part of the tracks using EnsemblePerturbation
and needed to concatenate it with the rest of the track that was not perturbed. So I read-in the perturbed *.22
files into a VortexTrack
using .from_file(...)
and realized my perturbed_segment_track.data
is different in format from the original_segment_track.data
and in order to concatenate them I used .fort_22()
to standardize both of them to the same thing! But then I could not create a new VortexTrack
from the concatenated dataframes