orjson and save
This commit is contained in:
parent
1384459941
commit
30f807bec0
3
utils/plot_json_export/.gitignore
vendored
3
utils/plot_json_export/.gitignore
vendored
@ -158,3 +158,6 @@ cython_debug/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
|
||||||
|
out.png
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import json, numpy as np, matplotlib.pyplot as plt
|
import orjson, numpy as np, matplotlib.pyplot as plt
|
||||||
|
|
||||||
def color_int2tuple(colorint):
|
def color_int2tuple(colorint):
|
||||||
# https://stackoverflow.com/a/2262152, License https://creativecommons.org/licenses/by-sa/2.5/
|
# https://stackoverflow.com/a/2262152, License https://creativecommons.org/licenses/by-sa/2.5/
|
||||||
@ -12,13 +12,13 @@ def main(argv):
|
|||||||
return 1
|
return 1
|
||||||
filename = argv[1]
|
filename = argv[1]
|
||||||
try:
|
try:
|
||||||
file = open(filename, "r")
|
file = open(filename, "rb")
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Error opening file.")
|
print("Error opening file.")
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
with file:
|
with file:
|
||||||
data = json.load(file)
|
data = orjson.loads(file.read())
|
||||||
assert "map" in data, "Invalid JSON savefile format"
|
assert "map" in data, "Invalid JSON savefile format"
|
||||||
plts = np.array(tuple(tuple(color_int2tuple(int(c)) for c in r) for r in data["map"]), dtype=np.uint8)
|
plts = np.array(tuple(tuple(color_int2tuple(int(c)) for c in r) for r in data["map"]), dtype=np.uint8)
|
||||||
if len(argv) >= 3:
|
if len(argv) >= 3:
|
||||||
@ -34,11 +34,11 @@ def main(argv):
|
|||||||
plts = np.rot90(plts, axes = (0,1))
|
plts = np.rot90(plts, axes = (0,1))
|
||||||
case "-90" | "270" | "+270":
|
case "-90" | "270" | "+270":
|
||||||
plts = np.rot90(plts, k = -1, axes = (0,1))
|
plts = np.rot90(plts, k = -1, axes = (0,1))
|
||||||
|
plt.figure(facecolor=(0, 0, 0))
|
||||||
plt.imshow(plts)
|
plt.imshow(plts)
|
||||||
try:
|
plt.axis('off')
|
||||||
plt.show()
|
plt.savefig('out.png', bbox_inches='tight')
|
||||||
except KeyboardInterrupt:
|
print("Image saved at out.png.")
|
||||||
pass
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
12
utils/plot_json_export/requirements.txt
Normal file
12
utils/plot_json_export/requirements.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
contourpy==1.1.0
|
||||||
|
cycler==0.11.0
|
||||||
|
fonttools==4.42.1
|
||||||
|
kiwisolver==1.4.5
|
||||||
|
matplotlib==3.7.2
|
||||||
|
numpy==1.25.2
|
||||||
|
orjson==3.9.5
|
||||||
|
packaging==23.1
|
||||||
|
Pillow==10.0.0
|
||||||
|
pyparsing==3.0.9
|
||||||
|
python-dateutil==2.8.2
|
||||||
|
six==1.16.0
|
Loading…
x
Reference in New Issue
Block a user