{"id":16571514,"url":"https://github.com/hrbrmstr/terminator","last_synced_at":"2025-10-29T01:30:46.804Z","repository":{"id":141238919,"uuid":"118976106","full_name":"hrbrmstr/terminator","owner":"hrbrmstr","description":"Rcpp implementation of day/night terminator generator","archived":false,"fork":false,"pushed_at":"2018-01-26T03:47:01.000Z","size":3599,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-02-03T11:04:03.066Z","etag":null,"topics":["daynight","geospatial","r","rcpp","rstats","terminator"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hrbrmstr.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-01-25T22:40:15.000Z","updated_at":"2023-01-09T19:20:11.000Z","dependencies_parsed_at":"2023-09-25T02:09:21.627Z","dependency_job_id":null,"html_url":"https://github.com/hrbrmstr/terminator","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"ea49f60352001d236fad44d8803249b7eb395828"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fterminator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fterminator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fterminator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hrbrmstr%2Fterminator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hrbrmstr","download_url":"https://codeload.github.com/hrbrmstr/terminator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219858513,"owners_count":16556043,"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":["daynight","geospatial","r","rcpp","rstats","terminator"],"created_at":"2024-10-11T21:24:16.420Z","updated_at":"2025-10-29T01:30:46.335Z","avatar_url":"https://github.com/hrbrmstr.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: rmarkdown::github_document\neditor_options: \n  chunk_output_type: console\n---\n\n# terminator\n\nCompute Global Terminator (Day/Night) Bands\n\n## Description\n\nCompute global terminator (day/night) bands which can be overlayed as day and night regions on a ggplot2 world map.\n\nThis is an Rcpp port of a [pure R port](https://github.com/JoGall/terminator) (by @JoGall) of a JS leaflet plugin.\n\n## What's Inside The Tin\n\nThe following functions are implemented:\n\n- `terminator`:\tCompute a single termiantor band\n- `terminator_lat_lon`:\tGenerate a full set of terminator frames\n\n## Installation\n\n```{r eval=FALSE}\ndevtools::install_github(\"hrbrmstr/terminator\")\n```\n\n```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}\noptions(width=120)\n```\n\n## Usage\n\n(NOTE: If you're trying to just knit this Rmd, remove the `eval=FALSE` bits. I didn't want to keep generating things and was too impatient to wait for a `cache=TRUE` run).\n\n```{r message=FALSE, warning=FALSE, error=FALSE}\nlibrary(terminator)\nlibrary(ggplot2)\nlibrary(gganimate) # devtools::install_github(\"dgrtwo/gganimate\")\n\n# current verison\npackageVersion(\"terminator\")\n```\n\nJoe had an asesome idea and made a perfectly fine pure R port. This one is just a wee bit faster.\n\n```{r bench, eval=FALSE}\nmicrobenchmark::microbenchmark(\n  pure_r = pure_r_terminator(as.POSIXct(Sys.Date()) + (60*60*0), -180, 190, 0.5),\n  rcpp = terminator::terminator(as.POSIXct(Sys.Date()) + (60*60*0), -180, 190, 0.5),\n  times=100\n) -\u003e mb\n\nmb\n## Unit: microseconds\n##    expr        min          lq        mean      median         uq        max neval\n##  pure_r 142373.445 157488.8415 174413.4417 173927.7860 184725.916 272773.959   100\n##    rcpp    483.505    553.2455    641.8395    609.8245    692.899   2487.993   100\n```\n\nRather than use the built-in map data, we'll use an `rnaturalearth` so we don't need to mess with extended longitudes.\n\n```{r wintri, fig.width=10}\nlibrary(ggalt)\nlibrary(rnaturalearth) # ropensci/rnaturalearth\n\nworld_map \u003c- fortify(countries110)\n\nggplot() +\n  geom_cartogram(\n    data=world_map, map=world_map, aes(x=long, y=lat, map_id=id),\n    fill=NA, color=\"#2b2b2b\"\n  ) -\u003e gg\n\nfor (i in 0:23) {\n  \n  gg \u003c- gg + geom_line(\n    data=terminator(as.integer((as.POSIXct(Sys.Date()) + (60*60*i))), -180, 180, 0.1),\n    aes(lon, lat), color=\"blue\"\n  )\n}\n\ngg + coord_proj(\"+proj=wintri\") + ggthemes::theme_map()\n```\n\nAnimation with `magick`:\n\n```{r magick, eval=FALSE}\nlibrary(magick)\nlibrary(rnaturalearth) # ropensci/rnaturalearth\nlibrary(tidyverse)\n\nworld_map \u003c- fortify(countries110, region=\"name\")\nworld_map \u003c- filter(world_map, id != \"Antarctica\")\n\nx \u003c- image_graph(width=1000*2, height=500*2, res=144)\npb \u003c- progress_estimated(24)\nfor (i in 0:23) {\n  pb$tick()$print()\n  ggplot() +\n    geom_cartogram(\n      data=world_map, map=world_map, aes(x=long, y=lat, map_id=id),\n      fill=NA, color=\"#2b2b2b\", size=0.125\n    ) +\n    geom_ribbon( \n      data=terminator(as.integer((as.POSIXct(Sys.Date()) + (60*60*(i)))), -180, 180, 0.1),\n      aes(lon, ymin=lat, ymax=90), fill=\"lightslategray\", alpha=1/2\n    ) +\n    scale_x_continuous(limits=c(-180, 180)) +\n    coord_quickmap() +\n    ggthemes::theme_map() -\u003e gg\n  print(gg)\n}\ndev.off()\nx \u003c- image_animate(x)\nimage_write(x, \"magick-preview.gif\")\n```\n\n![](magick-preview.gif)\n\nUsing Joe's animation example:\n\n```{r anim, eval=FALSE}\nterm_seq \u003c- terminator_lat_lon()\n\nchart \u003c- ggplot(term_seq, aes(frame = frame)) +\n  borders(\"world\", colour = \"gray90\", fill = \"gray85\") +\n  geom_ribbon(aes(lon, ymax = lat), ymin = 90, alpha = 0.2) +\n  coord_equal(xlim = c(-180, 190), ylim = c(-58, 85), expand = 0) +\n  ggthemes::theme_map()\n\ngganimate(\n  chart, \n  interval = 0.1, ani.width=1000, ani.height=600, \n  filename = \"terminator-animation.gif\"\n)\n```\n\n![](terminator-animation.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fterminator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhrbrmstr%2Fterminator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhrbrmstr%2Fterminator/lists"}