Skip to content

Commit

Permalink
more flexible from-file reading
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Mar 10, 2022
1 parent 669c963 commit 2123230
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions stormevents/nhc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ def __init__(
self.__invalid_storm_name = False
self.__location_hash = None

self.file_deck = file_deck
self.mode = mode
self.record_type = record_type

if isinstance(storm, DataFrame):
self.unfiltered_data = storm
elif isinstance(storm, (str, PathLike, pathlib.Path)):
Expand All @@ -102,6 +98,10 @@ def __init__(
except ValueError:
raise

self.file_deck = file_deck
self.mode = mode
self.record_type = record_type

self.__previous_configuration = self.__configuration

# use start and end dates to mask dataframe here
Expand Down Expand Up @@ -164,13 +164,7 @@ def from_file(
except:
pass

return cls(
storm=path,
start_date=start_date,
end_date=end_date,
file_deck=list(ATCF_FileDeck),
record_type=list(ATCF_RecordType),
)
return cls(storm=path, start_date=start_date, end_date=end_date,)

@property
def name(self) -> str:
Expand Down Expand Up @@ -364,7 +358,7 @@ def file_deck(self) -> ATCF_FileDeck:

@file_deck.setter
def file_deck(self, file_deck: ATCF_FileDeck):
if file_deck is None:
if file_deck is None and self.filename is None:
file_deck = ATCF_FileDeck.BEST
elif not isinstance(file_deck, ATCF_FileDeck):
file_deck = typepigeon.convert_value(file_deck, ATCF_FileDeck)
Expand Down Expand Up @@ -421,7 +415,9 @@ def record_type(self, record_type: ATCF_RecordType):

@property
def valid_record_types(self) -> List[ATCF_RecordType]:
if self.file_deck == ATCF_FileDeck.ADVISORY:
if self.file_deck is None:
valid_record_types = [record_type.value for record_type in ATCF_RecordType]
elif self.file_deck == ATCF_FileDeck.ADVISORY:
# see ftp://ftp.nhc.noaa.gov/atcf/docs/nhc_techlist.dat
# there are more but they may not have enough columns
valid_record_types = [
Expand Down

0 comments on commit 2123230

Please sign in to comment.