You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, since I want to automate this task, I want to use the raster max and min values instead of coding the numbers by hand. Thus, I used variables rastermin and rastermax I got from the raster statistics:
But I get an error: TypeError: The provided min value must be scalar type.
However, the variables are in fact scalar. When inspecting the code a little deeper I note that map_widgets.py only asks if the max and min variables are either int or float:
83 vmin = vis_params.get("min", kwargs.pop("vmin", 0))
84 if type(vmin) not in (int, float):
85 raise TypeError("The provided min value must be scalar type.")
My min and max variables are scalar, just a different type of float:
type(rastermin)
numpy.float32
And to confirm that this is the problem, this works fine: vis_params = {'min': float(rastermin), 'max': float(rastermax), 'palette': 'terrain'}
Conclusion
I see two alternatives
Change the error message:
To match the behavior of the code and change the error message to TypeError: The provided min/max values can only be 'int' or 'float'.
Allow other types:
Allow float32 (and possible other numpy types?). Maybe this could be done by forcing the conversion to int or float as I did above.
Acknowledgement
Thanks a lot for this great library!
The text was updated successfully, but these errors were encountered:
Environment Information
Description
I'm adding a layer of a single-band raster file.
This includes the following code:
However, since I want to automate this task, I want to use the raster max and min values instead of coding the numbers by hand. Thus, I used variables
rastermin
andrastermax
I got from the raster statistics:3. vis_params = {'min': rastermin, 'max': rastermax, 'palette': 'terrain'}
But I get an error:
TypeError: The provided min value must be scalar type.
However, the variables are in fact scalar. When inspecting the code a little deeper I note that
map_widgets.py
only asks if themax
andmin
variables are eitherint
orfloat
:My min and max variables are scalar, just a different type of float:
And to confirm that this is the problem, this works fine:
vis_params = {'min': float(rastermin), 'max': float(rastermax), 'palette': 'terrain'}
Conclusion
I see two alternatives
Change the error message:
To match the behavior of the code and change the error message to
TypeError: The provided min/max values can only be 'int' or 'float'.
Allow other types:
Allow float32 (and possible other numpy types?). Maybe this could be done by forcing the conversion to int or float as I did above.
Acknowledgement
Thanks a lot for this great library!
The text was updated successfully, but these errors were encountered: