Skip to content

Commit 695c181

Browse files
committed
Revert "Remove pickling until pickle PR.":
This commit is also in the fix-encoders test. The reason it wasn't used it because the mocker framework was being re-done in this commit. So its just sitting here in both unused. And at this point, modifying fix-encoder might provoke git to forget about conflicts already resolved. This reverts commit 94df9ac.
1 parent 45b96d9 commit 695c181

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""These are really just scripts, run them as such. Include pickle dev group."""
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Create pickled fig for use in integration tests."""
2+
3+
import pickle
4+
from pathlib import Path
5+
6+
import datashader as ds
7+
import datashader.transfer_functions as tf
8+
import pandas as pd
9+
import plotly.express as px
10+
import zstandard as zstd
11+
from colorcet import fire
12+
13+
cctx = zstd.ZstdCompressor(level=20)
14+
15+
df = pd.read_csv(
16+
"https://raw.githubusercontent.com/plotly/datasets/master/uber-rides-data1.csv",
17+
)
18+
dff = (
19+
df.query("Lat < 40.82")
20+
.query("Lat > 40.70")
21+
.query("Lon > -74.02")
22+
.query("Lon < -73.91")
23+
)
24+
25+
26+
cvs = ds.Canvas(plot_width=1000, plot_height=1000)
27+
agg = cvs.points(dff, x="Lon", y="Lat")
28+
# agg is an xarray object, see http://xarray.pydata.org/en/stable/ for more details
29+
coords_lat, coords_lon = agg.coords["Lat"].to_numpy(), agg.coords["Lon"].to_numpy()
30+
# Corners of the image
31+
coordinates = [
32+
[coords_lon[0], coords_lat[0]],
33+
[coords_lon[-1], coords_lat[0]],
34+
[coords_lon[-1], coords_lat[-1]],
35+
[coords_lon[0], coords_lat[-1]],
36+
]
37+
38+
39+
img = tf.shade(agg, cmap=fire)[::-1].to_pil()
40+
41+
42+
# Trick to create rapidly a figure with map axes
43+
fig = px.scatter_map(dff[:1], lat="Lat", lon="Lon", zoom=12)
44+
# Add the datashader image as a tile map layer image
45+
fig.update_layout(
46+
map_style="carto-darkmatter",
47+
map_layers=[{"sourcetype": "image", "source": img, "coordinates": coordinates}],
48+
)
49+
50+
raw = pickle.dumps(fig, protocol=5) # >=3.8
51+
compressed = cctx.compress(raw)
52+
with Path(f"./figs/{Path(__file__).stem}.pkl.zst").open("wb") as f:
53+
f.write(compressed)
54+
55+
print( # noqa: T201
56+
f"{Path(__file__).stem}.pkl: "
57+
f"{len(raw) / 1024:.1f} -> {len(compressed) / 1024:.1f} KB",
58+
)

0 commit comments

Comments
 (0)