stcorp / coda

The Common Data Access toolset
http://stcorp.github.io/coda/doc/html/index.html
BSD 3-Clause "New" or "Revised" License
39 stars 17 forks source link

Using a combined path in python intermediate array fetching no longer works #91

Closed svniemeijer closed 1 year ago

svniemeijer commented 1 year ago

When using an AEOLUS L2B file, this works:

>>> coda.fetch(product, 'mie_geolocation', -1,'windresult_geolocation', 'latitude_cog')

But this doesn't:

>>> coda.fetch(product, 'mie_geolocation', -1,'windresult_geolocation/latitude_cog')
coda.CodacError: coda_type_get_record_field_index_from_name(): record does not contain a field named 'windresult_geolocation/latitude_cog'

We should be using a cursor_goto to traverse any string arguments.

srepmub commented 1 year ago

oh darnit. it looks like I mistakenly had assumed that path 'elements' are always field names. this means the 'reldepth' and goto_parent strategy optimization also doesn't work. for now I reverted the type_path and goto_parent optimizations..

if we want such optimizations again, we could perhaps detect the case that we only have field lookups (and integers) in the whole 'path'. in this case we can cache field indices and backtrack without having to call get_cursor_depth (twice)..

can we easily see that a node expression is just a field lookup? (alternatively we could also check that the whole node expression matches a field name in the current record).

srepmub commented 1 year ago

(for just field names joined with '/' we could also cache field indices of course..)

svniemeijer commented 1 year ago

An alternative to using goto_parent is to create a copy of the cursor and using that to navigate the subtree:

import copy
cursor = coda.Cursor()
cursor2 = copy.deepcopy(cursor)

This copied cursor can then be thrown away instead of having to call goto_parent.

Not sure how this works with the type_path part.

srepmub commented 1 year ago

so this would probably be quite slow..

svniemeijer commented 1 year ago

This was fixed in version 2.24.2