read-ICESat-2 icon indicating copy to clipboard operation
read-ICESat-2 copied to clipboard

NameError: name 'i1' is not defined

Open GKG1312 opened this issue 1 year ago • 5 comments

Hi Tyler

In Fit ICESat-2 ATL03.ipynb file while running the Calculate average surface height for each beam section I am getting error corresponding to variable initialization. There is no previous initialization of variable i1 before it is used in line if np.any((dem_h[i1[i2]] >= (tlm_bot_band-tlm_buffer)) & (dem_h[i1[i2]] <= (tlm_top[b][idx]+tlm_buffer))):

The error is stated as: `--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [13], in <cell line: 2>() 681 for b in ['band1','band2']: 682 # bottom of the telemetry band for major frame 683 tlm_bot_band = tlm_top[b][idx] - tlm_height[b][idx] --> 684 if np.any((dem_h[i1[i2]] >= (tlm_bot_band-tlm_buffer)) & 685 (dem_h[i1[i2]] <= (tlm_top[b][idx]+tlm_buffer))): 686 # add telemetry height to window width 687 h_win_width += tlm_height[b][idx] 688 # photon indices for major frame (buffered by 1 frame on each side) 689 # do not use possible TEP photons in photon classification

NameError: name 'i1' is not defined`

Thanks Girish

GKG1312 avatar Feb 16 '23 05:02 GKG1312

Same issue here

ChaoEcohydroRS avatar Feb 20 '23 16:02 ChaoEcohydroRS

sorry @GKG1312 and @ChaoEcohydroRS, not sure how I didn't see this. I'm putting in a PR #75 to hopefully fix this for you.

tsutterley avatar Mar 21 '23 18:03 tsutterley

Hi @tsutterley, Thank you for your help. It seems that the error is resolved but I am getting some new errors regarding indices.


TypeError Traceback (most recent call last) Cell In[6], line 749 747 frame_number = np.copy(val['heights']['pce_mframe_cnt'][idx]) 748 # along-track X and Y coordinates --> 749 distance_along_X = np.copy(x_atc[idx:idx+cnt]) 750 distance_along_Y = np.copy(y_atc[idx:idx+cnt]) 751 # average background photon rate for segment

File ~/miniconda3/envs/bathy/lib/python3.9/site-packages/numpy/ma/core.py:3222, in MaskedArray.getitem(self, indx) 3212 """ 3213 x.getitem(y) <==> x[y] 3214 3215 Return the item described by i, as a masked array. 3216 3217 """ 3218 # We could directly use ndarray.getitem on self. 3219 # But then we would have to modify array_finalize to prevent the 3220 # mask of being reshaped if it hasn't been set up properly yet 3221 # So it's easier to stick to the current version -> 3222 dout = self.data[indx] 3223 _mask = self._mask 3225 def _is_scalar(m):

TypeError: only integer scalar arrays can be converted to a scalar index

This error is raised in the following lines of code:

distance_along_X = np.copy(x_atc[idx:idx+cnt])
distance_along_Y = np.copy(y_atc[idx:idx+cnt])

I checked the variables and found that idx is a list of indices, and cnt is a scalar value. I think there should be some confusion about slicing the array it should be either idx alone or idx should be an scalar. While tracing in from start I lost the idea of using idx . Can you have a look into it. Thank you Girish

GKG1312 avatar Mar 23 '23 08:03 GKG1312

yep should just be [idx]. fixed in #76

tsutterley avatar Mar 23 '23 16:03 tsutterley

thanks for tracking these down! I haven't touched these notebooks in a while since sliderule now has most of the functionality

tsutterley avatar Mar 23 '23 16:03 tsutterley