{"id":17202036,"url":"https://github.com/colcarroll/ridge_map","last_synced_at":"2025-04-09T15:06:38.685Z","repository":{"id":45978246,"uuid":"184413189","full_name":"ColCarroll/ridge_map","owner":"ColCarroll","description":"Ridge plots of ridges","archived":false,"fork":false,"pushed_at":"2025-01-21T16:03:08.000Z","size":20291,"stargazers_count":545,"open_issues_count":13,"forks_count":51,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-09T15:06:30.055Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ColCarroll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-01T12:30:48.000Z","updated_at":"2025-03-30T07:47:17.000Z","dependencies_parsed_at":"2024-06-20T00:07:48.826Z","dependency_job_id":"3a7d494b-834d-47df-9c82-dc64c7b7e7c2","html_url":"https://github.com/ColCarroll/ridge_map","commit_stats":{"total_commits":34,"total_committers":8,"mean_commits":4.25,"dds":0.6176470588235294,"last_synced_commit":"e149b90744b33707e4f5f558c2db61b5cc2fc5e9"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fridge_map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fridge_map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fridge_map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColCarroll%2Fridge_map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ColCarroll","download_url":"https://codeload.github.com/ColCarroll/ridge_map/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055284,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T02:13:23.127Z","updated_at":"2025-04-09T15:06:38.658Z","avatar_url":"https://github.com/ColCarroll.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"ridge_map\n=========\n![Build status](https://github.com/ColCarroll/ridge_map/actions/workflows/build.yml/badge.svg)\n\n*Ridge plots of ridges*\n-----------------------\n\nA library for making ridge plots of... ridges. Choose a location, get an elevation map, and tinker with it to make something beautiful. Heavily inspired from [Zach Cole's beautiful art](https://twitter.com/ZachACole/status/1121554541101477889), [Jake Vanderplas' examples](https://github.com/jakevdp/altair-examples/blob/master/notebooks/PulsarPlot.ipynb), and Joy Division's [1979 album \"Unknown Pleasures\"](https://gist.github.com/ColCarroll/68e29c92b766418b0a4497b4eb2ecba4).\n\nUses [matplotlib](https://matplotlib.org/), [SRTM.py](https://github.com/tkrajina/srtm.py), [numpy](https://www.numpy.org/), and [scikit-image](https://scikit-image.org/) (for lake detection).\n\nInstallation\n------------\n\nAvailable on [PyPI](https://pypi.org/project/ridge-map/):\n\n```bash\npip install ridge_map\n```\n\nOr live on the edge and install from github with\n\n```bash\npip install git+https://github.com/colcarroll/ridge_map.git\n```\n\nYou can also make a copy of [this colab](https://colab.research.google.com/drive/1ntwd73haePt3OS5ysz4yGSlhmUecY24O?usp=sharing).\n\nWant to help?\n-------------\n\n- I feel like I am missing something easy or obvious with lake/road/river/ocean detection, but what I've got gets me most of the way there. If you hack on the `RidgeMap.preprocessor` method and find something nice, I would love to hear about it!\n- Did you make a cool map? Open an issue with the code and I will add it to the examples.\n\nExamples\n--------\n\nThe API allows you to download the data once, then edit the plot yourself,\nor allow the default processor to help you.\n\n### New Hampshire by default\n\nPlotting with all the defaults should give you a map of my favorite mountains.\n\n```python\nfrom ridge_map import RidgeMap\n\nRidgeMap().plot_map()\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/white_mountains.png?raw=true)\n\n### Download once and tweak settings\n\nFirst you download the elevation data to get an array with shape\n`(num_lines, elevation_pts)`, then you can use the preprocessor\nto automatically detect lakes, rivers, and oceans, and scale the elevations.\nFinally, there are options to style the plot\n\n```python\nrm = RidgeMap((11.098251,47.264786,11.695633,47.453630))\nvalues = rm.get_elevation_data(num_lines=150)\nvalues=rm.preprocess(\n    values=values,\n    lake_flatness=2,\n    water_ntile=10,\n    vertical_ratio=240)\nrm.plot_map(values=values,\n            label='Karwendelgebirge',\n            label_y=0.1,\n            label_x=0.55,\n            label_size=40,\n            linewidth=1)\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/karwendelgebirge.png?raw=true)\n\n### Plot with colors!\n\nIf you are plotting a town that is super into burnt orange for whatever\nreason, you can respect that choice.\n\n```python\nrm = RidgeMap((-97.794285,30.232226,-97.710171,30.334509))\nvalues = rm.get_elevation_data(num_lines=80)\nrm.plot_map(values=rm.preprocess(values=values, water_ntile=12, vertical_ratio=40),\n            label='Austin\\nTexas',\n            label_x=0.75,\n            linewidth=6,\n            line_color='orange')\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/austin.png?raw=true)\n\n### Plot with even more colors!\n\nThe line color accepts a [matplotlib colormap](https://matplotlib.org/gallery/color/colormap_reference.html#sphx-glr-gallery-color-colormap-reference-py), so really feel free to go to town.\n\n```python\nrm = RidgeMap((-123.107300,36.820279,-121.519775,38.210130))\nvalues = rm.get_elevation_data(num_lines=150)\nrm.plot_map(values=rm.preprocess(values=values, lake_flatness=3, water_ntile=50, vertical_ratio=30),\n            label='The Bay\\nArea',\n            label_x=0.1,\n            line_color = plt.get_cmap('spring'))\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/san_francisco.png?raw=true)\n\n### Plot with custom fonts and elevation colors!\n\nYou can find a good font [from Google](https://fonts.google.com/), and then get the path to the ttf file [in the github repo](https://github.com/google/fonts/tree/master/ofl).\n\nIf you pass a matplotlib colormap, you can specify `kind=\"elevation\"` to color tops of mountains different from bottoms. `ocean`, `gnuplot`, and `bone` look nice.\n\n```python\nfrom ridge_map import FontManager\n\nfont = FontManager('https://github.com/google/fonts/blob/main/ofl/uncialantiqua/UncialAntiqua-Regular.ttf?raw=true')\nrm = RidgeMap((-156.250305,18.890695,-154.714966,20.275080), font=font.prop)\n\nvalues = rm.get_elevation_data(num_lines=100)\nrm.plot_map(values=rm.preprocess(values=values, lake_flatness=2, water_ntile=10, vertical_ratio=240),\n            label=\"Hawai'i\",\n            label_y=0.85,\n            label_x=0.7,\n            label_size=60,\n            linewidth=2,\n            line_color=plt.get_cmap('ocean'),\n            kind='elevation')\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/hawaii.png?raw=true)\n\n### How do I find a bounding box?\n\nI have been using [this website](http://bboxfinder.com). I find an area I like, draw a rectangle, then copy and paste the coordinates into the `RidgeMap` constructor.\n\n```python\nrm = RidgeMap((-73.509693,41.678682,-73.342838,41.761581))\nvalues = rm.get_elevation_data()\nrm.plot_map(values=rm.preprocess(values=values, lake_flatness=2, water_ntile=2, vertical_ratio=60),\n            label='Kent\\nConnecticut',\n            label_y=0.7,\n            label_x=0.65,\n            label_size=40)\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/kent.png?raw=true)\n\n### What about really flat areas?\n\nYou might really have to tune the `water_ntile` and `lake_flatness` to get the water right. You can set them to 0 if you do not want any water marked.\n\n```python\nrm = RidgeMap((-71.167374,42.324286,-70.952454, 42.402672))\nvalues = rm.get_elevation_data(num_lines=50)\nrm.plot_map(values=rm.preprocess(values=values, lake_flatness=4, water_ntile=30, vertical_ratio=20),\n            label='Cambridge\\nand Boston',\n            label_x=0.75,\n            label_size=40,\n            linewidth=1)\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/boston.png?raw=true)\n\n### Can I change the angle?\n\nYes, you can change the angle at which you look at the map. South to North is 0 degrees, East to West is 90 degrees and so forth with the rest of the compass. I really recommend playing around with this setting because of the really cool maps it can generate.\n\nPlay around with `interpolation`, `lock_rotation`, and `crop` to polish out the map.\n\n```python\nrm = RidgeMap((-124.848974,46.292035,-116.463262,49.345786))\nvalues = rm.get_elevation_data(elevation_pts=300, num_lines=300, viewpoint_angle=11)\nvalues=rm.preprocess(\n    values=values,\n    lake_flatness=2,\n    water_ntile=10,\n    vertical_ratio=240\n)\nrm.plot_map(values=values,\n    label='Washington',\n    label_y=0.8,\n    label_x=0.05,\n    label_size=40,\n    linewidth=2\n)\n```\n\n![png](/examples/washington.png?raw=true)\n![gif](/examples/washington.gif?raw=true)\n\n### What about Walden Pond?\n\nIt is that pleasant kettle pond in the bottom right of this map, looking entirely comfortable with its place in Western writing and thought.\n\n```python\nrm = RidgeMap((-71.418858,42.427511,-71.310024,42.481719))\nvalues = rm.get_elevation_data(num_lines=100)\nrm.plot_map(values=rm.preprocess(values=values, water_ntile=15, vertical_ratio=30),\n            label='Concord\\nMassachusetts',\n            label_x=0.1,\n            label_size=30)\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/concord.png?raw=true)\n\n### Do you play nicely with other matplotlib figures?\n\nOf course! If you really want to put a stylized elevation map in a scientific plot you are making, I am not going to stop you, and will actually make it easier for you. Just pass an argument for `ax` to `RidgeMap.plot_map`.\n\n```python\nimport numpy as np\nfig, axes = plt.subplots(ncols=2, figsize=(20, 5))\nx = np.linspace(-2, 2)\ny = x * x\n\naxes[0].plot(x, y, 'o')\n\nrm = RidgeMap()\nrm.plot_map(label_size=24, background_color=(1, 1, 1), ax=axes[1])\n```\n\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/multiaxis.png?raw=true)\n\nUser Examples\n-------------\n\n### Annotating, changing background color, custom text\n\nThis example shows how to annotate a lat/long on the map, and updates the color of the label text to allow for a dark background. Thanks to [kratsg](https://github.com/kratsg) for contributing.\n\n```python\nimport matplotlib\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nbgcolor = np.array([65,74,76])/255.\n\nscipp = (-122.060510, 36.998776)\nrm = RidgeMap((-122.087116,36.945365,-121.999226,37.023250))\nscipp_coords = ((scipp[0] - rm.longs[0])/(rm.longs[1] - rm.longs[0]),(scipp[1] - rm.lats[0])/(rm.lats[1] - rm.lats[0]))\n\nvalues = rm.get_elevation_data(num_lines=150)\nridges = rm.plot_map(values=rm.preprocess(values=values,\n                                          lake_flatness=1,\n                                          water_ntile=0,\n                                          vertical_ratio=240),\n            label='Santa Cruz\\nMountains',\n            label_x=0.75,\n            label_y=0.05,\n            label_size=36,\n            kind='elevation',\n            linewidth=1,\n            background_color=bgcolor,\n            line_color = plt.get_cmap('cool'))\n\n# Bit of a hack to update the text label color\nfor child in ridges.get_children():\n    if isinstance(child, matplotlib.text.Text) and 'Santa Cruz' in child._text:\n        label_artist = child\n        break\nlabel_artist.set_color('white')\n\nridges.text(scipp_coords[0]+0.005, scipp_coords[1]+0.005, 'SCIPP',\n            fontproperties=rm.font,\n            size=20,\n            color=\"white\",\n            transform=ridges.transAxes,\n            verticalalignment=\"bottom\",\n            zorder=len(values)+10)\n\nridges.plot(*scipp_coords, 'o',\n            color='white',\n            transform=ridges.transAxes,\n            ms=6,\n            zorder=len(values)+10)\n```\n\n#### Updated Annotation and Custom Text Color\nThe above code still works, but now there is a simplified method (Shown Below) that will produce the same image.\n\n```python\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom ridge_map import RidgeMap\n\nbgcolor = np.array([65,74,76])/255.\n\nrm = RidgeMap((-122.087116,36.945365,-121.999226,37.023250))\nvalues = rm.get_elevation_data(num_lines=150)\nvalues = rm.preprocess(\n    values=values, \n    lake_flatness=1, \n    water_ntile=0, \n    vertical_ratio=240\n)\n            \nrm.plot_map(\n    values=values,\n    label='Santa Cruz\\nMountains',\n    label_x=0.75,\n    label_y=0.05,\n    label_size=36,\n    label_color='white',\n    kind='elevation',\n    linewidth=1,\n    background_color=bgcolor,\n    line_color = plt.get_cmap('cool')\n)\n\nrm.plot_annotation(\n    label='SCIPP', \n    coordinates=(-122.060510, 36.998776), \n    x_offset=0.005, \n    y_offset=0.005, \n    label_size=20, \n    annotation_size=6, \n    color='white',\n    background=False\n)\n```\n![png](https://github.com/ColCarroll/ridge_map/blob/main/examples/santa_cruz.png?raw=true)\n\nElevation Data\n--------------\n\nElevation data used by `ridge_map` comes from NASA's [Shuttle Radar Topography Mission](https://www2.jpl.nasa.gov/srtm/) (SRTM), high resolution topographic data collected in 2000, and released in 2015. SRTM data are sampled at a resolution of 1 arc-second (about 30 meters). SRTM data is provided to `ridge_map` via the python package `SRTM.py` ([link](https://github.com/tkrajina/srtm.py)). SRTM data is not available for latitudes greater than N 60° or less than S 60°:\n\n\n\n![gif](https://www2.jpl.nasa.gov/srtm/images/SRTM_2-24-2016.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolcarroll%2Fridge_map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolcarroll%2Fridge_map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolcarroll%2Fridge_map/lists"}