Skip to content

Commit

Permalink
Add sample earthquake example (#382)
Browse files Browse the repository at this point in the history
* Add sample earthquake example

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update pantry.py

* Update pantry.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tkoyama010 and pre-commit-ci[bot] authored Jul 15, 2023
1 parent da42fdc commit 1447094
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/geovista/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
BASE_URL: str = "https://github.com/bjlittle/geovista-data/raw/{version}/data/"

#: Pin to use the specific geovista-data repository version for geovista resources.
DATA_VERSION: str = "2023.06.2"
DATA_VERSION: str = "2023.07.0"

#: Environment variable to override pooch cache manager path.
ENV: str = "GEOVISTA_CACHEDIR"
Expand Down
41 changes: 41 additions & 0 deletions src/geovista/examples/from_2d__earthquake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
"""Importable and runnable geovista example.
Notes
-----
.. versionadded:: 0.4.0
"""
from __future__ import annotations

import geovista as gv
from geovista.common import to_cartesian
from geovista.pantry import sample_earthquake
import geovista.theme


def main() -> None:
"""Create a point cloud from 2-D latitude and longitude large earthquake dataset.
The resulting mesh contains point cloud of large earthquake.
It uses a sample large earthquake dataset with point model.
"""
# load sample data
sample = sample_earthquake()

# convert coordinate to cartesian
points = to_cartesian(lons=sample.lons, lats=sample.lats)

# plot the mesh
plotter = gv.GeoPlotter()
plotter.add_points(points, render_points_as_spheres=True, color="red")
plotter.add_base_layer(texture=gv.natural_earth_1())
plotter.add_coastlines()
plotter.add_axes()
plotter.show()


if __name__ == "__main__":
main()
41 changes: 41 additions & 0 deletions src/geovista/pantry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"lfric_orog",
"lfric_sst",
"oisst_avhrr_sst",
"sample_earthquake",
"um_orca2",
"um_orca2_gradient",
"ww3_global_smc",
Expand Down Expand Up @@ -816,3 +817,43 @@ def ww3_global_tri() -> SampleUnstructuredXY:
)

return sample


@lru_cache(maxsize=LRU_CACHE_SIZE)
def sample_earthquake() -> SampleStructuredXYZ:
"""Download and cache the sample large earthquake dataset.
Returns
-------
SampleStructuredXYZ
The spatial coordinates and data payload.
Notes
-----
.. versionadded:: 0.4.0
"""
try:
import pandas as pd
except ImportError:
raise ImportError(
"\n\nInstall pandas to download this sample. Run:\n",
"\n pip install pandas\n",
) from None
fname = "earthquakes.parq"
processor = pooch.Decompress(method="auto", name=fname)
resource = CACHE.fetch(f"pantry/{fname}.bz2", processor=processor)

# load the lon/lat points
columns = ["depth", "id", "latitude", "longitude", "mag", "place", "time", "type"]
dataset = pd.read_parquet(resource, columns=columns, engine="fastparquet")

# load the lon/lat/zlevel points
lons = dataset["longitude"][:]
lats = dataset["latitude"][:]
zlevel = dataset["depth"][:]
data = dataset["mag"][:]

sample = SampleStructuredXYZ(lons=lons, lats=lats, zlevel=zlevel, data=data)

return sample
1 change: 1 addition & 0 deletions src/geovista/registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ raster/NE1_50M_SR_W.jpg 1a39003fe5fabb82a6816e79bb6bbe8215a8060d2e437b110f265ced
raster/uv-checker-map-4k.png b9ad63b29f85aed2ef2a6d630028d50a63f3a9050a3f9f0b291dcb5878adf820
raster/world.topo.bathy.200412.3x5400x2700.jpg a9f0088972dee0254610af851c4d6838ca3f2cf79176987e0a5713e2c15ec042
pantry/dynamico_icosahedral.nc.bz2 e5c05f015f89e2790a1f7f5c75f03521dcdd3d3d72434cacc9ec5cf023402820
pantry/earthquakes.parq.bz2 77cf6f9da2c6595f53fc2baf79ac1c6beb5c8c5ab94416d2d8a35d35ca939153
pantry/fvcom_tamar.nc.bz2 03730cd580bc472389a278e00e07947168daaa8d90f15aa87e7aa50263292e5e
pantry/icon_extpar_0010_R02B04_G.nc.bz2 6c212ff1e4bda0ba68bfa191c194d665687fc75f92bcc8bb4c7d45f88ba5d1dc
pantry/lam.nc.bz2 66a9b1541220cebba4947dfc4c564f53d0eb992d7b08f85c35936ba92ade10f1
Expand Down

0 comments on commit 1447094

Please sign in to comment.