SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Pronto Raster: A C++ library
for Map Algebra
Alex Hagen-Zanker
a.hagen-zanker@surrey.ac.uk
This presentation
• Motivation
• Map Algebra
• Library requirements
• Main design elements
• Raster / Range concepts
• Expression Templates
• Elementary spatial transforms
• Generic moving window analysis
• Use of the library
• Applications
https://github.com/ahhz/raster
Motivation: Map Algebra
Local operations Focal operations Zonal operations
3
4
7
+
=
1 3 2
5
2
13
Σ A B A B
A B B B
A A A B
4 2 2 4
1 2 1 2
3 4 3 2
=
Σ
Zone Σ
A 17
B 13
=
https://github.com/ahhz/raster
Motivation: Existing tools
• Geodata management: GDAL, Proj, GeoTIFF, etc.
• Image processing: OpenCV, GIL, etc.
• Linear algebra: Eigen, Blitz, UBLAS, etc.
• Scripting languages: ArcGIS Python, PC Raster,
R-raster, Geotrellis
• GIS software: Raster Calculator and specific tools in
QGIS, SAGA, GRASS, ArcGIS, etc.
All of these facilitate Map Algebra operations,
but none meets all (my) requirements
https://github.com/ahhz/raster
Motivation: User requirements
Requirement Key challenge
Customizable Be able to apply custom local, focal and zonal functions on any
number of layers
Efficient Minimal creation of temporary datasets for intermediary results
Usable Idiomatic interface, minimal use of boiler plate code
Scalable Work with large raster data sets that exceed available memory
Flexible Work with wide range of data formats without preprocessing
Compatible Be able to use in conjunction with other libraries (e.g. for
optimization, simulation control, etc.)
https://github.com/ahhz/raster
Researcher / consultant working
in geocomputational domain who
does not like being constrained by
built-in methods
Design: Range / Raster concepts
Range*
Gives access to a sequence of
values through iterator access.
Unlike a Container does not
have to store its own values
Range View
A Range that can be copied O(1)
and is meant to be passed to
functions by value
Raster
A Range with known number of
rows and columns.
Additionally, must give access to
sub-raster .
Raster View
A Raster that is also a View.
https://github.com/ahhz/raster*Official proposal to C++ standard, see also https://ericniebler.github.io/range-v3/
Design: Range / Raster concepts
Concept Main requirements
Range iterator_type begin();
iterator_type end();
Sized size_type size();
View copy-constructor O(1)
Raster sub_type sub_raster(start_row, start_col, rows,
cols);
size_type rows();
size_type cols();
https://github.com/ahhz/raster
Design: Range / Raster concepts
#include <pronto/raster/io.h>
namespace pr = pronto::raster;
int main()
{
auto ras = pr::open<int>("my_file.tif")
int sum = 0;
for(auto&& v : ras)
{
sum += v;
}
}
Use GDAL to open a raster
dataset as a model of the
Raster View concept
Use range-based for-loop
to iterate over all values in
the raster
https://github.com/ahhz/raster
Design: Range / Raster concepts
#include <pronto/raster/io.h>
namespace pr = pronto::raster;
int main()
{
auto ras = pr::open<int>("my_file.tif")
int sum = 0;
for(auto&& v : ras.sub_raster(2,3,10,20))
{
sum += v;
}
}
Iterate over subset of the
raster. First cell at (2,3)
then 10 rows and 20
columns
https://github.com/ahhz/raster
Design: Expression Templates
• Local operations take Raster Views as input and
produce an ET that also is a Raster View.
• Input and output conform to the same concept:
highly composable
• Cell values of the ET are only calculated once they
are iterated over
• No need to allocate memory
• A generic function, transform, is implemented,
other local functions can be implemented in terms
of transform
https://github.com/ahhz/raster
Design: Expression Templates
#include <pronto/raster/io.h>
#include <pronto/raster/transform_raster_view.h>
#include <functional>
namespace pr = pronto::raster;
int main()
{
auto a = pr::open<int>("a.tif");
auto b = pr::open<int>("b.tif");
auto sum = pr::transform(std::plus<int>, a, b);
for(auto&& v : sum.sub_raster(2,3,10,20))
{
// do something
}
}
Open two datasets
Apply std::plus to each
cell of both input
datasets
Iterate over a sub-raster of the
Expression Raster and calculate
the required values onlyhttps://github.com/ahhz/raster
Design: Expression Templates
auto a = pr::open<int>("a.tif");
auto b = pr::open<int>("b.tif");
auto diff = pr::transform(std::minus<int>, a, b);
auto sqr_lambda = [](int x){return x*x;};
auto sqr_diff = pr::transform(sqr_lambda, diff);
int sum_of_squared_diff = 0;
for(auto&& v : square_diff)
{
sum_of_squared_diff += v;
}
Compose a transform in
multiple steps
Iterate over values,
without allocating extra
memory, or creating a
temporary dataset.
https://github.com/ahhz/raster
Design: Expression Templates
#include <pronto/raster/io.h>
#include <pronto/raster/raster_algebra_operators.h>
#include <pronto/raster/raster_algebra_wrapper.h>
namespace pr = pronto::raster;
int main()
{
auto a = pr::raster_algebra_wrap(br::open<int>("a.tif"));
auto b = pr::raster_algebra_wrap(br::open<int>("b.tif"));
auto square_diff = (a – b) * (a – b);
for(auto&& v : square_diff)
{
// do something
}
}
Wrap a and b in raster_algebra_wrapper
to allow use of overloaded operators
Iterate over values.
https://github.com/ahhz/raster
Design: Elementary spatial operators
https://github.com/ahhz/raster
Function Effect
pad add const-valued leading and trailing rows and
columns with an unmutable value
sub_raster as required by the Raster concept
offset returns value found at a fixed spatial offset in the
input RasterView
h_edge / v_edge iterate over all horizontally / vertically adjacent cell
pairs
Design: Generalized moving windows
• Moving window analysis
is a common type of Focal
Operation
• Each cell obtains the
value of a summary
statistics calculated for
cells in a surrounding
window
• Efficient implementations
exploit overlap in
windows of adjacent cells
• Moving window indicator
is itself a Raster View
https://github.com/ahhz/raster
Circular window of cells Circular window of edges
Square window of edgesSquare window of cells
Design: Generalized moving windows
O(r x n)
r = radius
n = raster size
O(n)
n = raster size
https://github.com/ahhz/rasterHagen-Zanker, AH (2016) A computational framework for generalized moving windows and its application to landscape
pattern analysis International Journal of Applied Earth Observation and Geoinformation.
Design: Generalized moving windows
• Generalized windows based on Visitor design
pattern:
• add(element, weight)
• subtract(element, weight)
• add(subtotal, weight)
• subtract(subtotal, weight)
• extract()
• Can be used with different moving window methods
• Can also be used for zonal statistics
https://github.com/ahhz/raster
Design: Generalized moving windows
#include <pronto/raster/moving_window_indicator.h>
#include <pronto/raster/indicator/mean.h>
namespace pr = pronto::raster;
int main()
{
auto in = pr::open<int>("my_file.tif");
auto window = pr::circle(2);
auto indicator = pr::mean_generator<int>{};
auto out = pr::moving_window_indicator(in, window, indicator);
for(auto&& v : out)
{
// do something
}
}
Calculate the mean indicator for
a circular window with radius 2
"out" is a Raster View and hence
is used as such
https://github.com/ahhz/raster
Design: Assign to force evaluation
#include <pronto/raster/assign.h>
#include <pronto/raster/io.h>
#include <cmath>
namespace pr = pronto::raster;
int main()
{
auto in = pr::open<int>("my_file.tif");
auto sqrt = pr::transform([](int x){return std::sqrt(x);}, in);
auto out = pr::create_from_model<float>("sqrt.tif", in);
pr::assign(b, out);
}
Cheap: Create ET for the sqrt of
values in “my_file.tif”
https://github.com/ahhz/raster
Expensive: Create “sqrt.tif” and
write values
Design: use std::optional for nodata
values
https://github.com/ahhz/raster
#include <pronto/raster/io.h>
#include <pronto/raster/nodata_transform.h>
#include <pronto/raster/plot_raster.h>
namespace pr = pronto::raster;
int main()
{
auto in = pr::open<int>("demo.tif");
auto nodata = pr::nodata_to_optional(in, 6);
auto un_nodata = pr::optional_to_nodata(nodata,
-99);
}
Value type: int
0 3 6 2 5
1 4 0 3 6
2 5 1 4 0
3 6 2 5 1
Value type: std::optional<int>
0 3 - 2 5
1 4 0 3 -
2 5 1 4 0
3 - 2 5 1
Value type: int
0 3 -99 2 5
1 4 0 3 -99
2 5 1 4 0
3 -99 2 5 1
Providing an idiomatic way for functions to
skip over missing values or to leave cells
unspecified
Design: Runtime polymorphism
through type erasure
• Runtime polymorphism is sometimes required
• operations specified by user (e.g. Raster Calculator)
• value type of raster dataset unknown at compile time
Type erased class Holds Is a Raster View?
any_raster<T> Raster View object
with value type T
Yes
any_blind_raster any_raster<T>, where
T is a supported type
Has: rows(), cols(), sub_raster(…)
Lacks: begin(), end()
https://github.com/ahhz/raster
Design: Runtime polymorphism
through type erasure
pr::any_raster<int> plus_or_minus(bool do_plus)
{
auto a = pr::open<int>("a.tif");
auto b = pr::open<int>("b.tif");
if(do_plus) {
auto x = pr::transform(std::plus<int>, a, b));
return pr::make_any_raster(x);
} else {
auto y = pr::transform(std::minus<int>, a, b));
return pr::make_any_raster(y);
}
}
Runtime decision
x and y are different types;
but both are Raster Views
with int as value type
https://github.com/ahhz/raster
Design: Runtime polymorphism
through type erasure
pr::any_blind_raster a_in= pr::open_any("a.tif");
pr::any_blind_raster b_in= pr::open_any("b.tif");
auto a = pr::raster_algebra_wrap(a_in);
auto b = pr::raster_algebra_wrap(b_in);
auto c = (b-a) * (b-a);
pr::export_any("out.tif", c.unwrap());
Raster algebra made to work
with any_blind_raster
Exported to the
appropriate value type
Opened as the appropriate
value type
Unwrap from
raster_algebra_wrapper
https://github.com/ahhz/raster
Current state of the library
• Still relatively new
• Consolidating existing functionality before extending
• Documentation
• Majority of library is documented
• Including stand-alone examples for most functions
• Testing
• Using Google Test
• Still poor coverage, but solid core and expanding
• Benchmarks
• Still minimal
• Comparing against scripting languages (good)
• Comparing against direct C++ implementation (reasonable,
depending on type of access, optimal is read-only, forward-only, and
compile-time polymorphism)
https://github.com/ahhz/raster
Future music: wish list
• Transpose function
• Vertical / Horizontal flip function
• Mosaic function
• Parallel processing
• Sparse rasters?
• Many more users and an active community!
https://github.com/ahhz/raster
Future music: Parallel processing
• The sub_raster() requirement of Raster Views
combined with the Expression Template design
allows doing calculation for only a part of the raster
• For local operations and generalized moving
windows only the assign function needs to be
parallelized
• Split the rasters into sub-raster blocks
• Assign all blocks asynchronously
• And… rest of library needs to be thread safe (esp.
raster data access)
https://github.com/ahhz/raster
Scale dependent landscape
metrics
Applications
Cellular Automata land use
model
Fuzzy set map comparison
https://github.com/ahhz/raster
Conclusions
Requirement Key challenge Solution
Customizable Be able to apply custom local, focal
and zonal functions on any number
of layers
• Transform function
• Indicator concept
• Generalized moving windows
Efficient Minimal creation of temporary
datasets for intermediary results
• Using Expression Template
• Using non-copying spatial
operations
• Potential for parallelization
Usable Idiomatic interface, minimal use of
boiler plate code
• Range based for-loop
• std::optional for NODATA value
Scalable Work with large raster data sets that
exceed available memory
• Uses GDAL buffering and LRU
Flexible Work with wide range of data
formats without preprocessing
• Uses GDAL for data access
• RAII
Compatible Be able to use in conjunction with
other libraries (e.g. for optimization,
simulation control, etc.)
• C++
• Simple concepts with standard
interfaces
Thank you!
https://github.com/ahhz/raster
github.com/ahhz/raster
a.hagen-zanker@surrey.ac.uk

Weitere ähnliche Inhalte

Was ist angesagt?

Papilledema vs papillitis with notes timothy zagada
Papilledema vs papillitis with notes  timothy zagadaPapilledema vs papillitis with notes  timothy zagada
Papilledema vs papillitis with notes timothy zagadaTimothy Zagada
 
Synaptophore naman
Synaptophore namanSynaptophore naman
Synaptophore namanNaman Jain
 
Smooth Pursuit Eye Movement
Smooth Pursuit Eye MovementSmooth Pursuit Eye Movement
Smooth Pursuit Eye MovementAde Wijaya
 
DRY AGE RELATED MACULAR DEGENERATION
DRY AGE RELATED MACULAR DEGENERATIONDRY AGE RELATED MACULAR DEGENERATION
DRY AGE RELATED MACULAR DEGENERATIONShruti Laddha
 
Epidemiology & Community Optometry-8,9,10,11.pptx
Epidemiology & Community Optometry-8,9,10,11.pptxEpidemiology & Community Optometry-8,9,10,11.pptx
Epidemiology & Community Optometry-8,9,10,11.pptxssuser22cc61
 
Low vision aids dr. d p shah
Low vision aids   dr. d p shahLow vision aids   dr. d p shah
Low vision aids dr. d p shahlionsleaders
 
B-SCAN IN OPHTHALMOLOGY.pptx
B-SCAN IN OPHTHALMOLOGY.pptxB-SCAN IN OPHTHALMOLOGY.pptx
B-SCAN IN OPHTHALMOLOGY.pptxssuserbba7e3
 
What is Convergence Insufficiency?
What is Convergence Insufficiency?What is Convergence Insufficiency?
What is Convergence Insufficiency?Dominick Maino
 
Nystagmus assessments and management mehedi
Nystagmus assessments and management  mehediNystagmus assessments and management  mehedi
Nystagmus assessments and management mehediMehedi Hasan
 
Basic approach on HVF
Basic approach on HVFBasic approach on HVF
Basic approach on HVFAzul .
 
RAP TYPE 3 CNVM -AJAY DUDANI
RAP TYPE 3 CNVM -AJAY DUDANIRAP TYPE 3 CNVM -AJAY DUDANI
RAP TYPE 3 CNVM -AJAY DUDANIAjayDudani1
 

Was ist angesagt? (20)

Papilledema vs papillitis with notes timothy zagada
Papilledema vs papillitis with notes  timothy zagadaPapilledema vs papillitis with notes  timothy zagada
Papilledema vs papillitis with notes timothy zagada
 
Synaptophore naman
Synaptophore namanSynaptophore naman
Synaptophore naman
 
Retinal imaging
Retinal imagingRetinal imaging
Retinal imaging
 
Smooth Pursuit Eye Movement
Smooth Pursuit Eye MovementSmooth Pursuit Eye Movement
Smooth Pursuit Eye Movement
 
DRY AGE RELATED MACULAR DEGENERATION
DRY AGE RELATED MACULAR DEGENERATIONDRY AGE RELATED MACULAR DEGENERATION
DRY AGE RELATED MACULAR DEGENERATION
 
09 fundus camera
09 fundus camera09 fundus camera
09 fundus camera
 
Epidemiology & Community Optometry-8,9,10,11.pptx
Epidemiology & Community Optometry-8,9,10,11.pptxEpidemiology & Community Optometry-8,9,10,11.pptx
Epidemiology & Community Optometry-8,9,10,11.pptx
 
Low vision aids dr. d p shah
Low vision aids   dr. d p shahLow vision aids   dr. d p shah
Low vision aids dr. d p shah
 
B-SCAN IN OPHTHALMOLOGY.pptx
B-SCAN IN OPHTHALMOLOGY.pptxB-SCAN IN OPHTHALMOLOGY.pptx
B-SCAN IN OPHTHALMOLOGY.pptx
 
Refraction
RefractionRefraction
Refraction
 
Synechia
SynechiaSynechia
Synechia
 
Glaucomatous Optic Atrophy
Glaucomatous Optic AtrophyGlaucomatous Optic Atrophy
Glaucomatous Optic Atrophy
 
What is Convergence Insufficiency?
What is Convergence Insufficiency?What is Convergence Insufficiency?
What is Convergence Insufficiency?
 
Nystagmus namrata
Nystagmus  namrataNystagmus  namrata
Nystagmus namrata
 
Visual Acuity Assessment.pdf
Visual Acuity Assessment.pdfVisual Acuity Assessment.pdf
Visual Acuity Assessment.pdf
 
Nystagmus assessments and management mehedi
Nystagmus assessments and management  mehediNystagmus assessments and management  mehedi
Nystagmus assessments and management mehedi
 
Stereopsis
Stereopsis  Stereopsis
Stereopsis
 
Basic approach on HVF
Basic approach on HVFBasic approach on HVF
Basic approach on HVF
 
RAP TYPE 3 CNVM -AJAY DUDANI
RAP TYPE 3 CNVM -AJAY DUDANIRAP TYPE 3 CNVM -AJAY DUDANI
RAP TYPE 3 CNVM -AJAY DUDANI
 
Hirschberg test
Hirschberg testHirschberg test
Hirschberg test
 

Ähnlich wie Pronto raster v3

RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)Daniel Nüst
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce AlgorithmsAmund Tveit
 
Hadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectHadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectMao Geng
 
Greg Hogan – To Petascale and Beyond- Apache Flink in the Clouds
Greg Hogan – To Petascale and Beyond- Apache Flink in the CloudsGreg Hogan – To Petascale and Beyond- Apache Flink in the Clouds
Greg Hogan – To Petascale and Beyond- Apache Flink in the CloudsFlink Forward
 
Reducing Redundancies in Multi-Revision Code Analysis
Reducing Redundancies in Multi-Revision Code AnalysisReducing Redundancies in Multi-Revision Code Analysis
Reducing Redundancies in Multi-Revision Code AnalysisSebastiano Panichella
 
2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumertirlukachaitanya
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinaloscon2007
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBArangoDB Database
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in RSamuel Bosch
 
Echtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQLEchtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQLMoritz Flucht
 
Apache Arrow (Strata-Hadoop World San Jose 2016)
Apache Arrow (Strata-Hadoop World San Jose 2016)Apache Arrow (Strata-Hadoop World San Jose 2016)
Apache Arrow (Strata-Hadoop World San Jose 2016)Wes McKinney
 
Hive Anatomy
Hive AnatomyHive Anatomy
Hive Anatomynzhang
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
Using R on High Performance Computers
Using R on High Performance ComputersUsing R on High Performance Computers
Using R on High Performance ComputersDave Hiltbrand
 

Ähnlich wie Pronto raster v3 (20)

RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)RR & Docker @ MuensteR Meetup (Sep 2017)
RR & Docker @ MuensteR Meetup (Sep 2017)
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce Algorithms
 
Hadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log projectHadoop and HBase experiences in perf log project
Hadoop and HBase experiences in perf log project
 
Greg Hogan – To Petascale and Beyond- Apache Flink in the Clouds
Greg Hogan – To Petascale and Beyond- Apache Flink in the CloudsGreg Hogan – To Petascale and Beyond- Apache Flink in the Clouds
Greg Hogan – To Petascale and Beyond- Apache Flink in the Clouds
 
Reducing Redundancies in Multi-Revision Code Analysis
Reducing Redundancies in Multi-Revision Code AnalysisReducing Redundancies in Multi-Revision Code Analysis
Reducing Redundancies in Multi-Revision Code Analysis
 
2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Os Reindersfinal
Os ReindersfinalOs Reindersfinal
Os Reindersfinal
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDB
 
Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
Echtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQLEchtzeitapplikationen mit Elixir und GraphQL
Echtzeitapplikationen mit Elixir und GraphQL
 
Overview of the Hive Stinger Initiative
Overview of the Hive Stinger InitiativeOverview of the Hive Stinger Initiative
Overview of the Hive Stinger Initiative
 
dev_int_96
dev_int_96dev_int_96
dev_int_96
 
Modern C++
Modern C++Modern C++
Modern C++
 
Apache Arrow (Strata-Hadoop World San Jose 2016)
Apache Arrow (Strata-Hadoop World San Jose 2016)Apache Arrow (Strata-Hadoop World San Jose 2016)
Apache Arrow (Strata-Hadoop World San Jose 2016)
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Hive Anatomy
Hive AnatomyHive Anatomy
Hive Anatomy
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
Using R on High Performance Computers
Using R on High Performance ComputersUsing R on High Performance Computers
Using R on High Performance Computers
 

Kürzlich hochgeladen

Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Monika Rani
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)Areesha Ahmad
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and ClassificationsAreesha Ahmad
 
Grade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsGrade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsOrtegaSyrineMay
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusNazaninKarimi6
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLkantirani197
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000Sapana Sha
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPirithiRaju
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Silpa
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxSuji236384
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.Nitya salvi
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsSérgio Sacani
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxFarihaAbdulRasheed
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticssakshisoni2385
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxMohamedFarag457087
 
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Servicenishacall1
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...chandars293
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxseri bangash
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)Areesha Ahmad
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....muralinath2
 

Kürzlich hochgeladen (20)

Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
Grade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its FunctionsGrade 7 - Lesson 1 - Microscope and Its Functions
Grade 7 - Lesson 1 - Microscope and Its Functions
 
development of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virusdevelopment of diagnostic enzyme assay to detect leuser virus
development of diagnostic enzyme assay to detect leuser virus
 
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRLKochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
Kochi ❤CALL GIRL 84099*07087 ❤CALL GIRLS IN Kochi ESCORT SERVICE❤CALL GIRL
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.Molecular markers- RFLP, RAPD, AFLP, SNP etc.
Molecular markers- RFLP, RAPD, AFLP, SNP etc.
 
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptxPSYCHOSOCIAL NEEDS. in nursing II sem pptx
PSYCHOSOCIAL NEEDS. in nursing II sem pptx
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune WaterworldsBiogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
Biogenic Sulfur Gases as Biosignatures on Temperate Sub-Neptune Waterworlds
 
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptxCOST ESTIMATION FOR A RESEARCH PROJECT.pptx
COST ESTIMATION FOR A RESEARCH PROJECT.pptx
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
Digital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptxDigital Dentistry.Digital Dentistryvv.pptx
Digital Dentistry.Digital Dentistryvv.pptx
 
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
The Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptxThe Mariana Trench remarkable geological features on Earth.pptx
The Mariana Trench remarkable geological features on Earth.pptx
 
GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)GBSN - Microbiology (Unit 3)
GBSN - Microbiology (Unit 3)
 
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
Human & Veterinary Respiratory Physilogy_DR.E.Muralinath_Associate Professor....
 

Pronto raster v3

  • 1. Pronto Raster: A C++ library for Map Algebra Alex Hagen-Zanker a.hagen-zanker@surrey.ac.uk
  • 2. This presentation • Motivation • Map Algebra • Library requirements • Main design elements • Raster / Range concepts • Expression Templates • Elementary spatial transforms • Generic moving window analysis • Use of the library • Applications https://github.com/ahhz/raster
  • 3. Motivation: Map Algebra Local operations Focal operations Zonal operations 3 4 7 + = 1 3 2 5 2 13 Σ A B A B A B B B A A A B 4 2 2 4 1 2 1 2 3 4 3 2 = Σ Zone Σ A 17 B 13 = https://github.com/ahhz/raster
  • 4. Motivation: Existing tools • Geodata management: GDAL, Proj, GeoTIFF, etc. • Image processing: OpenCV, GIL, etc. • Linear algebra: Eigen, Blitz, UBLAS, etc. • Scripting languages: ArcGIS Python, PC Raster, R-raster, Geotrellis • GIS software: Raster Calculator and specific tools in QGIS, SAGA, GRASS, ArcGIS, etc. All of these facilitate Map Algebra operations, but none meets all (my) requirements https://github.com/ahhz/raster
  • 5. Motivation: User requirements Requirement Key challenge Customizable Be able to apply custom local, focal and zonal functions on any number of layers Efficient Minimal creation of temporary datasets for intermediary results Usable Idiomatic interface, minimal use of boiler plate code Scalable Work with large raster data sets that exceed available memory Flexible Work with wide range of data formats without preprocessing Compatible Be able to use in conjunction with other libraries (e.g. for optimization, simulation control, etc.) https://github.com/ahhz/raster Researcher / consultant working in geocomputational domain who does not like being constrained by built-in methods
  • 6. Design: Range / Raster concepts Range* Gives access to a sequence of values through iterator access. Unlike a Container does not have to store its own values Range View A Range that can be copied O(1) and is meant to be passed to functions by value Raster A Range with known number of rows and columns. Additionally, must give access to sub-raster . Raster View A Raster that is also a View. https://github.com/ahhz/raster*Official proposal to C++ standard, see also https://ericniebler.github.io/range-v3/
  • 7. Design: Range / Raster concepts Concept Main requirements Range iterator_type begin(); iterator_type end(); Sized size_type size(); View copy-constructor O(1) Raster sub_type sub_raster(start_row, start_col, rows, cols); size_type rows(); size_type cols(); https://github.com/ahhz/raster
  • 8. Design: Range / Raster concepts #include <pronto/raster/io.h> namespace pr = pronto::raster; int main() { auto ras = pr::open<int>("my_file.tif") int sum = 0; for(auto&& v : ras) { sum += v; } } Use GDAL to open a raster dataset as a model of the Raster View concept Use range-based for-loop to iterate over all values in the raster https://github.com/ahhz/raster
  • 9. Design: Range / Raster concepts #include <pronto/raster/io.h> namespace pr = pronto::raster; int main() { auto ras = pr::open<int>("my_file.tif") int sum = 0; for(auto&& v : ras.sub_raster(2,3,10,20)) { sum += v; } } Iterate over subset of the raster. First cell at (2,3) then 10 rows and 20 columns https://github.com/ahhz/raster
  • 10. Design: Expression Templates • Local operations take Raster Views as input and produce an ET that also is a Raster View. • Input and output conform to the same concept: highly composable • Cell values of the ET are only calculated once they are iterated over • No need to allocate memory • A generic function, transform, is implemented, other local functions can be implemented in terms of transform https://github.com/ahhz/raster
  • 11. Design: Expression Templates #include <pronto/raster/io.h> #include <pronto/raster/transform_raster_view.h> #include <functional> namespace pr = pronto::raster; int main() { auto a = pr::open<int>("a.tif"); auto b = pr::open<int>("b.tif"); auto sum = pr::transform(std::plus<int>, a, b); for(auto&& v : sum.sub_raster(2,3,10,20)) { // do something } } Open two datasets Apply std::plus to each cell of both input datasets Iterate over a sub-raster of the Expression Raster and calculate the required values onlyhttps://github.com/ahhz/raster
  • 12. Design: Expression Templates auto a = pr::open<int>("a.tif"); auto b = pr::open<int>("b.tif"); auto diff = pr::transform(std::minus<int>, a, b); auto sqr_lambda = [](int x){return x*x;}; auto sqr_diff = pr::transform(sqr_lambda, diff); int sum_of_squared_diff = 0; for(auto&& v : square_diff) { sum_of_squared_diff += v; } Compose a transform in multiple steps Iterate over values, without allocating extra memory, or creating a temporary dataset. https://github.com/ahhz/raster
  • 13. Design: Expression Templates #include <pronto/raster/io.h> #include <pronto/raster/raster_algebra_operators.h> #include <pronto/raster/raster_algebra_wrapper.h> namespace pr = pronto::raster; int main() { auto a = pr::raster_algebra_wrap(br::open<int>("a.tif")); auto b = pr::raster_algebra_wrap(br::open<int>("b.tif")); auto square_diff = (a – b) * (a – b); for(auto&& v : square_diff) { // do something } } Wrap a and b in raster_algebra_wrapper to allow use of overloaded operators Iterate over values. https://github.com/ahhz/raster
  • 14. Design: Elementary spatial operators https://github.com/ahhz/raster Function Effect pad add const-valued leading and trailing rows and columns with an unmutable value sub_raster as required by the Raster concept offset returns value found at a fixed spatial offset in the input RasterView h_edge / v_edge iterate over all horizontally / vertically adjacent cell pairs
  • 15. Design: Generalized moving windows • Moving window analysis is a common type of Focal Operation • Each cell obtains the value of a summary statistics calculated for cells in a surrounding window • Efficient implementations exploit overlap in windows of adjacent cells • Moving window indicator is itself a Raster View https://github.com/ahhz/raster
  • 16. Circular window of cells Circular window of edges Square window of edgesSquare window of cells Design: Generalized moving windows O(r x n) r = radius n = raster size O(n) n = raster size https://github.com/ahhz/rasterHagen-Zanker, AH (2016) A computational framework for generalized moving windows and its application to landscape pattern analysis International Journal of Applied Earth Observation and Geoinformation.
  • 17. Design: Generalized moving windows • Generalized windows based on Visitor design pattern: • add(element, weight) • subtract(element, weight) • add(subtotal, weight) • subtract(subtotal, weight) • extract() • Can be used with different moving window methods • Can also be used for zonal statistics https://github.com/ahhz/raster
  • 18. Design: Generalized moving windows #include <pronto/raster/moving_window_indicator.h> #include <pronto/raster/indicator/mean.h> namespace pr = pronto::raster; int main() { auto in = pr::open<int>("my_file.tif"); auto window = pr::circle(2); auto indicator = pr::mean_generator<int>{}; auto out = pr::moving_window_indicator(in, window, indicator); for(auto&& v : out) { // do something } } Calculate the mean indicator for a circular window with radius 2 "out" is a Raster View and hence is used as such https://github.com/ahhz/raster
  • 19. Design: Assign to force evaluation #include <pronto/raster/assign.h> #include <pronto/raster/io.h> #include <cmath> namespace pr = pronto::raster; int main() { auto in = pr::open<int>("my_file.tif"); auto sqrt = pr::transform([](int x){return std::sqrt(x);}, in); auto out = pr::create_from_model<float>("sqrt.tif", in); pr::assign(b, out); } Cheap: Create ET for the sqrt of values in “my_file.tif” https://github.com/ahhz/raster Expensive: Create “sqrt.tif” and write values
  • 20. Design: use std::optional for nodata values https://github.com/ahhz/raster #include <pronto/raster/io.h> #include <pronto/raster/nodata_transform.h> #include <pronto/raster/plot_raster.h> namespace pr = pronto::raster; int main() { auto in = pr::open<int>("demo.tif"); auto nodata = pr::nodata_to_optional(in, 6); auto un_nodata = pr::optional_to_nodata(nodata, -99); } Value type: int 0 3 6 2 5 1 4 0 3 6 2 5 1 4 0 3 6 2 5 1 Value type: std::optional<int> 0 3 - 2 5 1 4 0 3 - 2 5 1 4 0 3 - 2 5 1 Value type: int 0 3 -99 2 5 1 4 0 3 -99 2 5 1 4 0 3 -99 2 5 1 Providing an idiomatic way for functions to skip over missing values or to leave cells unspecified
  • 21. Design: Runtime polymorphism through type erasure • Runtime polymorphism is sometimes required • operations specified by user (e.g. Raster Calculator) • value type of raster dataset unknown at compile time Type erased class Holds Is a Raster View? any_raster<T> Raster View object with value type T Yes any_blind_raster any_raster<T>, where T is a supported type Has: rows(), cols(), sub_raster(…) Lacks: begin(), end() https://github.com/ahhz/raster
  • 22. Design: Runtime polymorphism through type erasure pr::any_raster<int> plus_or_minus(bool do_plus) { auto a = pr::open<int>("a.tif"); auto b = pr::open<int>("b.tif"); if(do_plus) { auto x = pr::transform(std::plus<int>, a, b)); return pr::make_any_raster(x); } else { auto y = pr::transform(std::minus<int>, a, b)); return pr::make_any_raster(y); } } Runtime decision x and y are different types; but both are Raster Views with int as value type https://github.com/ahhz/raster
  • 23. Design: Runtime polymorphism through type erasure pr::any_blind_raster a_in= pr::open_any("a.tif"); pr::any_blind_raster b_in= pr::open_any("b.tif"); auto a = pr::raster_algebra_wrap(a_in); auto b = pr::raster_algebra_wrap(b_in); auto c = (b-a) * (b-a); pr::export_any("out.tif", c.unwrap()); Raster algebra made to work with any_blind_raster Exported to the appropriate value type Opened as the appropriate value type Unwrap from raster_algebra_wrapper https://github.com/ahhz/raster
  • 24. Current state of the library • Still relatively new • Consolidating existing functionality before extending • Documentation • Majority of library is documented • Including stand-alone examples for most functions • Testing • Using Google Test • Still poor coverage, but solid core and expanding • Benchmarks • Still minimal • Comparing against scripting languages (good) • Comparing against direct C++ implementation (reasonable, depending on type of access, optimal is read-only, forward-only, and compile-time polymorphism) https://github.com/ahhz/raster
  • 25. Future music: wish list • Transpose function • Vertical / Horizontal flip function • Mosaic function • Parallel processing • Sparse rasters? • Many more users and an active community! https://github.com/ahhz/raster
  • 26. Future music: Parallel processing • The sub_raster() requirement of Raster Views combined with the Expression Template design allows doing calculation for only a part of the raster • For local operations and generalized moving windows only the assign function needs to be parallelized • Split the rasters into sub-raster blocks • Assign all blocks asynchronously • And… rest of library needs to be thread safe (esp. raster data access) https://github.com/ahhz/raster
  • 27. Scale dependent landscape metrics Applications Cellular Automata land use model Fuzzy set map comparison https://github.com/ahhz/raster
  • 28. Conclusions Requirement Key challenge Solution Customizable Be able to apply custom local, focal and zonal functions on any number of layers • Transform function • Indicator concept • Generalized moving windows Efficient Minimal creation of temporary datasets for intermediary results • Using Expression Template • Using non-copying spatial operations • Potential for parallelization Usable Idiomatic interface, minimal use of boiler plate code • Range based for-loop • std::optional for NODATA value Scalable Work with large raster data sets that exceed available memory • Uses GDAL buffering and LRU Flexible Work with wide range of data formats without preprocessing • Uses GDAL for data access • RAII Compatible Be able to use in conjunction with other libraries (e.g. for optimization, simulation control, etc.) • C++ • Simple concepts with standard interfaces