Skip to content

KeyError: "['stratum'] not in index" error in load_survey_data() #28

@emiliom

Description

@emiliom

I ran into an error on my first attempt at running EchoPro using the minimal_echopro_workflow.ipynb notebook. Specifically, on cell 3, survey_2019.load_survey_data(), I get this error:

KeyError: "['stratum'] not in index"

@b-reyes could you look into it?

I'm using the same set of input files I used in July.

I installed the echopro environment using a slight variation of your instructions and requirements file, but my changes are specifically focused on jupyter/ipython packages so they should not affect anything being done in survey_2019.load_survey_data(). Specifically:

mamba create -c conda-forge -n echopro python=3.9 ipykernel --file requirements.txt
conda activate echopro
pip install -e .

Where requirements.txt is:

geopandas==0.10.2
PyYAML==6.0
xarray==2022.3.0
geopy==2.2.0
openpyxl==3.0.9
ipywidgets==7.7.0
ipympl==0.8.7
numba==0.55.1
# notebook==6.4.11
# nb_conda_kernels==2.3.1
# jupyter_contrib_nbextensions==0.5.1

Here is the complete error trace:

KeyError                                  Traceback (most recent call last)
File <timed eval>:1

File /usr/mayorgadat/workmain/acoustics/gh/uw-echospace/EchoPro/EchoPro/survey/survey.py:222, in Survey.load_survey_data(self, file_type)
    220 # load all associated stratification data
    221 if file_type in ('strata', 'all'):
--> 222     LoadStrataData(self)
    224 if file_type in ('nasc', 'all'):
    225     self.nasc_df = load_nasc_data.load_nasc_df(self)

File /usr/mayorgadat/workmain/acoustics/gh/uw-echospace/EchoPro/EchoPro/load_stratification_data/load_stratification_data.py:29, in LoadStrataData.__init__(self, survey)
     26 # expected columns for geo strata Dataframe
     27 self.geo_strata_cols = {'Strata index', 'Latitude (upper limit)'}
---> 29 self._load_stratification_file()
     30 self._load_geographic_stratification()
     31 self._get_strata_sig_b()

File /usr/mayorgadat/workmain/acoustics/gh/uw-echospace/EchoPro/EchoPro/load_stratification_data/load_stratification_data.py:63, in LoadStrataData._load_stratification_file(self)
     60 self._check_strata_df(strata_df)
     62 # extract only those columns that are necessary
---> 63 strata_df = strata_df[['Year', 'stratum', 'Haul', 'wt']].copy()
     65 # set data types of dataframe
     66 strata_df = strata_df.astype({'Year': int, 'stratum': int,
     67                               'Haul': int, 'wt': np.float64})

File ~/miniconda3/envs/echopro/lib/python3.9/site-packages/pandas/core/frame.py:3511, in DataFrame.__getitem__(self, key)
   3509     if is_iterator(key):
   3510         key = list(key)
-> 3511     indexer = self.columns._get_indexer_strict(key, "columns")[1]
   3513 # take() does not accept boolean indexers
   3514 if getattr(indexer, "dtype", None) == bool:

File ~/miniconda3/envs/echopro/lib/python3.9/site-packages/pandas/core/indexes/base.py:5796, in Index._get_indexer_strict(self, key, axis_name)
   5793 else:
   5794     keyarr, indexer, new_indexer = self._reindex_non_unique(keyarr)
-> 5796 self._raise_if_missing(keyarr, indexer, axis_name)
   5798 keyarr = self.take(indexer)
   5799 if isinstance(key, Index):
   5800     # GH 42790 - Preserve name from an Index

File ~/miniconda3/envs/echopro/lib/python3.9/site-packages/pandas/core/indexes/base.py:5859, in Index._raise_if_missing(self, key, indexer, axis_name)
   5856     raise KeyError(f"None of [{key}] are in the [{axis_name}]")
   5858 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())
-> 5859 raise KeyError(f"{not_found} not in index")

KeyError: "['stratum'] not in index"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions