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

Error: NeededInitPrefix is not defined #157

Closed
ryan-salo opened this issue Jun 5, 2023 · 4 comments
Closed

Error: NeededInitPrefix is not defined #157

ryan-salo opened this issue Jun 5, 2023 · 4 comments

Comments

@ryan-salo
Copy link

I tried running:

from localtileserver import get_leaflet_tile_layer, TileClient
from ipyleaflet import Map

client = TileClient("/tmp/local.tif")

And got this error:

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/large_image/tilesource/geo.py:230, in GDALBaseFileTileSource.getPixelSizeInMeters(self)
    223 def getPixelSizeInMeters(self):
    224     """
    225     Get the approximate base pixel size in meters.  This is calculated as
    226     the average scale of the four edges in the WGS84 ellipsoid.
    227 
    228     :returns: the pixel size in meters or None.
    229     """
--> 230     bounds = self.getBounds(NeededInitPrefix + 'epsg:4326')
    231     if not bounds:
    232         return

NameError: name 'NeededInitPrefix' is not defined

Env setup:

# conda only used to install env, python, and pip:
mamba create -n localtileserver -c conda-forge python pip
conda activate localtileserver
pip install localtileserver jupyterlab ipyleaflet
#ipyleaflet                0.17.3
#jupyterlab                4.0.1
#localtileserver           0.7.0
#pip                       23.1.2
#python                    3.11.3
Here is the full stack trace
File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/localtileserver/client.py:908, in BaseTileClient.__init__(self, filename, default_projection, port, debug, host, client_port, client_host, client_prefix, cors_all)
    906 elif isinstance(filename, RasterioFileTileSource):
    907     filename = filename._getLargeImagePath()
--> 908 super().__init__(filename=filename, default_projection=default_projection)
    909 app = AppManager.get_or_create_app(cors_all=cors_all)
    910 self._key = launch_server(app, port=port, debug=debug, host=host)

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/localtileserver/client.py:482, in LocalTileClient.__init__(self, filename, default_projection)
    476 def __init__(
    477     self,
    478     filename: Union[pathlib.Path, str],
    479     default_projection: Optional[str] = "EPSG:3857",
    480 ):
    481     super().__init__(filename, default_projection)
--> 482     self._tile_source = get_tile_source(self.filename, self.default_projection)

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/localtileserver/client.py:82, in BaseTileClientInterface.default_projection(self)
     79 @property
     80 def default_projection(self):
     81     if self._default_projection == "":
---> 82         self._default_projection = "EPSG:3857" if self.is_geospatial else None
     83     return self._default_projection

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/localtileserver/client.py:433, in BaseTileClientInterface.is_geospatial(self)
    430 @property
    431 def is_geospatial(self):
    432     if self._is_geospatial is None:
--> 433         self._is_geospatial = self.metadata(projection=None).get("geospatial", False)
    434     return self._is_geospatial

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/localtileserver/client.py:603, in LocalTileClient.metadata(self, projection)
    601     if projection == "":
    602         projection = self.default_projection
--> 603     tile_source = get_tile_source(self.filename, projection)
    604     self._metadata[projection] = get_meta_data(tile_source)
    605 return self._metadata[projection]

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/localtileserver/tiler/utilities.py:72, in get_tile_source(path, projection, style, encoding)
     68 def get_tile_source(
     69     path: Union[pathlib.Path, str], projection: str = None, style: str = None, encoding: str = "PNG"
     70 ) -> RasterioFileTileSource:
     71     path = get_clean_filename(path)
---> 72     return RasterioFileTileSource(str(path), projection=projection, style=style, encoding=encoding)

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/large_image/cache_util/cache.py:227, in LruCacheMetaclass.__call__(cls, *args, **kwargs)
    225         except Exception:
    226             pass
--> 227     raise exc
    228 instance._classkey = key
    229 with cacheLock:

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/large_image/cache_util/cache.py:218, in LruCacheMetaclass.__call__(cls, *args, **kwargs)
    216         return result
    217 try:
--> 218     instance = super().__call__(*args, **kwargs)
    219     # for pickling
    220     instance._initValues = (args, kwargs.copy())

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/large_image_source_rasterio/__init__.py:136, in RasterioFileTileSource.__init__(self, path, projection, unitsPerPixel, **kwargs)
    129     self.sourceSizeY = self.sizeY = self.dataset.height
    131 # netCDF is blacklisted from rasterio so it won't be used.
    132 # use the mapnik source if needed. This variable is always ignored
    133 # is_netcdf = False
    134 
    135 # get the different scales and projections from the image
--> 136 scale = self.getPixelSizeInMeters()
    138 # raise an error if we are missing some information about the projection
    139 # i.e. we don't know where to place it on a map
    140 isProjected = self.projection or self.dataset.driver.lower() in {'png'}

File ~/miniconda3/envs/localtileserver/lib/python3.11/site-packages/large_image/tilesource/geo.py:230, in GDALBaseFileTileSource.getPixelSizeInMeters(self)
    223 def getPixelSizeInMeters(self):
    224     """
    225     Get the approximate base pixel size in meters.  This is calculated as
    226     the average scale of the four edges in the WGS84 ellipsoid.
    227 
    228     :returns: the pixel size in meters or None.
    229     """
--> 230     bounds = self.getBounds(NeededInitPrefix + 'epsg:4326')
    231     if not bounds:
    232         return

NameError: name 'NeededInitPrefix' is not defined
@banesullivan
Copy link
Owner

This was bound to happen with the massive refactor in girder/large_image#1115

Seems I introduced this bug following the refactor in girder/large_image#1182

@ryan-salo, the quick fix on your end is to install pyproj. I'll patch this upstream in large-image though

@banesullivan
Copy link
Owner

See girder/large_image#1190

@banesullivan
Copy link
Owner

Fix upstream will be in next large image release. I'm going to leave this open to remember to bump the minimum version here

@banesullivan
Copy link
Owner

localtileserver>=0.7.1 resolves this issue

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

2 participants