ACCESS-Cloud-Based-InSAR / dem-stitcher

Download and merge DEM tiles
Apache License 2.0
39 stars 15 forks source link

BadZipFile: File is not a zip file #83

Closed sugizo closed 9 hours ago

sugizo commented 1 month ago

The bug

/usr/local/lib/python3.10/dist-packages/dem_stitcher/stitcher.py:138: UserWarning: We need to localize the tiles as a Geotiff. Saving to tmp_f08d402f-9a1f-4ccc-907c-c35741d781ab
  warn(f"We need to localize the tiles as a Geotiff. Saving to {str(tile_dir)}", category=UserWarning)
Downloading srtm_v3 tiles:   0%|          | 0/2 [00:00<?, ?it/s]
---------------------------------------------------------------------------
BadZipFile                                Traceback (most recent call last)
[<ipython-input-22-1ebc4ae49366>](https://localhost:8080/#) in <cell line: 26>()
     24 area_or_point = 'Point'
     25 
---> 26 X, p = stitch_dem(bounds_tif, 
     27                   dem_name = 'srtm_v3',  # srtm_v3, nasadem
     28                   dst_ellipsoidal_height = ellipsoidal_height,

14 frames
[/usr/lib/python3.10/zipfile.py](https://localhost:8080/#) in _RealGetContents(self)
   1334             raise BadZipFile("File is not a zip file")
   1335         if not endrec:
-> 1336             raise BadZipFile("File is not a zip file")
   1337         if self.debug > 1:
   1338             print(endrec)

BadZipFile: File is not a zip file

To Reproduce

from dem_stitcher import stitch_dem
from dem_stitcher.datasets import DATASETS
from geopy.geocoders import Nominatim

geolocator = Nominatim(user_agent = "Chrome")

location = geolocator.geocode('rome, italy')

latitude = location.latitude
longitude = location.longitude

factor_lat = 0.2
factor_lon = 0.2

min_lat = float("{:.1f}".format(latitude - factor_lat) )
max_lat = float("{:.1f}".format(latitude + factor_lat) )
min_lon = float("{:.1f}".format(longitude - factor_lon) )
max_lon = float("{:.1f}".format(longitude + factor_lon) )

# as xmin, ymin, xmax, ymax in epsg:4326
bounds_tif = [min_lon, min_lat, max_lon, max_lat]
ellipsoidal_height = False
area_or_point = 'Point'

X, p = stitch_dem(bounds_tif, 
                  dem_name = 'srtm_v3',  # srtm_v3, nasadem
                  dst_ellipsoidal_height = ellipsoidal_height,
                  dst_area_or_point = area_or_point)

Additional context

error only occurs when use dem_name : srtm_v3 and nasadem

best regards

cmarshak commented 1 month ago

Hi @sugizo - can you make sure that you have the correct credentials stored in your ~/.netrc?

machine urs.earthdata.nasa.gov
    login <username>
    password <password>

I have to make a PR that makes the error more human readable as this error is totally indecipherable - I am sorry about that.

cmarshak commented 1 month ago

There is a blurb in the readme but really needs better error handling.

https://github.com/ACCESS-Cloud-Based-InSAR/dem-stitcher?tab=readme-ov-file#credentials