Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'False: boolean label can not be used without a boolean index' when using gt.calc_fluorescence #182

Closed
TToolsee opened this issue Jun 19, 2023 · 2 comments · Fixed by #184
Labels
bug Something isn't working

Comments

@TToolsee
Copy link

TToolsee commented Jun 19, 2023

Describe the bug
I'm using the same glider data used in the GliderTools paper and I'm trying to conduct a quenching correction on the fluorescence data to eventually calculate chl_a from it. I keep getting the following error and I'm not quite sure how to fix it?

To Reproduce
`
##% Importing data with xarray
sg = xr.open_dataset(base_dir + 'GLIDER_SAZ_SOSCEx3_MERGED.nc')#,decode_times=False)
flr = sg.flr_raw
dives = sg.dives
depth = sg.depth
time = sg.time
lat = sg.latitude
lon = sg.longitude

Identify bad fluorescence profiles

flr_iqr = gt.cleaning.outlier_bounds_iqr(flr, multiplier=3)

bad_profiles = gt.optics.find_bad_profiles(dives, depth, flr_iqr,
ref_depth=300,
stdev_multiplier=4,
method='mean')
flr_goodprof = flr_iqr.where(~bad_profiles[0])

fluorescence dark count

flr_dark = gt.optics.fluorescence_dark_count(flr_iqr, depth)

flr_base, flr_spikes = gt.cleaning.despike(flr_dark, 11, spike_method='median')

Quenching correction

flr_qnch, flr, qnch_layer, [fig1, fig2] = gt.calc_fluorescence(
flr_base, bbp700, dives, depth, time, lat, lon, 53, 0.0121,
profiles_ref_depth=300, deep_method='mean', deep_multiplier=1,
spike_window=11, spike_method='median', return_figure=True,
night_day_group=False, sunrise_sunset_offset=2, verbose=True)`

Error obtained:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/var/folders/ft/m5x6lgcj519d4rqmtbkkm1m40000gn/T/ipykernel_34646/2703357150.py in <cell line: 1>()
----> 1 flr_qnch, flr, qnch_layer, [fig1, fig2] = gt.calc_fluorescence(
      2     flr_base, bbp700, dives, depth, time, lat, lon, 53, 0.0121,
      3     profiles_ref_depth=300, deep_method='mean', deep_multiplier=1,
      4     spike_window=11, spike_method='median', return_figure=True,
      5     night_day_group=False, sunrise_sunset_offset=2, verbose=True)

~/opt/anaconda3/envs/ocean/lib/python3.9/site-packages/glidertools/processing.py in calc_fluorescence(flr_raw, bbp, dives, depth, time, lat, lon, dark_count, scale_factor, spike_window, spike_method, night_day_group, sunrise_sunset_offset, profiles_ref_depth, deep_multiplier, deep_method, return_figure, verbose)
    639 
    640     printv(verbose, "\tQuenching correction")
--> 641     quench_corrected, quench_layer = op.quenching_correction(
    642         baseline,
    643         bbp,

~/opt/anaconda3/envs/ocean/lib/python3.9/site-packages/glidertools/optics.py in quenching_correction(flr, bbp, dives, depth, time, lat, lon, max_photic_depth, night_day_group, surface_layer, sunrise_sunset_offset)
    701     # get the binned averages for each batch and select the night
    702     night_ave = df.groupby([day, batch, np.around(depth)]).mean()
--> 703     night_ave = night_ave.dropna().loc[False]
    704     # A second group where only batches are grouped
    705     grp_batch = df.groupby(batch)

~/opt/anaconda3/envs/ocean/lib/python3.9/site-packages/pandas/core/indexing.py in __getitem__(self, key)
   1071 
   1072             maybe_callable = com.apply_if_callable(key, self.obj)
-> 1073             return self._getitem_axis(maybe_callable, axis=axis)
   1074 
   1075     def _is_scalar_access(self, key: tuple):

~/opt/anaconda3/envs/ocean/lib/python3.9/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
   1309 
   1310         # fall thru to straight lookup
-> 1311         self._validate_key(key, axis)
   1312         return self._get_label(key, axis=axis)
   1313 

~/opt/anaconda3/envs/ocean/lib/python3.9/site-packages/pandas/core/indexing.py in _validate_key(self, key, axis)
   1116             or self.obj._get_axis(axis).dtype.name == "boolean"
   1117         ):
-> 1118             raise KeyError(
   1119                 f"{key}: boolean label can not be used without a boolean index"
   1120             )

KeyError: 'False: boolean label can not be used without a boolean index'
@MartinMohrmann
Copy link
Member

MartinMohrmann commented Jun 20, 2023

Hi,
Thank you for reporting this issue! It is not obvious to me how the quenching_correction, and especially the crashing line
night_ave = night_ave.dropna().loc[False] are supposed to work. I am not the author of the code, but I have the impression that the 'isday' variable should be used here to select only the nighttime, i.e. isday==False. I hope to find some more time to look into this in the start of July. If you in the meantime make any progress yourself with analyzing or fixing this issue let us know!

@MartinMohrmann MartinMohrmann added the bug Something isn't working label Jun 22, 2023
@TToolsee
Copy link
Author

TToolsee commented Jul 7, 2023

Hi Martin,

I'm also quite confused about how to fix the error. I've tried setting isday==False or even setting night_day_group=True but both did not fix the error. Still no progress with fixing the error on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants