Skip to content

Commit 9bf3eb4

Browse files
authored
Merge pull request #26 from ESA-PhiLab/refactor-extensions
Refactor extensions
2 parents a663ae0 + a666ead commit 9bf3eb4

11 files changed

Lines changed: 42 additions & 52 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<img src="preview/segmentation.png" />
55

6-
Tool for manual image segmentation and classification of satellite imagery (or images in general). It was designed to accelerate the creation of machine learning training datasets for Earth Observation. This application is a flask app which can be run locally. Special highlights:
6+
Tool for manual image segmentation of satellite imagery (or images in general). It was designed to accelerate the creation of machine learning training datasets for Earth Observation. This application is a flask app which can be run locally. Special highlights:
77
* Support by AI (gradient boosted decision tree) when doing image segmentation
88
* Multiple and configurable views for multispectral imagery
99
* Simple setup with pip and one configuration file

demo/cloud-segmentation.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "cloud-segmentation",
3-
"authentication_required": true,
43
"images": {
54
"path": {
65
"Sentinel1": "images/{id}/s1.tif",

docs/config.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ To use IRIS, you need to define a project file in JSON or YAML format. A full-wo
44

55
- [Project file configurations](#project-file-configurations)
66
* [name](#name)
7-
* [authentication_required](#authentication_required)
87
* [port](#port)
98
* [host](#host)
109
* [images](#images)
@@ -20,14 +19,6 @@ Optional name for this project.
2019
"name": "cloud-segmentation"
2120
```
2221

23-
## authentication_required
24-
Defines whether you want to use IRIS with or without user authentication (latter is not yet implemented).
25-
26-
<i>Example:</i>
27-
```
28-
"authentication_required": true
29-
```
30-
3122
## port
3223
Set the port which IRIS is served on. Defaults to 5000.
3324
<i>Example:</i>

iris/__init__.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
import webbrowser
88

99
import flask
10-
from flask_sqlalchemy import SQLAlchemy
1110
import numpy as np
1211
import yaml
1312

14-
import iris.extensions
13+
from iris.extensions import db, compress
1514
from iris.project import project
1615

1716
def get_demo_file(example=None):
@@ -52,7 +51,7 @@ def parse_cmd_line():
5251
return vars(args)
5352

5453
def run_app():
55-
create_default_admin(app, db)
54+
create_default_admin(app)
5655
if args['production']:
5756
import gevent.pywsgi
5857
app_server = gevent.pywsgi.WSGIServer((project['host'], project['port']), app)
@@ -65,25 +64,24 @@ def create_app(project_file, args):
6564
project.load_from(project_file)
6665
project.debug = args['debug']
6766

67+
6868
# Create the flask app:
6969
app = flask.Flask(__name__)
70-
# app.config['TESTING'] = True
71-
app.config['EXPLAIN_TEMPLATE_LOADING'] = True
72-
73-
# We need this secret key to encrypt cookies
74-
app.secret_key = os.urandom(16)
7570

76-
# Database stuff:
71+
app.config.from_pyfile('config.py')
7772
app.config['SQLALCHEMY_DATABASE_URI'] = \
7873
'sqlite:///' + join(project['path'], 'iris.db')
79-
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
80-
db = SQLAlchemy(app)
8174

82-
return app, db
75+
# Register the extensions:
76+
db.init_app(app)
77+
compress.init_app(app)
78+
79+
return app
8380

84-
def create_default_admin(app, db):
81+
def create_default_admin(app):
8582
# Add a default admin account:
86-
admin = User.query.filter_by(name='admin').first()
83+
with app.app_context():
84+
admin = User.query.filter_by(name='admin').first()
8785
if admin is not None:
8886
return
8987

@@ -105,18 +103,12 @@ def create_default_admin(app, db):
105103
admin=True,
106104
)
107105
admin.set_password(password)
108-
db.session.add(admin)
109-
db.session.commit()
106+
with app.app_context():
107+
db.session.add(admin)
108+
db.session.commit()
110109

111110
def register_extensions(app):
112-
# Reduce the amount of transferred data by compressing it:
113-
iris.extensions.Compress(app)
114-
app.config['COMPRESS_MIMETYPES'] = [
115-
'text/html', 'text/css', 'text/xml',
116-
'application/json', 'application/octet-stream',
117-
'application/javascript'
118-
]
119-
111+
120112
from iris.main import main_app
121113
app.register_blueprint(main_app)
122114
from iris.segmentation import segmentation_app
@@ -136,11 +128,12 @@ def register_extensions(app):
136128
}
137129
args['project'] = get_demo_file()
138130

139-
app, db = create_app(args['project'], args)
131+
app = create_app(args['project'], args)
140132
from iris.models import User, Action
141133

142-
db.create_all()
143-
db.session.commit()
134+
with app.app_context():
135+
db.create_all()
136+
db.session.commit()
144137

145138
register_extensions(app)
146139

iris/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
3+
# General settings
4+
SECRET_KEY = os.urandom(24)
5+
EXPLAIN_TEMPLATE_LOADING = True
6+
7+
# Flask-SQLAlchemy settings
8+
SQLALCHEMY_TRACK_MODIFICATIONS = False
9+
10+
# Flask-Compress settings
11+
COMPRESS_MIMETYPES = [
12+
'text/html', 'text/css', 'text/xml',
13+
'application/json', 'application/octet-stream',
14+
'application/javascript'
15+
]

iris/default_config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"port": 5000,
3-
"authentication_required": true,
43
"images": {
54
"thumbnails": false,
65
"metadata": false

iris/extensions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
from flask_compress import Compress
2+
from flask_sqlalchemy import SQLAlchemy
3+
4+
db = SQLAlchemy()
5+
compress = Compress()

iris/project.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ def load_from(self, filename):
5757
if 'name' not in self.config:
5858
self.config['name'] = ".".join(basename(filename).split(".")[:-1])
5959

60-
if isinstance(self['authentication_required'], str):
61-
if self['authentication_required'].lower == 'false':
62-
self['authentication_required'] = False
63-
else:
64-
self['authentication_required'] = True
65-
6660
self._init_paths_and_files(filename)
6761

6862
# Default seed

iris/tests/test_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_required_authentication(self):
1515
addresses = [
1616
# admin
1717
'admin/users', 'admin/images', 'admin/actions/segmentation',
18-
'admin/actions/classification', 'admin/actions/detection',
18+
'admin/actions/detection',
1919
# user
2020
'user/get/current', 'user/show/current', 'user/config',
2121
'user/save_config',

iris/user/templates/user/show.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ <h3>Last segmentation masks</h3>
5353
</table>
5454
{% endif %}
5555
</div>
56-
57-
<div class="accordion" onclick="toogle_display(this);">Classification</div>
58-
<div class="panel">
59-
<p>Not yet implemented...</p>
60-
</div>
6156
{% if user.id == current_user.id %}
6257
<p>
6358
<button onclick="logout();">Logout</button>

0 commit comments

Comments
 (0)