Skip to content

Commit

Permalink
💫 IceSat2Explorer is now free to explore any placename
Browse files Browse the repository at this point in the history
Remove the hardcoding on visualizing whillans_upstream region only! Just needed a proper __init__ and super()__init__ inside the class :D. This change also allows us to make IceSat2Explorer a first class import citizen again, as the data won't be loaded on `import deepicedrain`, and tests won't break because of a FileNotFoundError for 'df_dhdt_whillans_upstream.parquet'.
  • Loading branch information
weiji14 committed Sep 15, 2020
1 parent d5139b2 commit ef939bf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
5 changes: 2 additions & 3 deletions atlxi_dhdt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
"import tqdm\n",
"import xarray as xr\n",
"\n",
"import deepicedrain\n",
"import deepicedrain.vizplots"
"import deepicedrain"
]
},
{
Expand Down Expand Up @@ -925,7 +924,7 @@
"source": [
"# Interactive holoviews scatter plot to find referencegroundtrack needed\n",
"# Tip: Hover over the points, and find those with high 'dhdt_slope' values\n",
"viewer = deepicedrain.vizplots.IceSat2Explorer(name=\"ICESat-2 Explorer\")\n",
"viewer = deepicedrain.IceSat2Explorer(name=\"ICESat-2 Explorer\", placename=placename)\n",
"dashboard: pn.layout.Column = pn.Column(viewer.widgets, viewer.view)\n",
"# dashboard"
]
Expand Down
3 changes: 1 addition & 2 deletions atlxi_dhdt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import xarray as xr

import deepicedrain
import deepicedrain.vizplots

# %%
client = dask.distributed.Client(n_workers=72, threads_per_worker=1)
Expand Down Expand Up @@ -414,7 +413,7 @@
# %%
# Interactive holoviews scatter plot to find referencegroundtrack needed
# Tip: Hover over the points, and find those with high 'dhdt_slope' values
viewer = deepicedrain.vizplots.IceSat2Explorer(name="ICESat-2 Explorer")
viewer = deepicedrain.IceSat2Explorer(name="ICESat-2 Explorer", placename=placename)
dashboard: pn.layout.Column = pn.Column(viewer.widgets, viewer.view)
# dashboard

Expand Down
3 changes: 1 addition & 2 deletions deepicedrain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
lonlat_to_xy,
point_in_polygon_gpu,
)

# from deepicedrain.vizplots import IceSat2Explorer
from deepicedrain.vizplots import IceSat2Explorer

__version__: str = "0.2.1"

Expand Down
1 change: 1 addition & 0 deletions deepicedrain/atlas_catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ sources:
type: str
default: siple_coast
allowed:
- kamb
- siple_coast
- whillans_upstream
- whillans_downstream
Expand Down
36 changes: 22 additions & 14 deletions deepicedrain/vizplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class IceSat2Explorer(param.Parameterized):
See also https://github.com/holoviz/datashader/pull/676.
"""

# Param Widgets that interactively control plot settings
plot_variable = param.Selector(
default="dhdt_slope", objects=["referencegroundtrack", "dhdt_slope", "h_corr"]
)
Expand All @@ -37,24 +38,29 @@ class IceSat2Explorer(param.Parameterized):
rasterize = param.Boolean(default=True)
datashade = param.Boolean(default=False)

# Load from intake data source
# catalog = intake.cat.atlas_cat
catalog: intake.catalog.local.YAMLFileCatalog = intake.open_catalog(
os.path.join(os.path.dirname(__file__), "atlas_catalog.yaml")
)
placename: str = "whillans_upstream"
source = catalog.icesat2dhdt(placename=placename)
if os.path.exists(f"ATLXI/df_dhdt_{placename}.parquet"):
def __init__(self, placename: str = "whillans_upstream", **kwargs):
super().__init__(**kwargs)
self.placename = placename

# Load from intake data source
# catalog = intake.cat.atlas_cat
self.catalog: intake.catalog.local.YAMLFileCatalog = intake.open_catalog(
os.path.join(os.path.dirname(__file__), "atlas_catalog.yaml")
)
self.source = self.catalog.icesat2dhdt(placename=self.placename)

try:
import cudf
import hvplot.cudf

df_ = cudf.read_parquet(source._urlpath)
self.df_ = cudf.read_parquet(self.source._urlpath)
except ImportError:
df_ = source.to_dask()
plot: hv.core.spaces.DynamicMap = source.plot.dhdt_slope() # default plot
startX, endX = plot.range("x")
startY, endY = plot.range("y")
self.df_ = self.source.to_dask()

# Setup default plot (dhdt_slope) and x/y axis limits
self.plot: hv.core.spaces.DynamicMap = self.source.plot.dhdt_slope()
self.startX, self.endX = self.plot.range("x")
self.startY, self.endY = self.plot.range("y")

def keep_zoom(self, x_range, y_range):
self.startX, self.endX = x_range
Expand All @@ -79,7 +85,9 @@ def view(self) -> hv.core.spaces.DynamicMap:

# Create the plot! Uses plot_kwargs from catalog metdata
# self.plot = getattr(source.plot, self.plot_variable)()
self.source = self.catalog.icesat2dhdt(cycle=self.cycle_number)
self.source = self.catalog.icesat2dhdt(
cycle=self.cycle_number, placename=self.placename
)
plot_kwargs = {
"xlabel": self.source.metadata["fields"]["x"]["label"],
"ylabel": self.source.metadata["fields"]["y"]["label"],
Expand Down

0 comments on commit ef939bf

Please sign in to comment.