Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'i1' is not defined #73

Open
GKG1312 opened this issue Feb 16, 2023 · 5 comments
Open

NameError: name 'i1' is not defined #73

GKG1312 opened this issue Feb 16, 2023 · 5 comments

Comments

@GKG1312
Copy link

GKG1312 commented Feb 16, 2023

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

@ChaoEcohydroRS
Copy link

Same issue here

@tsutterley
Copy link
Owner

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.

@GKG1312
Copy link
Author

GKG1312 commented Mar 23, 2023

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

@tsutterley
Copy link
Owner

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

@tsutterley
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants