diff --git a/.gitignore b/.gitignore index bc1cd58..60b197a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,94 @@ geodata +#### joe made this: http://goel.io/joe +#### python #### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +.venv/ +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + diff --git a/.python-version b/.python-version index 0b2eb36..424e179 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.7.2 +3.6.8 diff --git a/INSTALL.md b/INSTALL.md index fb60951..aa1ceb6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,5 +1,5 @@ ``` -pyenv install 3.7.2 +pyenv install $(cat .python-version) pyenv local pip install -r requirements.txt ``` diff --git a/data.py b/data.py new file mode 100644 index 0000000..6001b0e --- /dev/null +++ b/data.py @@ -0,0 +1,74 @@ +import geopandas +import os +import rasterio +import pandas as pd +from matplotlib import pyplot +from shapely.geometry import Point + +directory = os.path.dirname(os.path.abspath(__file__)) + +GEODATA = os.path.join(directory, 'geodata') +ECOREGIONS = os.path.join(GEODATA, 'ecoregions', 'Ecoregions2017.shp') +ELEVATION = os.path.join(GEODATA, 'srtm', 'topo30-180.tif') +TEMP = os.path.join(GEODATA, 'air_temp') +PRECIP = os.path.join(GEODATA, 'precipitation') + +def read_temp_data(year): + return pd.read_csv(os.path.join(TEMP, 'air_temp.{}'.format(year)), sep='\s+', header=None, + names=['longitude', 'latitude', 'january', + 'february', 'march', 'april', + 'may', 'june', 'july', 'august', + 'september', 'november', 'october', + 'december', 'yearly_avg']) + +def read_precip_data(year): + return pd.read_csv(os.path.join(PRECIP, 'precip.{}'.format(year)), sep='\s+', header=None, + names=['longitude', 'latitude', 'january', + 'february', 'march', 'april', + 'may', 'june', 'july', 'august', + 'september', 'november', 'october', + 'december', 'yearly_avg']) + +eco = geopandas.read_file(ECOREGIONS) +elevation = rasterio.open(ELEVATION) + +# world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) +# world['geometry'] = world['geometry'].unary_union + +# world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) +# print(world.head()) +# world = world[['continent', 'geometry']] +# continents = world.dissolve(level=1) +# continents.plot(); + +# print(eco.head()) +# print(elevation) + +# eco['geometry'].boundary.plot() +# eco.dissolve() + +# eco.plot() +# # rasterio.plot.show(src) +# # pyplot.imshow(elevation.read(1)) +# 51.42 +# 35.69 +# tehran = eco.geometry.contains() +def get_point_information(longitude, latitude): + p = Point(longitude, latitude) + ecoregion = eco.loc[lambda c: c.geometry.contains(p)] + return { + 'biome_num': ecoregion.loc['BIOME_NUM'].iloc[0], + 'biome_name': ecoregion.loc['BIOME_NAME'].iloc[0], + } +import time +start_time = time.time() +print('Before call') +print('Tehran', get_point_information(51.42, 35.69)) +print("--- %s seconds ---" % (time.time() - start_time)) +start_time = time.time() +print('Amazon', get_point_information(-59.78, -5.5)) +print("--- %s seconds ---" % (time.time() - start_time)) +# print(eco.geometry) +# print(tehran.distance(world.boundary)) +# world.boundary.plot() +pyplot.show() diff --git a/nn.py b/nn.py new file mode 100644 index 0000000..b49999f --- /dev/null +++ b/nn.py @@ -0,0 +1,13 @@ +from __future__ import absolute_import, division, print_function + +# TensorFlow and tf.keras +import tensorflow as tf +from tensorflow import keras + +# Helper libraries +import numpy as np +import matplotlib.pyplot as plt + +import data + +print(tf.__version__) diff --git a/requirements.txt b/requirements.txt index 5f4daa8..bccc651 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ matplotlib==3.0.2 descartes==1.1.0 pysal==2.0.0 rasterio==1.0.15 +tensorflow==1.12.0