Skip to content

Commit

Permalink
Add common name of birds
Browse files Browse the repository at this point in the history
  • Loading branch information
acmiyaguchi committed Dec 14, 2022
1 parent d67c061 commit bee26e1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,19 @@ These are saved as parquet files and are checked into the repository.

```bash
python -m birdcall_distribution.commands.model_assets intercept_car data/ee_v3_americas_5.parquet data/processed/models/intercept_car/americas/5 --n-species 10 --cores 4 --samples 5000

python -m birdcall_distribution.commands.model_assets intercept_car data/ee_v3_western_us_2.parquet data/processed/models/intercept_car/western_us/2 --n-species 10 --cores 4 --samples 5000

python -m birdcall_distribution.commands.model_assets intercept_car data/ee_v3_ca_1.parquet data/processed/models/intercept_car/ca/1 --n-species 10 --cores 4 --samples 5000


python -m birdcall_distribution.commands.model_assets intercept_covariate_car data/ee_v3_americas_5.parquet data/processed/models/intercept_covariate_car/americas/5 --n-species 10 --cores 4 --samples 5000

python -m birdcall_distribution.commands.model_assets intercept_covariate_car data/ee_v3_western_us_2.parquet data/processed/models/intercept_covariate_car/western_us/2 --n-species 10 --cores 4 --samples 5000

python -m birdcall_distribution.commands.model_assets intercept_covariate_car data/ee_v3_ca_1.parquet data/processed/models/intercept_covariate_car/ca/1 --n-species 10 --cores 4 --samples 5000
```

We also generate the manifest:

```bash
python -m birdcall_distribution.commands.generate_manifest data/processed data/processed/manifest.json
python -m birdcall_distribution.commands.bird_name_mapping data/processed data/processed
```

```bash
Expand Down
42 changes: 35 additions & 7 deletions app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"https://storage.googleapis.com/iyse6420-birdcall-distribution/processed";
let manifest = [];
let species_mapper = {};
let model = "intercept_covariate_car";
let region = "americas";
let specie = null;
Expand All @@ -22,8 +23,10 @@
let should_show = true;
onMount(async () => {
const res = await fetch(`${url}/manifest.json`);
let res = await fetch(`${url}/manifest.json`);
manifest = await res.json();
res = await fetch(`${url}/species_mapping.json`);
species_mapper = await res.json();
});
$: models = uniq(manifest.map((item) => item.model));
Expand All @@ -43,6 +46,7 @@
fetch(`${url}/${selected.path}/${selected.traces.trace}`)
.then((res) => res.json())
.then((data) => (trace = [...data]));
$: common_name = specie ? species_mapper[specie] : null;
// NOTE: we don't really need the ppc data atm, but we could use it to show a
// histogram or something
Expand All @@ -59,15 +63,30 @@

<h3>Options</h3>

<ModelOptions {models} {regions} {species} bind:model bind:region bind:specie />
<ModelOptions
{models}
{regions}
{species}
{species_mapper}
bind:model
bind:region
bind:specie
bind:should_show
/>

{#if selected}
<h3>
{specie},
{common_name} (<a href="https://ebird.org/species/{specie}">{specie}</a>),
{region},
{selected.grid_size} degree resolution,
{selected.grid_size}&deg; resolution,
{trace.filter((x) => x.index.includes("phi[")).length} cells
</h3>

<p>
Find more information about the {common_name} on its
<a href="https://ebird.org/species/{specie}">eBird page.</a>
</p>

<div class="primary">
<h4>linear scale</h4>
<div>
Expand All @@ -90,12 +109,21 @@

<h3>options</h3>

<ModelOptions {models} {regions} {species} bind:model bind:region bind:specie bind:should_show />
<ModelOptions
{models}
{regions}
{species}
{species_mapper}
bind:model
bind:region
bind:specie
bind:should_show
/>

<h3>
{specie},
{common_name} (<a href="https://ebird.org/species/{specie}">{specie}</a>),
{region},
{selected.grid_size} degree resolution,
{selected.grid_size}&deg; resolution,
{trace.filter((x) => x.index.includes("phi[")).length} cells
</h3>

Expand Down
3 changes: 2 additions & 1 deletion app/src/routes/ModelOptions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export let models = [];
export let regions = [];
export let species = [];
export let species_mapper = {};
export let model;
export let region;
export let specie;
Expand Down Expand Up @@ -37,7 +38,7 @@
{#each species as item}
<label>
<input type="radio" bind:group={specie} value={item} />
{item}
{species_mapper[item]}
</label>
{/each}
</div>
Expand Down
46 changes: 46 additions & 0 deletions birdcall_distribution/commands/bird_name_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
from argparse import ArgumentParser
from functools import partial
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import tqdm

from birdcall_distribution.geo import get_grid_meta, get_modis_land_cover_name
from birdcall_distribution.plot import dataframe_color_getter, plot_grid


def parse_args():
"""Parse args for the input and output paths"""
parser = ArgumentParser()
parser.add_argument("input", type=str, help="Path to the input dataset")
parser.add_argument("output", type=str, help="Path to the output directory")
return parser.parse_args()


def main():
args = parse_args()
input_path = Path(args.input)
output_path = Path(args.output)

taxonomy_df = pd.read_csv(
"https://storage.googleapis.com/birdclef-eda-f22/data/raw/birdclef-2022/eBird_Taxonomy_v2021.csv"
)
taxonomy_df.columns = taxonomy_df.columns.str.lower()
species_mapper = taxonomy_df.set_index("species_code")["primary_com_name"].to_dict()

# read manifest file
with open(input_path / "manifest.json") as f:
manifest = json.load(f)

# get all the set of all species
species = set([row["primary_label"] for row in manifest])
mapper_subset = {k: v for k, v in species_mapper.items() if k in species}
with open(output_path / "species_mapping.json", "w") as f:
json.dump(mapper_subset, f, indent=2)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion notebooks/2022-12-04-quail.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
"version": "3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]"
},
"orig_nbformat": 4,
"vscode": {
Expand Down

0 comments on commit bee26e1

Please sign in to comment.