This commit is contained in:
Peter 2021-02-26 17:45:57 +08:00
parent ae3a392af3
commit 39cd215cfd
12 changed files with 131 additions and 52 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 KiB

After

Width:  |  Height:  |  Size: 405 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 396 KiB

File diff suppressed because one or more lines are too long

BIN
RESULTS_21w07a/abs_freq.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 KiB

File diff suppressed because one or more lines are too long

BIN
RESULTS_21w07a/rel_freq.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 KiB

1
RESULTS_ALL__21w08b.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,7 @@ plot = main(style='default',
show_bounds=False,
linewidth=2,
dpi=100,
size=[16,10])
size=[16,15])
mpld3.save_html(plot[1][0], str(output_path / Path('abs_freq.html')), template_type='simple')
mpld3.save_html(plot[1][1], str(output_path / Path('rel_freq.html')), template_type='simple')
plt.close("all")
@ -19,7 +19,7 @@ plot = main(style='dark_background',
show_bounds=True,
linewidth=0.75,
dpi=100,
size=[16,10])
size=[16,15])
plot[1][0].savefig(str(output_path / Path('abs_freq.png')))
plot[1][1].savefig(str(output_path / Path('rel_freq.png')))
plot[0].show()

132
graph.py
View File

@ -1,18 +1,32 @@
import matplotlib.pyplot as plt
from cycler import cycler
from matplotlib.ticker import MultipleLocator
from copy import deepcopy
import json
DATA_FILES = [
'./RESULTS_ALL__1.16.5.json',
'./RESULTS_ALL__21w07a.json',
'./RESULTS_ALL__21w08b.json'
]
with open('./RESULTS_ALL__NEW_ORGEN_TEST.json', 'r') as file:
NEW_DATA = json.loads(file.read())
with open('./RESULTS_ALL__OLD_ORE_GEN.json', 'r') as file:
OLD_DATA = json.loads(file.read())
DATA = []
def list_distribution(block, data):
return [ y[block] if block in y else 0 for y in data ]
for datafile in DATA_FILES:
with open(datafile, 'r') as file:
DATA.append(json.loads(file.read()))
def list_distribution(blocks, data):
slices = []
for yslice in data:
c = 0
for block in blocks.split('||'):
if block in yslice: c += yslice[block]
slices.append(c)
return slices
# return [ y[block] if block in y else 0 for y in data ]
ABSOLUTE_BLOCKS_OLD = [
'minecraft:diamond_ore',
@ -24,7 +38,14 @@ ABSOLUTE_BLOCKS_OLD = [
'minecraft:coal_ore',
# 'minecraft:lava'
]
ABSOLUTE_BLOCKS_NEW = ABSOLUTE_BLOCKS_OLD+[
ABSOLUTE_BLOCKS_NEW = [
'minecraft:diamond_ore||minecraft:deepslate_diamond_ore',
'minecraft:redstone_ore||minecraft:deepslate_redstone_ore',
'minecraft:emerald_ore',
'minecraft:gold_ore||minecraft:deepslate_gold_ore',
'minecraft:lapis_ore',
'minecraft:iron_ore||minecraft:deepslate_iron_ore',
'minecraft:coal_ore',
'minecraft:copper_ore',
'minecraft:amethyst_block',
]
@ -32,13 +53,26 @@ ABSOLUTE_BLOCKS_NEW = ABSOLUTE_BLOCKS_OLD+[
RELATIVE_BLOCKS_OLD = ABSOLUTE_BLOCKS_OLD+[ #BLOCKS to show in the relative frequency distribution.
'minecraft:lava'
]
RELATIVE_BLOCKS_NEW = RELATIVE_BLOCKS_OLD+[
'minecraft:copper_ore',
'minecraft:amethyst_block',
RELATIVE_BLOCKS_NEW = deepcopy(ABSOLUTE_BLOCKS_NEW)
RELATIVE_BLOCKS_NEW.insert(-2, 'minecraft:lava')
ABSOLUTE_AX_PROPERTIES = [
{"title":"1.16.5 generation", "ylabel":r'$\Sigma ore$', "xlabel":'Elevation above void (m)'},
{"title":"21w07a generation", "ylabel":r'$\Sigma ore$', "xlabel":'Elevation above grimstone (m)'},
{"title":"21w08b generation", "ylabel":r'$\Sigma ore$', "xlabel":'Elevation above grimstone (m)'}
]
RELATIVE_AX_PROPERTIES = [
{"title":"1.16.5 generation", "ylabel":'Relative Frequency (%)', "xlabel":'Elevation above void (m)'},
{"title":"21w07a generation", "ylabel":'Relative Frequency (%)', "xlabel":'Elevation above grimstone (m)'},
{"title":"21w08b generation", "ylabel":'Relative Frequency (%)', "xlabel":'Elevation above grimstone (m)'}
]
x = list(range(-64,321))
#
#
#
def cfg_naxis(axes):
for axis in axes:
axis.grid(True, color='white', linewidth=0.2, linestyle='--', which="major")
@ -59,10 +93,11 @@ def orechunk(y):
return y / (2*sample_r/16)**2
def sigmaore(x):
return x * (2*sample_r/16)**2
def gen_maxis(axis):
secax = axis.secondary_yaxis('right', functions=(orechunk, sigmaore))
secax.minorticks_on()
secax.set_ylabel(r'$ore\cdot chunk\_layer^{-1}$')
def gen_maxis(axes):
for axis in axes:
secax = axis.secondary_yaxis('right', functions=(orechunk, sigmaore))
secax.minorticks_on()
secax.set_ylabel(r'$ore\cdot chunk\_layer^{-1}$')
def set_figure(fig, dpi, size):
fig.set_dpi(100)
@ -78,6 +113,14 @@ def plot_absolute(axis, blocks, data, padl, padu, width):
def plot_relative(axis, blocks, data, padl, padu, width):
[ axis.plot(x, [0 for x in range(padl[0],padl[1])]+[p/sum(tmp)*100 for p in tmp]+[0 for x in range(padu[0],padu[1])], label=ore, linewidth=width) for ore in blocks if (tmp := list_distribution(ore, data))]
def set_ax_properties(axes, ax_properties):
i = 0
for ax in axes:
ax.set_title(ax_properties[i]['title'])
ax.set_xlabel(ax_properties[i]['xlabel'])
ax.set_ylabel(ax_properties[i]['ylabel'])
i += 1
# quick/hackily converted the script to a function
def main(style, show_bounds, linewidth, dpi, size):
plt.style.use(style)
@ -85,48 +128,47 @@ def main(style, show_bounds, linewidth, dpi, size):
#
# abs frequency.
#
fig0, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=True)
fig0, axes = plt.subplots(
len(DATA),
sharex=True,
sharey=True
)
set_figure(fig0, dpi, size)
plt.subplots_adjust(left=0.05, right=0.95, top=0.9, bottom=0.05)
fig0.suptitle('New ore generation - Absolute frequency - 1024*1024 area sample size')
plot_absolute(ax1, ABSOLUTE_BLOCKS_OLD, OLD_DATA, [-64, 1], [256, 320], linewidth)
plot_absolute(ax2, ABSOLUTE_BLOCKS_NEW, NEW_DATA, [0, 0], [0, 0], linewidth)
plot_absolute(axes[0], ABSOLUTE_BLOCKS_OLD, DATA[0], [-64, 1], [256, 320], linewidth)
_ = 1
for data in DATA[1:]:
plot_absolute(axes[_], ABSOLUTE_BLOCKS_NEW, data, [0, 0], [0, 0], linewidth)
_ += 1
gen_maxis(ax1)
gen_maxis(ax2)
if show_bounds: add_bounds(ax1)
ax1.set_title("1.16.5 generation")
ax1.set_ylabel(r'$\Sigma ore$')
ax1.set_xlabel('Elevation above void (m)')
ax2.set_title("21w07a generation")
ax2.set_ylabel(r'$\Sigma ore$')
ax2.set_xlabel('Elevation above grimstone (m)')
cfg_naxis([ax1, ax2])
gen_maxis(axes)
if show_bounds: add_bounds(axes[0])
set_ax_properties(axes, ABSOLUTE_AX_PROPERTIES)
cfg_naxis(axes)
#
# Let's also show relative frequency.
#
fig1, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=True)
fig1, axes = plt.subplots(
len(DATA),
sharex=True,
sharey=True
)
set_figure(fig1, dpi, size)
plt.subplots_adjust(left=0.05, right=0.95, top=0.9, bottom=0.05)
fig1.suptitle('New ore generation - Relative frequency - 1024*1024 area sample size')
plot_relative(ax1, RELATIVE_BLOCKS_OLD, OLD_DATA, [-64, 1], [256, 320], linewidth)
plot_relative(ax2, RELATIVE_BLOCKS_NEW, NEW_DATA, [0, 0], [0, 0], linewidth)
if show_bounds: add_bounds(ax1)
ax1.set_title("1.16.5 generation")
ax1.set_ylabel('Relative Frequency (%)')
ax1.set_xlabel('Elevation above void (m)')
ax2.set_title("21w07a generation")
ax2.set_ylabel('Relative Frequency (%)')
ax2.set_xlabel('Elevation above grimstone (m)')
cfg_naxis([ax1, ax2])
plot_relative(axes[0], RELATIVE_BLOCKS_OLD, DATA[0], [-64, 1], [256, 320], linewidth)
_ = 1
for data in DATA[1:]:
plot_relative(axes[_], RELATIVE_BLOCKS_NEW, data, [0, 0], [0, 0], linewidth)
_ += 1
if show_bounds: add_bounds(axes[0])
set_ax_properties(axes, RELATIVE_AX_PROPERTIES)
cfg_naxis(axes)
return [plt, [fig0, fig1]]

View File

@ -7,7 +7,7 @@ import timeit
TIME_START_GLOBAL = timeit.default_timer()
# Load the world folder relative to the current working dir
WORLD_NAME = 'NEW_ORGEN_TEST'
WORLD_NAME = '21w08b'
total_r = 512
r = 128 # Split ops into these 'blocks' to save memory.
block_fac = math.floor(total_r/r)