Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2Convenience functions to call everything. 

3 

4Anything implemented here should be caching. 

5""" 

6from pathlib import Path 

7from typing import Optional, Tuple 

8 

9from .get_mars_data import fetch_data, generate_fn 

10from .read_mars_data import read_ascii_data 

11 

12 

13def get_parse_data(**kwargs) -> Tuple[dict, Optional[Path]]: 

14 """Get and parse data. 

15 

16 This is a convenience function. It first checks for 

17 already downloaded data and uses that in preference. 

18 

19 Args: 

20 **kwargs: to pass to fetch. See the documentation of `fetch_data`. 

21 

22 Returns: 

23 (dict): The data. 

24 

25 """ 

26 if "outdir" not in kwargs: 

27 kwargs["outdir"] = Path(".") 

28 elif isinstance(kwargs["outdir"], str): 

29 kwargs["outdir"] = Path(kwargs["outdir"]) 

30 params = {k: v for k, v in kwargs.items() if k not in {"outdir", "get_img", "get_data"}} # type: ignore 

31 dataf = kwargs["outdir"] / generate_fn(**params) 

32 if dataf.exists(): 

33 kwargs["fetch_data"] = False 

34 imgf = dataf.with_suffix(".png") 

35 if "get_img" not in kwargs: 

36 kwargs["get_img"] = False 

37 get_data = not dataf.exists() 

38 get_img = kwargs["get_img"] and not imgf.exists() 

39 if any((get_data, get_img)): 

40 fetch_data(**kwargs) 

41 

42 return read_ascii_data(dataf), imgf if kwargs["get_img"] else None