fmaussion/salem

GoogleVisibleMap with negative latitude

Closed this issue · 2 comments

AFAICT GoogleVisibleMap doesn't like negative values. For example, i'm trying to plot a region straddling the equator.

Changing the -5 to 1 for example works.

from salem import GoogleVisibleMap, Map

g = GoogleVisibleMap(x=[100, 110], y=[-5, 5],
                     scale=4, maptype='satellite')

ggl_img = g.get_vardata()


InvalidURL Traceback (most recent call last)
in
----> 1 ggl_img = g.get_vardata()

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/salem/datasets.py in get_vardata(self, var_id)
551 def get_vardata(self, var_id=0):
552 """Return and subset the image."""
--> 553 return self._img[self.sub_y[0]:self.sub_y[1]+1,
554 self.sub_x[0]:self.sub_x[1]+1, :]
555

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/salem/init.py in _lazy_property(self)
30 def _lazy_property(self):
31 if not hasattr(self, attr_name):
---> 32 setattr(self, attr_name, fn(self))
33 return getattr(self, attr_name)
34

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/salem/datasets.py in _img(self)
543 """Download the image."""
544 if self.use_cache:
--> 545 return utils.joblib_read_img_url(self.googleurl.generate_url())
546 else:
547 from matplotlib.image import imread

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/joblib/memory.py in call(self, *args, **kwargs)
589
590 def call(self, *args, **kwargs):
--> 591 return self._cached_call(args, kwargs)[0]
592
593 def getstate(self):

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/joblib/memory.py in _cached_call(self, args, kwargs, shelving)
532
533 if must_call:
--> 534 out, metadata = self.call(*args, **kwargs)
535 if self.mmap_mode is not None:
536 # Memmap the output at the first call to be consistent with

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/joblib/memory.py in call(self, *args, **kwargs)
759 if self._verbose > 0:
760 print(format_call(self.func, args, kwargs))
--> 761 output = self.func(*args, **kwargs)
762 self.store_backend.dump_item(
763 [func_id, args_id], output, verbose=self._verbose)

~/local/bin/anaconda3/envs/dev/lib/python3.8/site-packages/salem/utils.py in joblib_read_img_url(url)
287
288 from matplotlib.image import imread
--> 289 fd = urlopen(url, timeout=10)
290 return imread(io.BytesIO(fd.read()))
291

~/local/bin/anaconda3/envs/dev/lib/python3.8/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):

~/local/bin/anaconda3/envs/dev/lib/python3.8/urllib/request.py in open(self, fullurl, data, timeout)
523
524 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 525 response = self._open(req, data)
526
527 # post-process response

~/local/bin/anaconda3/envs/dev/lib/python3.8/urllib/request.py in _open(self, req, data)
540
541 protocol = req.type
--> 542 result = self._call_chain(self.handle_open, protocol, protocol +
543 '_open', req)
544 if result:

~/local/bin/anaconda3/envs/dev/lib/python3.8/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result

~/local/bin/anaconda3/envs/dev/lib/python3.8/urllib/request.py in https_open(self, req)
1391
1392 def https_open(self, req):
-> 1393 return self.do_open(http.client.HTTPSConnection, req,
1394 context=self._context, check_hostname=self._check_hostname)
1395

~/local/bin/anaconda3/envs/dev/lib/python3.8/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1348 try:
1349 try:
-> 1350 h.request(req.get_method(), req.selector, req.data, headers,
1351 encode_chunked=req.has_header('Transfer-encoding'))
1352 except OSError as err: # timeout error

~/local/bin/anaconda3/envs/dev/lib/python3.8/http/client.py in request(self, method, url, body, headers, encode_chunked)
1253 encode_chunked=False):
1254 """Send a complete request to the server."""
-> 1255 self._send_request(method, url, body, headers, encode_chunked)
1256
1257 def _send_request(self, method, url, body, headers, encode_chunked):

~/local/bin/anaconda3/envs/dev/lib/python3.8/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1264 skips['skip_accept_encoding'] = 1
1265
-> 1266 self.putrequest(method, url, **skips)
1267
1268 # chunked encoding will happen if HTTP/1.1 is used and either

~/local/bin/anaconda3/envs/dev/lib/python3.8/http/client.py in putrequest(self, method, url, skip_host, skip_accept_encoding)
1098
1099 url = url or '/'
-> 1100 self._validate_path(url)
1101
1102 request = '%s %s %s' % (method, url, self._http_vsn_str)

~/local/bin/anaconda3/envs/dev/lib/python3.8/http/client.py in _validate_path(self, url)
1198 match = _contains_disallowed_url_pchar_re.search(url)
1199 if match:
-> 1200 raise InvalidURL(f"URL can't contain control characters. {url!r} "
1201 f"(found at least {match.group()!r})")
1202

InvalidURL: URL can't contain control characters. '/maps/api/staticmap?key=AIzaSyAjPH6t6Y2OnPDNHesGFvTaVzaaFWj_WCE&maptype=satellite&format=png&scale=4&center=1600 Amphitheatre Parkway Mountain View, CA&zoom=6&size=640x640&sensor=false&language=en' (found at least ' ')

Thanks for the report. The problem is not the negative lat, but the center on `lat=0' : this is a bug in motionless, which interprets lat=0 as kwarg not set.