world-ecoregion/predict.py

58 lines
1.4 KiB
Python
Raw Normal View History

2019-02-27 11:36:20 +00:00
import numpy as np
from utils import *
from nn import B, compile_b
2019-02-27 11:36:20 +00:00
from draw import draw
import time
def chunker(seq, size):
return (seq[pos:pos + size] for pos in range(0, len(seq), size))
2019-03-07 03:25:23 +00:00
def predicted_map(path=None):
year = MAX_YEAR - 1
2019-02-27 11:36:20 +00:00
2019-03-07 03:25:23 +00:00
df = pd.read_pickle('data.p')
2019-02-27 11:36:20 +00:00
print('TEMPERATURE MODIFICATION OF {}'.format(change))
2019-03-05 11:53:29 +00:00
inputs = ['elevation', 'distance_to_water', 'latitude']
2019-02-27 11:36:20 +00:00
for season in SEASONS:
inputs += [
'temp_{}_{}'.format(season, year),
'precip_{}_{}'.format(season, year)
]
2019-03-05 11:53:29 +00:00
print(inputs)
# print(inputs)
2019-03-05 11:53:29 +00:00
frame = df[inputs + ['longitude']]
# print(frame.head())
2019-02-27 11:36:20 +00:00
2019-02-28 10:04:47 +00:00
for season in SEASONS:
frame.loc[:, 'temp_{}_{}'.format(season, year)] += change
2019-02-27 11:36:20 +00:00
columns = ['latitude', 'longitude', 'biome_num']
2019-02-27 11:36:20 +00:00
new_data = pd.DataFrame(columns=columns)
2019-02-27 11:36:20 +00:00
for i, chunk in enumerate(chunker(frame, B.batch_size)):
if chunk.shape[0] < B.batch_size:
continue
2019-03-05 11:53:29 +00:00
input_data = normalize_ndarray(chunk.loc[:, inputs].values)
2019-02-27 11:36:20 +00:00
out = B.predict(input_data)
f = pd.DataFrame({
'longitude': chunk.loc[:, 'longitude'],
'latitude': chunk.loc[:, 'latitude'],
'biome_num': out
}, columns=columns)
new_data = new_data.append(f)
2019-02-27 11:36:20 +00:00
2019-03-07 03:25:23 +00:00
draw(new_data, path=path)
if __name__ == "__main__":
compile_b()
predicted_map()