-
Notifications
You must be signed in to change notification settings - Fork 11
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
IndexError: list index out of range in open_data() #30
Comments
Hi @break2make. As stated on the package website, nctoolkit will not work on Windows. Your options would be to either use Linux/macOS or use the Linux subsystem for Windows. |
Hello, I have the same error in open_data() while working with Ubuntu (via Virtual Box), nctoolkit 0.8.6, CDO 2.1.1 and Python 3.10.8. |
Can you provide the line of code that's giving the problem and the full python error? The package is tested daily with CDO 2.1.1 and Python 3.10.8: https://app.circleci.com/pipelines/github/pmlmodelling/nctoolkit. And the tests are all passing at the minute. So it's most likely a versioning issue. Potentially conda is installing a very old version of a dependency that's incompatible in some way. If possible, could you upload a .yml file with your conda environment and I can possibly see if I can reproduce the problem. |
Yes, thank you for your really quick answer. My code (with screenshot attached) : IndexError Traceback (most recent call last) File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/api.py:755, in open_data(x, checks, **kwargs) File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/api.py:1506, in DataSet.contents(self) File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/api.py:1335, in DataSet.show_contents(self, n) IndexError: list index out of range` I don't see how to upload a .yml here (file type not supported) but here is my spec file |
OK. Based on the output, nctoolkit's backend CDO does not like the file that much, @agnesfrancois . Is there anyway to share the file? For now, you could try:
This won't check the contents of the file when it is opened. The checking is currently throwing the error. Can you try running this on the command line:
and add the results on here? That will show if there is a fundamental problem with the data itself or if maybe I need to tweak something in nctoolkit to handle the file. |
OK. That's strange. Based on that, you shouldn't be getting the error message. It sounds like there is some issue calling CDO (using subprocess) in nctoolkit. What errors are you getting when you try methods? |
Can you try the following:
If that doesn't work then there must be package mismatch. Also, try: That should show |
Indeed, there is a problem with both tests. The dataset has been reset to the starting point due to a run failure! Please change commands, where applicable, and re-run.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/runthis.py:1024, in run_this(os_command, self, output, out_file, suppress)
1022 else:
-> 1024 target = run_cdo(
1025 ff_command, target, out_file, precision=self._precision
1026 )
1027 target_list.append(target)
File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/runthis.py:593, in run_cdo(command, target, out_file, overwrite, precision)
592 remove_safe(target)
--> 593 raise ValueError(f"{command} was not successful. Check output")
595 session_info["latest_size"] = os.path.getsize(target)
ValueError: cdo -L -seltimestep,1 https://psl.noaa.gov/thredds/dodsC/Datasets/COBE/sst.mon.mean.nc /var/tmp/nctoolkitzmxhixgrnctoolkittmpnti50ji4.nc was not successful. Check output
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
Cell In[15], line 4
2 ds = nc.open_thredds("https://psl.noaa.gov/thredds/dodsC/Datasets/COBE/sst.mon.mean.nc")
3 ds.subset(time = 0)
----> 4 ds.plot()
File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/plot.py:61, in plot(self, vars, autoscale, out, coast, **kwargs)
58 kwargs["title"] = ""
60 # run any commands
---> 61 self.run()
63 if session_info["coast"]:
64 coast = True
File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/run.py:38, in run(self)
35 if self._merged:
36 output_method = "one"
---> 38 run_this(cdo_command, self, output=output_method)
40 self._merged = False
42 self._execute = False
File ~/anaconda3/envs/cdo/lib/python3.10/site-packages/nctoolkit/runthis.py:1198, in run_this(os_command, self, output, out_file, suppress)
1196 except Exception as e:
1197 self.reset()
-> 1198 raise ValueError(e)
ValueError: cdo -L -seltimestep,1 https://psl.noaa.gov/thredds/dodsC/Datasets/COBE/sst.mon.mean.nc /var/tmp/nctoolkitzmxhixgrnctoolkittmpnti50ji4.nc was not successful. Check output |
OK. It sounds like something has gone wrong in your conda environment and CDO isn't accesssible from Python. Try this:
You should get something like the output below. If you don't then something has gone wrong in your conda environment. Climate Data Operators version 2.1.1 (https://mpimet.mpg.de/cdo) |
That suggests the jupyter notebook you are using is not actually from the CDO environment. Check by running this in the notebook
You should see CDO in the packages. Otherwise, the notebook package is probably outside the CDO environment. |
Very strange. Try this in the notebook:
It's possible the Python version being used by the notebook does not actually come from the environment. Did you specify Python version when creating the environment? |
OK that's strange. CDO is in the environment, but is not accessible from the notebook. Running |
Hello ! Problem solved after checking this page : https://code.mpimet.mpg.de/boards/1/topics/13131 , jupyterlab was not installed in my virtual environment, so the notebook could not really make a link |
Thanks for confirming the problem @agnesfrancois. Always tricky to ensure everything you are using is in the environment |
I have a similar trouble on Ubuntu and wonder if a solution is available?
|
Hi @fipoucat. Which version of nctoolkit and CDO are installed? |
Hi, I am using nctoolkit 0.8.7 and cdo 2.1.1 |
Can you double check that you are actually using nctoolkit 0.8.7 in your environment @fipoucat ? It looks like it is picking up a much older version. You are getting an error at line 54 in the init.py file. But there isn't a line 54 : https://github.com/pmlmodelling/nctoolkit/blob/master/nctoolkit/__init__.py This looks like nctoolkit version 0.2.X, which won't work with CDO 2.0.X because they changed how output was returned. |
I'll try to uninstall it and reinstall and will update you |
@robertjwilson, that's correct in the cdo env version 0.2.2 was installed so uninstalling it solved the issue. |
I was too fast, when testing the example I am getting a strange error: |
Please add the code that caused the issue. This doesn't sound like something that could happen, so it's probably an environment issue. |
I am testing the example in the user guide: import numpy as mp ds = nc.open_data("/home/sarr/work/READING_ASSESS/sst.mon.mean.nc") Cell In[4], line 1 AttributeError: module 'nctoolkit' has no attribute 'open_data' |
I don't think there is anything within nctoolkit that could cause that too happen. Something must have gone wrong when installing or setting up environments. What happens when you try to autocomplete after typing |
I cleaned all installation and now working after reinstalled. Thank you |
Thanks @fipoucat |
@robertjwilson , |
This is normally not something to worry about. nctoolkit uses CDO which will preserve the netCDF data type when carrying out calculations. So if you have an integer data type, all calculations will use that data type. However, you can change thedata type by doing
In general, data type doesn't matter too much. There are some cases where you need to be careful. For example, let's say you wanted to calculate the fraction of years when temperature in a dataset was above 10 C. You could do the following:
However, if the data type is integer, you will probably just have 0s and 1s in the dataset before tmean, and you can only end up with a 0 or 1 in the output because it is integer. |
Hello, i get the same error when trying to import nctoolkit. `--------------------------------------------------------------------------- File ~/miniconda3/lib/python3.10/site-packages/nctoolkit/init.py:54 File ~/miniconda3/lib/python3.10/site-packages/nctoolkit/init.py:26, in valid(string) IndexError: list index out of range` I have cdo version 2.0.3 |
Which version of nctoolkit are you using @denisthenichita? Based on the error message, you have an old version installed. This can happen when you install with conda, which can install version 0.2x instead of a recent version. Old versions of nctoolkit won't work with CDO 2.0x because they changed how output was returned. Try updating to nctoolkit 0.9.0. Also update CDO to 2.0.5 or above. nctoolkit won't work with CDO 2.0.3 because a bug in CDO was causing one of the nctoolkit tests to fail. This was fixed in 2.0.5. |
Thank you for the very quick response. |
That version is almost 2.5 years old. Just do this to get the latest:
My recommendation would be to use mambaforge instead of conda. You won't run into these issues with it as much: https://github.com/conda-forge/miniforge |
I'm using Python 3.10 in Windows 10. Please help to resolve this issue.
The text was updated successfully, but these errors were encountered: