@@ -190,6 +190,10 @@ def __init__( # noqa: PLR0913
190190 "proxy_adinos" : "algae" ,
191191 "proxy_diatoms" : "Purples" ,
192192 "proxy_hdinos" : "Blues" ,
193+ "avgrois" : "YlOrRd" ,
194+ "casetemp" : "thermal" ,
195+ "casehumidity" : "PuBu" ,
196+ "casepress" : "deep" ,
193197 }
194198
195199 def _open_ds (self ):
@@ -407,6 +411,20 @@ def _get_biolume_plot_variables(self) -> list:
407411 return self ._get_lrauv_biolume_variables ()
408412 return self ._get_dorado_biolume_variables ()
409413
414+ def _get_planktivore_plot_variables (self ) -> list :
415+ """Get planktivore + context variables for plot_planktivore_2column()."""
416+ return [
417+ ("backseat_planktivore_hm_avgrois" , "linear" ),
418+ ("backseat_planktivore_lm_avgrois" , "linear" ),
419+ ("backseat_planktivore_casetemp" , "linear" ),
420+ ("backseat_planktivore_casehumidity" , "linear" ),
421+ ("density" , "linear" ),
422+ ("wetlabsbb2fl_particulatebackscatteringcoeff470nm" , "linear" ),
423+ ("wetlabsbb2fl_particulatebackscatteringcoeff650nm" , "linear" ),
424+ ("wetlabsbb2fl_mass_concentration_of_chlorophyll_in_sea_water" , "linear" ),
425+ ("backseat_planktivore_casepress" , "linear" ),
426+ ]
427+
410428 def _plot_nighttime_indicator (
411429 self ,
412430 fig : matplotlib .figure .Figure ,
@@ -1750,12 +1768,11 @@ def plot_biolume_2column(self) -> str: # noqa: C901, PLR0912, PLR0915
17501768
17511769 self ._open_ds ()
17521770
1753- # Early return if no biolume variables present
1754- biolume_prefix = "wetlabsubat_" if self ._is_lrauv () else "biolume_"
1755- if not any (v . startswith ( biolume_prefix ) for v in self . ds . variables ):
1771+ # Early return if no biolume plot variables present in dataset
1772+ plot_variables = self ._get_biolume_plot_variables ()
1773+ if not any (var in self . ds for var , _ in plot_variables ):
17561774 self .logger .warning (
1757- "No %s* variables found in dataset, skipping plot_biolume_2column" ,
1758- biolume_prefix ,
1775+ "No biolume plot variables found in dataset, skipping plot_biolume_2column" ,
17591776 )
17601777 return None
17611778
@@ -1868,6 +1885,143 @@ def plot_biolume_2column(self) -> str: # noqa: C901, PLR0912, PLR0915
18681885 self .logger .info ("Saved biolume 2column plot to %s" , output_file )
18691886 return str (output_file )
18701887
1888+ def plot_planktivore_2column (self ) -> str : # noqa: C901, PLR0912, PLR0915
1889+ """Create 2-column planktivore plot with map, ROIs, engineering, and context.
1890+
1891+ Layout (5 rows x 2 columns, column-major order):
1892+ (0,0) track map (0,1) density
1893+ (1,0) hm_avgrois (1,1) backscatter470
1894+ (2,0) lm_avgrois (2,1) backscatter650
1895+ (3,0) casetemp (3,1) chlorophyll
1896+ (4,0) casehumidity (4,1) casepress
1897+ """
1898+ # Skip plotting in pytest environment - too many prerequisites for CI
1899+ if "pytest" in sys .modules :
1900+ self .logger .info ("Skipping plot_planktivore_2column in pytest environment" )
1901+ return None
1902+
1903+ self ._open_ds ()
1904+
1905+ # Early return if no planktivore plot variables present in dataset
1906+ planktivore_vars = [
1907+ v
1908+ for v , _ in self ._get_planktivore_plot_variables ()
1909+ if v .startswith ("backseat_planktivore_" )
1910+ ]
1911+ if not any (var in self .ds for var in planktivore_vars ):
1912+ self .logger .warning (
1913+ "No backseat_planktivore plot variables found in dataset, "
1914+ "skipping plot_planktivore_2column" ,
1915+ )
1916+ return None
1917+
1918+ idist , iz , distnav = self ._grid_dims ()
1919+ if idist .size == 0 or iz .size == 0 or distnav .size == 0 :
1920+ self .logger .warning (
1921+ "Skipping plot_planktivore_2column due to missing gridding dimensions"
1922+ )
1923+ return None
1924+
1925+ fig , ax = plt .subplots (nrows = 5 , ncols = 2 , figsize = (18 , 10 ))
1926+ plt .subplots_adjust (hspace = 0.15 , wspace = 0.04 , left = 0.05 , right = 0.97 , top = 0.96 , bottom = 0.06 )
1927+
1928+ best_ctd = None
1929+ if self ._is_lrauv ():
1930+ self .logger .info ("LRAUV mission detected for planktivore 2column plot" )
1931+ self ._compute_density_lrauv ()
1932+ else :
1933+ self .logger .info ("Dorado mission detected for planktivore 2column plot" )
1934+ best_ctd = self ._get_best_ctd ()
1935+ self ._compute_density (best_ctd )
1936+
1937+ self ._plot_track_map (ax [0 , 0 ], ax [1 , 0 ])
1938+
1939+ if self .auv_name and self .mission :
1940+ try :
1941+ gulper_locations = self ._get_gulper_locations (distnav )
1942+ except FileNotFoundError as e :
1943+ self .logger .warning ("Error retrieving gulper locations: %s" , e ) # noqa: TRY400
1944+ gulper_locations = {}
1945+ else :
1946+ try :
1947+ gulper_locations = self ._get_sipper_locations (distnav )
1948+ except FileNotFoundError as e :
1949+ self .logger .warning ("Error retrieving sipper locations: %s" , e ) # noqa: TRY400
1950+ gulper_locations = {}
1951+
1952+ try :
1953+ profile_bottoms = self ._profile_bottoms (distnav )
1954+ except (TypeError , ValueError ) as e :
1955+ self .logger .warning ("Error computing profile bottoms: %s" , e ) # noqa: TRY400
1956+ profile_bottoms = None
1957+
1958+ try :
1959+ bottom_depths = self ._get_bathymetry (
1960+ self .ds .cf ["longitude" ].to_numpy (),
1961+ self .ds .cf ["latitude" ].to_numpy (),
1962+ )
1963+ except ValueError as e : # noqa: BLE001
1964+ self .logger .warning ("Error retrieving bathymetry: %s" , e ) # noqa: TRY400
1965+ bottom_depths = None
1966+
1967+ row = 1
1968+ col = 0
1969+
1970+ plot_variables = self ._get_planktivore_plot_variables ()
1971+
1972+ for var , scale in plot_variables :
1973+ self .logger .info ("Plotting %s..." , var )
1974+ if var not in self .ds :
1975+ self .logger .warning ("%s not in dataset, plotting with no data" , var )
1976+
1977+ self ._plot_var (
1978+ var ,
1979+ idist ,
1980+ iz ,
1981+ distnav ,
1982+ fig ,
1983+ ax ,
1984+ row ,
1985+ col ,
1986+ profile_bottoms ,
1987+ scale = scale ,
1988+ gulper_locations = gulper_locations ,
1989+ bottom_depths = bottom_depths ,
1990+ best_ctd = best_ctd ,
1991+ )
1992+ if row != 4 : # noqa: PLR2004
1993+ ax [row , col ].get_xaxis ().set_visible (False )
1994+ else :
1995+ ax [row , col ].set_xlabel ("Distance along track (km)" )
1996+
1997+ if row == 4 and col == 0 : # noqa: PLR2004
1998+ row = 0
1999+ col = 1
2000+ else :
2001+ row += 1
2002+
2003+ self ._plot_nighttime_indicator (fig , ax [0 , 1 ], distnav )
2004+
2005+ if self ._is_lrauv ():
2006+ netcdfs_dir = Path (BASE_LRAUV_PATH , f"{ Path (self .log_file ).parent } " )
2007+ output_file = Path (
2008+ netcdfs_dir ,
2009+ f"{ Path (self .log_file ).stem } _{ self .freq } _2column_planktivore.png" ,
2010+ )
2011+ else :
2012+ images_dir = Path (BASE_PATH , self .auv_name , MISSIONIMAGES , self .mission )
2013+ Path (images_dir ).mkdir (parents = True , exist_ok = True )
2014+ output_file = Path (
2015+ images_dir ,
2016+ f"{ self .auv_name } _{ self .mission } _{ self .freq } _2column_planktivore.png" ,
2017+ )
2018+ plt .savefig (output_file , dpi = 100 , bbox_inches = "tight" )
2019+ plt .show ()
2020+ plt .close (fig )
2021+
2022+ self .logger .info ("Saved planktivore 2column plot to %s" , output_file )
2023+ return str (output_file )
2024+
18712025 def _get_best_ctd (self ) -> str :
18722026 """Determine best CTD to use for ODV lookup table based on metadata"""
18732027 # LRAUV doesn't use multiple CTDs, return None
@@ -2333,6 +2487,7 @@ def process_command_line(self):
23332487 p_start = time .time ()
23342488 cp .plot_2column ()
23352489 cp .plot_biolume_2column ()
2490+ cp .plot_planktivore_2column ()
23362491 if cp .mission and cp .auv_name :
23372492 cp .gulper_odv ()
23382493 if cp .log_file :
0 commit comments