@@ -49,6 +49,21 @@ def _fix(units: str) -> str:
4949 return ds
5050
5151
52+ def fix_lndgrid_coords (ds : xr .Dataset ) -> xr .Dataset :
53+ """
54+ Return a dataset with coordinates properly assigned.
55+
56+ Note
57+ ----
58+ E3SM/CESM2 raw land model output comes as if it were run over sites in the
59+ `lndgrid` dimension. Some of the variables that are listed in these files
60+ are only of this dimension and really belong in the coordinates. These tend
61+ to be things like `lat`, `lon`, etc. and ilamb3 needs them to be associated
62+ with the dataset coordinates to work.
63+ """
64+ return ds .assign_coords ({v : ds [v ] for v in ds if ds [v ].dims == ("lndgrid" ,)})
65+
66+
5267def select_analysis_variable (setup : dict [str , Any ]) -> str :
5368 """
5469 Return the main variable to be used in this analysis.
@@ -358,6 +373,8 @@ def _load_comparison_data(
358373 # Fix bounds attributes (there is a bounds variable but it isn't in the
359374 # attributes)
360375 com = {var : dset .fix_missing_bounds_attrs (ds ) for var , ds in com .items ()}
376+ # Fix lndgrid cooridates if raw E3SM/CESM2 data is given
377+ com = {var : fix_lndgrid_coords (ds ) for var , ds in com .items ()}
361378 # Merge all the data together
362379 if len (com ) > 1 :
363380 # The grids should be the same, but sometimes models generate output
@@ -547,21 +564,34 @@ def run_single_block(
547564 "Reference intermediate data was not generated."
548565 ) # pragma: no cover
549566
567+ log_file = output_path / "post.log"
568+ log_id = logger .add (log_file , backtrace = True , diagnose = True )
569+
550570 # Phase 2: get plots and combine scalars and save
551- plt .rcParams .update ({"figure.max_open_warning" : 0 })
552- df = pd .concat (df_all ).drop_duplicates (
553- subset = ["source" , "region" , "analysis" , "name" ]
554- )
555- df = add_overall_score (df )
556- df_plots = plot_analyses (df , ds_ref , ds_com , analyses , output_path )
571+ try :
572+ plt .rcParams .update ({"figure.max_open_warning" : 0 })
573+ df = pd .concat (df_all ).drop_duplicates (
574+ subset = ["source" , "region" , "analysis" , "name" ]
575+ )
576+ df = add_overall_score (df )
577+ df_plots = plot_analyses (df , ds_ref , ds_com , analyses , output_path )
578+ except Exception :
579+ logger .exception (f"ILAMB analysis '{ block_name } ' failed in plotting." )
580+ return
557581
558582 # Generate an output page
559- if ilamb3 .conf ["debug_mode" ] and (output_path / "index.html" ).is_file ():
583+ try :
584+ if ilamb3 .conf ["debug_mode" ] and (output_path / "index.html" ).is_file ():
585+ logger .remove (log_id )
586+ return
587+ ds_ref .attrs ["header" ] = block_name
588+ html = generate_html_page (df , ds_ref , ds_com , df_plots )
589+ with open (output_path / "index.html" , mode = "w" ) as out :
590+ out .write (html )
591+ except Exception :
592+ logger .exception (f"ILAMB analysis '{ block_name } ' failed in generating html." )
560593 return
561- ds_ref .attrs ["header" ] = block_name
562- html = generate_html_page (df , ds_ref , ds_com , df_plots )
563- with open (output_path / "index.html" , mode = "w" ) as out :
564- out .write (html )
594+ logger .remove (log_id )
565595
566596
567597def run_analyses (
0 commit comments