michaelaye / nbplanetary

A nbdev-based approach to create a core library for planetarypy
https://michaelaye.github.io/nbplanetary/
MIT License
7 stars 1 forks source link

Fails to get MRO CTX index #59

Open cjtu opened 3 months ago

cjtu commented 3 months ago

Following this CTX example from the docs gives error (but other indices like hirise work)

from planetarypy.pds.apps import get_index
ctrindex = get_index("mro.ctx", "edr", refresh=False)
ctrindex.sample(5, random_state=42)  # setting random_state to always get same files for docs

Output:

{
    "name": "IndexError",
    "message": "list index out of range",
    "stack": "---------------------------------------------------------------------------
ParserError                               Traceback (most recent call last)
File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/planetarypy/pds/indexes.py:51, in Index.__init__(self, key, url, check_update)
     50 try:
---> 51     self.timestamp = parser.parse(config.get_value(self.key)[\"timestamp\"])
     52 except (toml.exceptions.NonExistentKey, ParserError):

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/dateutil/parser/_parser.py:1368, in parse(timestr, parserinfo, **kwargs)
   1367 else:
-> 1368     return DEFAULTPARSER.parse(timestr, **kwargs)

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/dateutil/parser/_parser.py:646, in parser.parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
    645 if len(res) == 0:
--> 646     raise ParserError(\"String does not contain a date: %s\", timestr)
    648 try:

ParserError: String does not contain a date: 

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
Cell In[3], line 1
----> 1 ctrindex = get_index(\"mro.ctx\", \"edr\", refresh=False)
      2 ctrindex.sample(5, random_state=42)  # setting random_state to always get same files for docs

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/planetarypy/pds/apps.py:33, in get_index(instr, index_name, refresh, force)
     31     index = Index(instr, check_update=refresh)
     32 else:
---> 33     index = Index(instr + \".indexes.\" + index_name, check_update=refresh)
     34 if not index.local_table_path.exists() or force:
     35     index.download()

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/planetarypy/pds/indexes.py:53, in Index.__init__(self, key, url, check_update)
     51     self.timestamp = parser.parse(config.get_value(self.key)[\"timestamp\"])
     52 except (toml.exceptions.NonExistentKey, ParserError):
---> 53     if self.local_label_path.exists():
     54         self.timestamp = datetime.fromtimestamp(
     55             self.local_label_path.stat().st_mtime
     56         )
     57         self.update_timestamp()

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/planetarypy/pds/indexes.py:146, in Index.local_label_path(self)
    144 @property
    145 def local_label_path(self):
--> 146     return self.local_dir / self.label_filename

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/planetarypy/pds/indexes.py:113, in Index.label_filename(self)
    111     return Path(str(self.url).split(\"/\")[-1])
    112 else:
--> 113     return Path.ls(self.local_dir, file_exts=[\".lbl\", \".LBL\"])[0]

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/fastcore/foundation.py:112, in L.__getitem__(self, idx)
--> 112 def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)

File ~/miniforge3/envs/plpy/lib/python3.12/site-packages/fastcore/foundation.py:116, in L._get(self, i)
    115 def _get(self, i):
--> 116     if is_indexer(i) or isinstance(i,slice): return getattr(self.items,'iloc',self.items)[i]
    117     i = mask2idxs(i)
    118     return (self.items.iloc[list(i)] if hasattr(self.items,'iloc')
    119             else self.items.__array__()[(i,)] if hasattr(self.items,'__array__')
    120             else [self.items[i_] for i_ in i])

IndexError: list index out of range"
}
michaelaye commented 3 months ago

interesting. could you try with refresh=True to see if that is the issue?

michaelaye commented 3 months ago

it looks like that maybe it never was downloaded?

cjtu commented 3 months ago

Ah ok, refresh=True downloads it and it works normally now with refresh=True or False. Weird that refresh=False works the first time for mro.hirise but not mro.ctx. I can reproduce by deleting downloaded indices.

Running get_index("mro.ctx", "edr", refresh=False) creates all the directories (/mro/ctx/indexes/edr), but they are empty (no download) and I get the error above.

But for get_index("mro.hirise", "rdr"), all dirs are correctly made and the index is downloaded as normal