# Prospecting
**by [Matt Hall](https://github.com/kwinkunks)**
We have 5 arrays of 4096 elements each. Each array represents a map as a 'raster' with 64 × 64 = 4096 pixels, and is given as a row in the dataset. Each pixel is represented by a single integer, taking values from 0 to 8.
The maps represent different things. In order, they are:
1. Reliability of well data.
2. Reliability of seismic data.
3. Porosity from wells and conceptual models.
4. Fracture density from wells and seismic.
5. Our land position (1 denotes 'our land').
We need to answer the following questions:
1. How many pixels have zero total reliability?
2. How many pixels are predicted to have better than 50th percentile (P50) porosity and better than P50 fracture density?
3. How many of these pixels have non-zero reliability and are on our land? These blobs are our _prospects_.
4. Find the product of the (x, y) coordinates of the cell containing the centre of mass of the largest _prospect_ blob.
For question 4, a centre of mass at (3.4, 12.6) is in the cell (3, 12) and you would respond with 3 × 12 = **36**.
We'll consider blobs to be connected if they have directly neighbouring pixels. In example A, below, there are 3 'blobs' of one pixel each. In example B there are 2 blobs, each with three pixels.
A B
1 0 1 1 1 0
0 1 0 1 0 1
0 0 0 0 1 1
## Example
Here is a dataset of smaller maps. Every row represents a map, each 3 × 3 pixels:
example = """0,1,0,1,2,1,0,1,0
2,1,0,1,1,1,0,1,0
0,1,2,1,3,1,1,2,2
0,2,1,2,3,1,1,3,2
1,1,1,1,1,1,0,0,0"""
If we re-shaped each row to make a 3 × 3 map, the maps would look like:
1 2 3 4 5 <--- map number
0 1 0 2 1 0 0 1 2 0 2 1 1 1 1
1 2 1 1 1 1 1 3 1 2 3 1 1 1 1
0 1 0 0 1 0 1 2 2 1 3 2 0 0 0
Here's how we might answer the questions:
1. There are **3** pixels with zeros in both of the reliability maps (the first two maps).
1. The P50 values on maps 3 and 4 are 1 and 2 respectively. There are **2** pixels that are higher on both maps.
1. Of those pixels, **1** has non-zero reliability and is on our land (map 5).
1. The coordinates of that pixels are (1, 1) so the product of those coordinates is **1**.
## Hints
It's likely that the `scipy.ndimage` module will be useful in answering question 4. For example, if you have an array `arr` like:
0 1 1
0 0 0
1 0 0
Then `scipy.ndimage.label()` will return two things: the labels and the number 2 (meaning it found 2 objects). The labels have the same shape as the original 'map':
0 1 1 <--- 1 denotes 'object 1'
0 0 0 <--- 0 denotes 'background', i.e. no objects
2 0 0 <--- 2 denotes 'object 2'
Once you have labels, you can get the centre of mass of the object labelled `3` with `scipy.ndimage.center_of_mass(arr, labels, 3)`.
We will use the default behaviour of the `scipy.ndimage.label()` function to decide if things are separate objects.
## A quick reminder how this works
This document is formatted in [Markdown](https://daringfireball.net/projects/markdown/).
You can retrieve your data, which is always a string, by choosing a **``** (also a string). This ensures that you have different data from other people, so be creative.
```
url = 'https://kata.geosci.ai/challenge/prospecting'
params = {
'key': # Replace with your own string.
}
r = requests.get(url, params)
r.text
```
To answer question 1, change the `params`:
```
params = {
'key': , # Use the same key you used to get your input.
'question': 1,
'answer': 1234 # Your answer; can be a float, int, list or array;
# the challenge description will tell you which.
}
```
To get a hint for a question, provide the question number but no answer:
```
params = {
'question': 1,
}
```
[Complete instructions at kata.geosci.ai](https://kata.geosci.ai/challenge)
[An example notebook to get you started](https://gist.github.com/kwinkunks/50f11dac6ab7ff8c3e6c7b34536501a2)
----
© 2023 [Scienxlab](https://scienxlab.org/) — Code: openly licensed under [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) — Text: openly licensed under [CC BY](https://creativecommons.org/licenses/by/4.0/).