flopy icon indicating copy to clipboard operation
flopy copied to clipboard

bug: flopy.utils.binaryfile.HeadUFile.get_ts() gives error for idx= 0

Open giovannifi opened this issue 2 years ago • 1 comments

I am trying to run this script:

import flopy
import flopy.utils.binaryfile as bf

path_exe = r'C:\modflow'
path_model = r'c:\models'
modelname = 'mymodel'

heads = bf.HeadUFile(path_model + '\\' + modelname + '.hds')  # hds file generated with the software mf-usg

print(heads.get_ts(idx=0))

and I get the following error message:

{IndexError}index -682005 is out of bounds for axis 0 with size XXXX

If I use any number between 1 and (XXXX - 1), I get a timeseries without any problem. I have the feeling that the command does not read node 0.

PS I am running flopy v 3.3.5 on a python 3.9 environment.

giovannifi avatar Aug 29 '22 07:08 giovannifi

Hey @giovannifi, this should be fixed by https://github.com/modflowpy/flopy/pull/1510. To get around this until a new release you can work from the head of the develop branch.

wpbonelli avatar Aug 29 '22 12:08 wpbonelli

Hi @giovannifi was this problem resolved for you? I rechecked some of flopy's example .hds files and didn't encounter the issue. Wanted to confirm before closing as there is a new release coming shortly.

wpbonelli avatar Nov 12 '22 13:11 wpbonelli

I am currently using python 3.9. I tried to run pip install flopy --upgrade but it does not give me the possibility to get the latest version of flopy (3.3.6). So I cannot really verify. Do I need to run python 3.10 to be able to install the latest version of flopy?

giovannifi avatar Nov 13 '22 08:11 giovannifi

Try to add the --force-reinstall switch

...just noticed you aren't pointing it to the develop branch. Use this: Pip install https://github.com/modflowpy/flopy/zipball/develop -U --force-reinstall

cnicol-gwlogic avatar Nov 13 '22 08:11 cnicol-gwlogic

tried that, it installs version 3.3.5.

giovannifi avatar Nov 13 '22 09:11 giovannifi

See my edited comment

cnicol-gwlogic avatar Nov 13 '22 09:11 cnicol-gwlogic

The command does not work for me due to SSL certificate limitation imposed by my company policies. it seems I can get the package only from the official repository. I have to work out with IT how I can run your command. For the moment this is the error message I get:

Collecting https://github.com/modflowpy/flopy/zipball/develop
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate signature failure (_ssl.c:1123)'))': /modflowpy/flopy/zipball/develop
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate signature failure (_ssl.c:1123)'))': /modflowpy/flopy/zipball/develop
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate signature failure (_ssl.c:1123)'))': /modflowpy/flopy/zipball/develop
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate signature failure (_ssl.c:1123)'))': /modflowpy/flopy/zipball/develop
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate signature failure (_ssl.c:1123)'))': /modflowpy/flopy/zipball/develop
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /modflowpy/flopy/zipball/develop (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate signature failure (_ssl.c:1123)')))

giovannifi avatar Nov 13 '22 09:11 giovannifi

Not sure on that one. You could try this instead: Pip install -U --force-reinstall git+https://github.com/modflowpy/flopy@develop

cnicol-gwlogic avatar Nov 13 '22 09:11 cnicol-gwlogic

@giovannifi if you're on mac and haven't previously installed certificates for your Python distribution, this might help

wpbonelli avatar Nov 13 '22 15:11 wpbonelli

Thanks all for the suggestions. I have finally managed to bypass the SSL issue by downloading the zip flopy package and manually install version 3.3.6. I re-run my script and it does not throw any error. So, yes this can be closed.

Thanks

giovannifi avatar Nov 14 '22 03:11 giovannifi

For future reference, @giovannifi, how did you manage to install it?

mbakker7 avatar Nov 14 '22 08:11 mbakker7

@mbakker7 I used the link provided by @cnicol-gwlogic in the post above (https://github.com/modflowpy/flopy/zipball/develop). This allowed me to download a zip file. Then I simply run the command: pip install <zipfilename>.zip

As you are asking, I take advantage of this to say the things I do not understand:

  • why is the zip file called modflowpy-flopy-3.3.5-215-g00757a4.zip, i.e. why does the file name contain the old flopy version? I can confirm that after the installation I had version 3.3.6 installed.
  • why is not posible to install the upgrade from the official repository (pypi.org)? if you check this page https://pypi.org/project/flopy/ the latest version is still 3.3.5.

giovannifi avatar Nov 14 '22 09:11 giovannifi

Let me start with a question: Did the suggestion from @cnicol-gwlogic not work? I think that is the official approach to pip install a version from a specific branch on github (although I have never tried that myself). Did you try it that way or do you have administrator restrictions to run that command? Or does that command only give you the zip file?

Version 3.3.6 has not been officially released. You installed the development branch from github, which has a file called version.py which contains the version number for when the development branch becomes the latest release. Once the development branch is the latest release, it will be possible to install it with pip install.

mbakker7 avatar Nov 14 '22 10:11 mbakker7

@mbakker7 I thought my previous messages were pretty clear in this regard. I explained that @cnicol-gwlogic command did not work in my case as my company restricts the access to some external websites via command line executions. I do not really know the details of the problem, I sent a request to the IT of my company to discover the issue but I got no answer. In any case the command returned a SSL certificate issue. I had similar problems in the past that were related to my company policy restrictions. Indeed, I do not have admin rights for my PC. If you want to see the error message I got, please check my post above. I simply copied and pasted the link in the command provided by @cnicol-gwlogic into a web browser and this downloaded the above mentioned zip file.

giovannifi avatar Nov 14 '22 11:11 giovannifi

I normally recommend the zipfile approach for two reasons: (1) it does not depend on git being installed (with certificates, etc.), and (2) it is faster to process. The git+https method does not work without git, and takes longer since it needs to clone every commit from the repo (from the first f9e98ed8428fa8ddb4e8b1e5ab493cacb8eab238 and onwards).

This should work to upgrade a pip-installed version:

pip uninstall --yes flopy
pip install https://github.com/modflowpy/flopy/archive/refs/heads/develop.zip

mwtoews avatar Nov 15 '22 00:11 mwtoews