Skip to content

Commit 3e2ac5a

Browse files
committed
addtional sets of error figs in case all local data points are nan
1 parent 259690a commit 3e2ac5a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

enacts/onset/maproom.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,11 @@ def onset_plots(
429429
int(dry_spell),
430430
time_coord="T",
431431
)
432+
isnan = np.isnan(onset_delta["onset_delta"]).mean()
433+
if isnan == 1:
434+
error_fig = pingrid.error_fig(error_msg="No onset dates were found")
435+
germ_sentence = ""
436+
return error_fig, error_fig, germ_sentence
432437
except TypeError:
433438
error_fig = pingrid.error_fig(
434439
error_msg="Please ensure all input boxes are filled for the calculation to run."
@@ -552,6 +557,10 @@ def cess_plots(
552557
int(cess_dry_spell),
553558
time_coord="T",
554559
)
560+
isnan = np.isnan(cess_delta["cess_delta"]).mean()
561+
if isnan == 1:
562+
error_fig = pingrid.error_fig(error_msg="No cessation dates were found")
563+
return error_fig, error_fig, tab_style
555564
except TypeError:
556565
error_fig = pingrid.error_fig(error_msg="Please ensure all input boxes are filled for the calculation to run.")
557566
return (
@@ -669,6 +678,10 @@ def length_plots(
669678
int(dry_spell),
670679
time_coord="T",
671680
)
681+
isnan = np.isnan(onset_delta["onset_delta"]).mean()
682+
if isnan == 1:
683+
error_fig = pingrid.error_fig(error_msg="No onset dates were found")
684+
return error_fig, error_fig, tab_style
672685
except TypeError:
673686
error_fig = pingrid.error_fig(
674687
error_msg="Please ensure all onset input boxes are filled."
@@ -685,17 +698,29 @@ def length_plots(
685698
int(cess_dry_spell),
686699
time_coord="T",
687700
)
701+
isnan = np.isnan(cess_delta["cess_delta"]).mean()
702+
if isnan == 1:
703+
error_fig = pingrid.error_fig(error_msg="No cessation dates were found")
704+
return error_fig, error_fig, tab_style
688705
except TypeError:
689706
error_fig = pingrid.error_fig(error_msg="Please ensure all cessation input boxes are filled")
690707
return error_fig, error_fig, tab_style
691708
if cess_delta["T"][0] < onset_delta["T"][0]:
692709
cess_delta = cess_delta.isel({"T": slice(1, None)})
693710
if cess_delta["T"].size != onset_delta["T"].size:
694711
onset_delta = onset_delta.isel({"T": slice(None, -2)})
695-
seasonal_length = (
696-
(cess_delta["T"] + cess_delta["cess_delta"]).drop_indexes("T")
697-
- (onset_delta["T"] + onset_delta["onset_delta"]).drop_indexes("T")
698-
)
712+
try:
713+
seasonal_length = (
714+
(cess_delta["T"] + cess_delta["cess_delta"]).drop_indexes("T")
715+
- (onset_delta["T"] + onset_delta["onset_delta"]).drop_indexes("T")
716+
)
717+
isnan = np.isnan(seasonal_length).mean()
718+
if isnan == 1:
719+
error_fig = pingrid.error_fig(error_msg="Onset or cessation not found for any season")
720+
return error_fig, error_fig, tab_style
721+
except TypeError:
722+
error_fig = pingrid.error_fig(error_msg="Please ensure all onset/cessation input boxes are filled")
723+
return error_fig, error_fig, tab_style
699724
length_graph = pgo.Figure()
700725
length_graph.add_trace(
701726
pgo.Scatter(

0 commit comments

Comments
 (0)