LinkedEarth / PyleoTutorials

Jupyter-based, science-driven tutorials for using the LinkedEarth data-software Python ecosystem
http://linked.earth/PyleoTutorials
Apache License 2.0
14 stars 7 forks source link

indexing issue in from_PaleoEnsembleArray #72

Closed CommonClimate closed 2 weeks ago

CommonClimate commented 3 weeks ago

Currently, what is holding up the completion of L1_working_with_age_ensembles.ipynb is this line:

ensemble = pyleo.EnsembleGeoSeries.from_PaleoEnsembleArray(geo_series = ts, paleo_array = paleoValues, age_depth = ts.depth, paleo_depth = paleoDepth)

Traceback:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[26], line 8
      1 ts = pyleo.GeoSeries(time = chronValues, value = paleo_row['paleoData_values'].iloc[0], 
      2                      time_name =  time_name, time_unit = time_unit,
      3                      value_name = value_name, value_unit = value_unit,
      4                      label = 'MD98-2181', archiveType = 'Marine sediment',
      5                      depth = chronDepth, depth_name = 'Depth', depth_unit = 'cm', lat = paleo_df['geo_meanLat'].iloc[0],
      6                     lon = paleo_df['geo_meanLon'].iloc[0])
----> 8 ensemble = pyleo.EnsembleGeoSeries.from_PaleoEnsembleArray(geo_series = ts, paleo_array = paleoValues, age_depth = ts.depth, paleo_depth = paleoDepth)

File [~/Documents/GitHub/Pyleoclim_util/pyleoclim/core/ensemblegeoseries.py:441](http://localhost:60043/doc/tree/~/Documents/GitHub/Pyleoclim_util/pyleoclim/core/ensemblegeoseries.py#line=440), in EnsembleGeoSeries.from_PaleoEnsembleArray(self, geo_series, paleo_array, paleo_depth, age_depth, extrapolate, verbose)
    438         raise ValueError("Age depth and series time need to have the same length")
    440     #Interpolate the age array to the value depth
--> 441     mapped_paleo = lipdutils.mapAgeEnsembleToPaleoData(
    442         ensembleValues=paleo_array, 
    443         depthEnsemble=paleo_depth, 
    444         depthMapping=age_depth,
    445         extrapolate=extrapolate
    446     )
    448 series_list = []
    450 #check that mapped_age and the original time vector are similar, and that the object is not a geoseries object

File [~/Documents/GitHub/Pyleoclim_util/pyleoclim/utils/lipdutils.py:1187](http://localhost:60043/doc/tree/~/Documents/GitHub/Pyleoclim_util/pyleoclim/utils/lipdutils.py#line=1186), in mapAgeEnsembleToPaleoData(ensembleValues, depthEnsemble, depthMapping, extrapolate)
   1184 depthMapping = np.array(depthMapping)
   1186 #Interpolate
-> 1187 ensembleValuesMapped = np.zeros((len(depthMapping),np.shape(ensembleValues)[1])) #placeholder
   1189 if extrapolate is True:
   1190     for i in np.arange(0,np.shape(ensembleValues)[1]):

IndexError: tuple index out of range

@alexkjames I think you were the one who wrote this Pyleoclim function - can you please take a look?

alexkjames commented 2 weeks ago

This is actually not a function issue, but a data issue (and an error handling issue). The function was expecting an array, but receiving a vector. This seems to be related to a change in the data and/or the data loading procedure. I've adjusted the code in the tutorial to be more robust, and will include additional error handling in the function in the near-ish future.

alexkjames commented 2 weeks ago

Fixed by ff5590ce37bd144f6f5dec429305f9116c567243