Skip to content

Commit

Permalink
chore: update tools to use local taxaloader when present (#24)
Browse files Browse the repository at this point in the history
* chore: update Phacelia

* chore: update taxa photos

* chore: update tools to use local taxaloader when present
  • Loading branch information
johnkenny54 authored Dec 31, 2024
1 parent 3f538bd commit 93d11f1
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 102 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ npm i --save @ca-plant-list/ca-plant-list
ca-plant-list loads photos of plants from iNat and maintains lists of photos of all the plants it knows about from both licensed iNat taxon photos and licensed iNat observation photos. If you want to customize the photos that appear on your site, you can add a file of iNat photo data to your local setup. This package provides some tools for doing so. For example, if you wanted to use photos from observations from Alameda and Contra Costa Counties, you could do this:

```zsh
npx node ./node_modules/@ca-plant-list/ca-plant-list/scripts/inatobsphotos.js -fn inatphotos.csv -q "place_id=845,1527"
npx inatobsphotos -q "place_id=845,1527"
```

That will create `data/inatphotos.csv` in your repo, populated by photos from verifiable observations of the taxa in data/taxa.csv from the place IDs identified in the `-q` param. It chooses from the most-faved observations with the "CC BY" or "CC BY-NC" licenses, or the CC0 declaration.

If you want to load from iNat taxon photos instead, you can do

```zsh
npx node ./node_modules/@ca-plant-list/ca-plant-list/scripts/inattaxonphotos.js -fn inatphotos.csv
npx inattaxonphotos
```

The only reason to do that would be to get more recently-updated iNat taxon photos than ca-plant-list knows about.
27 changes: 27 additions & 0 deletions data/inattaxonphotos.csv
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ Blepharizonia plumosa,89389624,jpg,cc-by-nc,Chloe Novak
Boechera breweri subsp. breweri,854971,jpg,cc-by-nc,Robert
Bolboschoenus fluviatilis,5421230,jpg,cc-by-nc,sarahaj
Bolboschoenus maritimus subsp. paludosus,132800260,jpeg,cc-by-nc,Peter Zika
Bolboschoenus maritimus subsp. paludosus,132800264,jpeg,cc-by-nc,Peter Zika
Bolboschoenus maritimus subsp. paludosus,448262257,jpg,cc-by-nc,Fred Melgert / Carla Hoegen
Bolboschoenus maritimus subsp. paludosus,448262847,jpg,cc-by-nc,Fred Melgert / Carla Hoegen
Bolboschoenus robustus,79020136,jpeg,cc-by-nc,Sarah Towne
Bowlesia incana,1678991,JPG,cc-by-nc,Carolyn Gritzmaker
Bowlesia incana,128744293,jpg,cc-by,Zihao Wang
Expand Down Expand Up @@ -964,6 +967,8 @@ Calystegia sepium subsp. limnophila,5091992,jpg,cc-by,Ken-ichi Ueda
Calystegia sepium subsp. limnophila,38875324,jpeg,cc-by,Lauren McLaurin
Calystegia silvatica subsp. disjuncta,2839177,jpg,cc0,Peter de Lange
Calystegia silvatica subsp. disjuncta,2839178,jpg,cc0,Peter de Lange
Calystegia silvatica subsp. disjuncta,132744682,jpeg,cc-by-nc,lflovesnature
Calystegia silvatica subsp. disjuncta,132744715,jpeg,cc-by-nc,lflovesnature
Calystegia soldanella,106263751,jpg,cc-by-nc,Dani Montijo
Calystegia soldanella,16180949,jpeg,cc-by,Arnim Littek
Calystegia soldanella,62295020,jpeg,cc0,葉子
Expand Down Expand Up @@ -1036,6 +1041,7 @@ Carex barbarae,16259864,jpeg,cc-by,Millie Basden
Carex barbarae,76197561,jpg,cc-by-nc,jrmorris
Carex barbarae,9536063,jpeg,cc-by-nc,James Bailey
Carex brevicaulis,13079255,jpeg,cc-by-nc,Robert Pergl
Carex brevicaulis,336177289,jpeg,cc-by,Flavien Saboureau
Carex comosa,2097792,jpg,cc-by-nc,Susan Elliott
Carex comosa,2097794,jpg,cc-by-nc,Susan Elliott
Carex densa,70367090,jpeg,cc-by-nc,James Miskelly
Expand Down Expand Up @@ -1598,6 +1604,7 @@ Cryptantha corollata,6694854,jpg,cc-by-nc,Steve Jones
Cryptantha corollata,6694853,jpg,cc-by-nc,Steve Jones
Cryptantha flaccida,103049,jpg,cc-by,dloarie
Cryptantha intermedia var. intermedia,17323919,jpg,cc-by-nc,BJ Stacey
Cryptantha intermedia var. intermedia,5699495,jpg,cc-by-nc,Chris Evers
Cryptantha juniperensis,378730932,jpg,cc-by-nc,madge
Cryptantha juniperensis,378730814,jpg,cc-by-nc,madge
Cryptantha juniperensis,38799107,jpeg,cc-by-nc,Conor and Alexandra
Expand Down Expand Up @@ -1680,6 +1687,9 @@ Cyperus involucratus,175703429,jpeg,cc-by,Licheng Shih
Cyperus involucratus,181908056,jpeg,cc-by-nc,Chris Close
Cyperus involucratus,7928186,jpg,cc-by-nc,LSchare (she/her)
Cyperus involucratus,55787221,jpeg,cc-by,agujaceratops
Cyperus niger,89856671,jpg,cc-by-nc,jrebman
Cyperus niger,161421212,jpeg,cc-by,Ken-ichi Ueda
Cyperus niger,237485592,jpeg,cc-by,Ken-ichi Ueda
Cyperus odoratus,24788159,jpeg,cc-by,Zihao Wang
Cyperus odoratus,25385210,jpg,cc-by-nc,Dan Johnson
Cyperus strigosus,321391275,jpeg,cc-by,Michael J. Papay
Expand Down Expand Up @@ -1752,6 +1762,7 @@ Delphinium californicum subsp. californicum,42625517,jpeg,cc-by-nc,kalibardo
Delphinium californicum subsp. californicum,42625528,jpeg,cc-by-nc,kalibardo
Delphinium californicum subsp. californicum,745389,jpg,cc-by-nc,Eric Wrubel
Delphinium californicum subsp. interius,4087,jpg,cc-by,Ken-ichi Ueda
Delphinium californicum subsp. interius,129448412,jpg,cc-by-nc,kevinsherrill
Delphinium glaucum,37397608,jpg,cc-by-nc,Guy Lemelin
Delphinium glaucum,3738355,jpg,cc-by,Andrey Zharkikh
Delphinium gypsophilum,15118,jpg,cc-by,marlin harms
Expand Down Expand Up @@ -2247,6 +2258,8 @@ Eriophyllum confertiflorum var. confertiflorum,17035891,jpg,cc-by-nc,Fred Melger
Eriophyllum confertiflorum var. confertiflorum,42156614,jpg,cc-by-nc,docprt
Eriophyllum jepsonii,35246132,jpg,cc-by-nc,Christian Schwarz
Eriophyllum jepsonii,64529857,jpg,cc-by-nc,Chloe and Trevor Van Loon
Eriophyllum lanatum var. achilleoides,375544135,jpg,cc-by-nc,Karlyn H. Lewis
Eriophyllum lanatum var. achilleoides,62642791,png,cc-by-nc,James Gonsman
Eriophyllum staechadifolium,171909656,jpg,cc-by,DeeF
Eriophyllum staechadifolium,2266969,JPG,cc-by,Don Loarie
Eriophyllum staechadifolium,8009436,jpg,cc-by-nc,Bill Miller
Expand Down Expand Up @@ -2350,6 +2363,7 @@ Erythranthe microphylla,121654136,jpg,cc-by-nc,alivea009
Erythranthe microphylla,127754761,jpeg,cc-by-nc,Dan Tucker
Erythranthe microphylla,6708076,jpeg,cc-by-nc,Andrew Simon
Erythranthe microphylla,268075917,jpg,cc-by-nc,Dean Lyons
Erythranthe microphylla,373764496,jpg,cc-by-nc,Ocean Fleskes
Erythranthe moschata,301068789,jpg,cc-by-nc,nathantay
Erythranthe moschata,305753498,jpg,cc-by-nc,Ocean Fleskes
Erythranthe moschata,948210,jpg,cc-by-nc,Susan
Expand Down Expand Up @@ -3070,6 +3084,9 @@ Juncus xiphioides,9806786,jpg,cc-by-nc,Sarah Wilson
Juniperus californica,185052,jpg,cc-by,Ken-ichi Ueda
Juniperus californica,20654,jpg,cc-by,Ken-ichi Ueda
Juniperus californica,528925,jpg,cc-by-nc,Tom Scott
Juniperus communis var. saxatilis,62016689,jpg,cc-by-nc,Boris Bolshakov
Juniperus communis var. saxatilis,142708159,jpeg,cc-by-nc,Alexander Rumpel
Juniperus communis var. saxatilis,108219672,jpg,cc-by-nc,Felipe Castilla Lattke
Keckiella breviflora var. breviflora,160934765,jpg,cc-by,Steve Matson
Keckiella breviflora var. breviflora,160934761,jpg,cc-by,Steve Matson
Keckiella corymbosa,149319402,jpeg,cc-by-nc,Jason Cantley
Expand Down Expand Up @@ -3242,6 +3259,7 @@ Lepidium dictyotum,272680,jpg,cc-by-nc,2009 Zoya Akulova
Lepidium didymum,175706599,jpeg,cc-by-nc,Aleksandr_Levon
Lepidium didymum,8011861,jpg,cc0,Jesse Rorabaugh
Lepidium didymum,114049269,jpeg,cc-by-nc,博甫
Lepidium didymum,207927754,jpg,cc-by-nc,Chuangzao
Lepidium draba,17017121,jpg,cc-by,Conrad Altmann
Lepidium draba,127389190,jpg,cc-by-nc,africaspotter
Lepidium draba,34927501,jpg,cc-by-nc,Kayla Echols
Expand Down Expand Up @@ -4286,6 +4304,10 @@ Phoradendron leucarpum subsp. macrophyllum,248523345,jpeg,cc-by-nc,James Bailey
Phoradendron leucarpum subsp. macrophyllum,34637175,jpg,cc-by-nc,jimpark67
Phoradendron leucarpum subsp. macrophyllum,51724554,jpg,cc-by-nc,ellen hildebrandt
Phoradendron leucarpum subsp. tomentosum,37764,jpg,cc-by,Franco Folini
Phoradendron leucarpum subsp. tomentosum,274597968,jpg,cc-by-nc,Ryan Brooks
Phoradendron leucarpum subsp. tomentosum,175973152,jpeg,cc-by-nc,Anne Parsons
Phoradendron leucarpum subsp. tomentosum,106352640,jpeg,cc-by-nc,Patricia
Phoradendron leucarpum subsp. tomentosum,275717813,jpeg,cc-by,Cricket Raspet
Phragmites australis,51566082,jpg,cc-by-nc,mimzee
Phragmites australis,53131602,jpg,cc-by-nc,Sergey Mayorov
Phragmites australis,57666377,jpeg,cc-by-nc,Roger Debenham
Expand Down Expand Up @@ -4760,6 +4782,8 @@ Quercus durata var. durata,22844206,jpg,cc-by,John Rusk
Quercus garryana var. garryana,1765723,jpg,cc-by-nc,Di
Quercus garryana var. garryana,132101933,jpg,cc-by,Biodiversity Heritage Library
Quercus garryana var. garryana,132101934,jpg,cc-by,The Marmot
Quercus garryana var. garryana,294381780,jpg,cc-by-nc,JoeJoe Clark
Quercus garryana var. garryana,428986606,jpeg,cc-by-nc,Mart Hughes
Quercus ilex,52702145,jpg,cc-by-nc,Muriel Bendel
Quercus ilex,165811504,jpeg,cc-by-nc,juristi
Quercus ilex,243199963,jpeg,cc-by-nc,Platon Kleanthidis
Expand Down Expand Up @@ -4834,6 +4858,7 @@ Ranunculus sceleratus,146317741,jpg,cc-by-nc,Vladimir Bryukhov
Ranunculus sceleratus,31618021,jpg,cc-by-nc,Марина Горбунова-Ëлкина
Ranunculus sceleratus,17360630,jpeg,cc-by-nc,Nathan Taylor
Ranunculus sceleratus,74753531,jpeg,cc-by,Nina Filippova
Ranunculus sceleratus var. sceleratus,3155996,JPG,cc-by-nc,Bob O'Kennon
Raphanus raphanistrum,381509992,jpg,cc-by-nc,califorag3r
Raphanus raphanistrum,79344995,jpeg,cc-by-nc,Nadezhda Nayanova
Raphanus raphanistrum,284199344,jpg,cc-by-nc,chedar
Expand Down Expand Up @@ -5483,6 +5508,8 @@ Spergula arvensis,5060236,jpg,cc-by-nc,Simon Nicholas
Spergularia bocconi,24556284,jpeg,cc-by-nc,James Bailey
Spergularia bocconi,112060330,jpeg,cc-by-nc,James Bailey
Spergularia bocconi,34753827,jpg,cc-by-nc,sue_meiman
Spergularia macrotheca var. leucantha,270639696,jpg,cc-by-nc,Bonnie Nickel
Spergularia macrotheca var. leucantha,270639736,jpg,cc-by-nc,Bonnie Nickel
Spergularia macrotheca var. longistyla,183054472,jpg,cc-by-nc,jpgalvan
Spergularia macrotheca var. longistyla,187421118,jpg,cc-by-nc,chrisdan
Spergularia macrotheca var. longistyla,186674278,jpg,cc0,Scott Yarger
Expand Down
8 changes: 4 additions & 4 deletions data/taxa.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1331,10 +1331,10 @@ Persicaria punctata,,N,37303,11014,78456,Water Smartweed
Petasites frigidus var. palmatus,coltsfoot,N,8060,6269,55778,Arctic Sweet Coltsfoot
Petrorhagia dubia,pink grass,X,37370,6275,60602
Petunia parviflora,wild petunia,N,37378,6279,159650,Seaside Petunia
Phacelia breweri,,N,37425,6292,68813,Brewer's Phacelia,,blue,3,6
Phacelia californica,rock phacelia,N,37426,6293,53170,Rock Phacelia
Phacelia ciliata,great valley phacelia,N,37432,6302,58180,Great Valley Phacelia
Phacelia distans,"sordid phacelia,distant phacelia",N,37450,6318,56631,Wild Heliotrope,,"white,blue",3,5
Phacelia breweri,Brewer's phacelia,N,37425,6292,68813,Brewer's Phacelia,annual,blue,3,6
Phacelia californica,rock phacelia,N,37426,6293,53170,Rock Phacelia,perennial,blue,3,9
Phacelia ciliata,great valley phacelia,N,37432,6302,58180,Great Valley Phacelia,annual,blue,3,6
Phacelia distans,"sordid phacelia,distant phacelia",N,37450,6318,56631,Wild Heliotrope,annual,"white,blue",3,5
Phacelia divaricata,,N,37451,6319,51093,Divaricate Phacelia
Phacelia douglasii,,N,37452,6320,58182,Douglas' Phacelia
Phacelia egena,,N,37455,6322,58183,Kaweah River Phacelia
Expand Down
44 changes: 36 additions & 8 deletions lib/taxa.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Families } from "./families.js";
import { FlowerColor } from "./flowercolor.js";
import { InatPhoto } from "./inat_photo.js";
import { TaxaCSV } from "./tools/taxacsv.js";
import { ErrorLog } from "./errorlog.js";
import { Program } from "./program.js";

const FLOWER_COLORS = [
{ name: "white", color: "white" },
Expand Down Expand Up @@ -109,12 +111,13 @@ class Taxa {
#loadPhotosFromFile(dataDir, filename) {
if (!fs.existsSync(path.join(dataDir, filename))) return;
/** @type {InatCsvPhoto[]} */
const csvPhotos = CSV.parseFile(dataDir, filename).map( row => {
const csvPhotos = CSV.parseFile(dataDir, filename).map((row) => {
/** @type {InatLicenseCode} */
let licenseCode = "cc-by";
if (row.licenseCode === "cc-by-nc-sa") licenseCode = "cc-by-nc-sa";
else if (row.licenseCode === "cc-by-nc") licenseCode = "cc-by-nc";
else if (row.licenseCode === "cc-by-nc-nd") licenseCode = "cc-by-nc-nd";
else if (row.licenseCode === "cc-by-nc-nd")
licenseCode = "cc-by-nc-nd";
else if (row.licenseCode === "cc-by") licenseCode = "cc-by";
else if (row.licenseCode === "cc-by-sa") licenseCode = "cc-by-sa";
else if (row.licenseCode === "cc-by-nd") licenseCode = "cc-by-nd";
Expand All @@ -124,11 +127,11 @@ class Taxa {
return {
attrName: row.attrName,
ext: row.ext,
id: Number( row.id ),
id: Number(row.id),
licenseCode,
name: row.name
name: row.name,
};
} );
});
for (const csvPhoto of csvPhotos) {
const taxon = this.getTaxon(csvPhoto.name);
if (!taxon) {
Expand All @@ -149,9 +152,9 @@ class Taxa {
* @param {string} dataDir
*/
#loadInatPhotos(dataDir) {
this.#loadPhotosFromFile( "./data", "inatphotos.csv" );
this.#loadPhotosFromFile( dataDir, "inattaxonphotos.csv" );
this.#loadPhotosFromFile( dataDir, "inatobsphotos.csv" );
this.#loadPhotosFromFile("./data", "inatphotos.csv");
this.#loadPhotosFromFile(dataDir, "inattaxonphotos.csv");
this.#loadPhotosFromFile(dataDir, "inatobsphotos.csv");
}

getFamilies() {
Expand Down Expand Up @@ -190,6 +193,31 @@ class Taxa {
return this.#isSubset;
}

/**
* @param {import("commander").OptionValues} options
*/
static async loadTaxa(options) {
const errorLog = new ErrorLog(options.outputdir + "/errors.tsv", false);

const loaderPath = "./js/taxaloader.js";
let taxa;
if (fs.existsSync(loaderPath)) {
const taxaLoaderClass = await import(
"file:" + path.resolve(loaderPath)
);
taxa = await taxaLoaderClass.TaxaLoader.loadTaxa(options, errorLog);
} else {
taxa = new Taxa(
Program.getIncludeList(options.datadir),
errorLog,
options.showFlowerErrors,
);
}

errorLog.write();
return taxa;
}

/**
* @param {SynonymData[]} synCSV
* @param {Object<string,TaxonData>|boolean} inclusionList
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ca-plant-list/ca-plant-list",
"version": "0.4.14",
"version": "0.4.16",
"description": "Tools to create Jekyll files for a website listing plants in an area of California.",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -31,7 +31,8 @@
"ca-plant-list": "scripts/build-site.js",
"ca-plant-book": "scripts/build-ebook.js",
"cpl-photos": "scripts/cpl-photos.js",
"cpl-tools": "scripts/cpl-tools.js"
"cpl-tools": "scripts/cpl-tools.js",
"inatobsphotos": "scripts/inatobsphotos.js"
},
"dependencies": {
"archiver": "^5.3.1",
Expand Down
33 changes: 2 additions & 31 deletions scripts/cpl-tools.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env node

import * as path from "node:path";
import { Option } from "commander";
import { Taxa } from "../lib/taxa.js";
import { Program } from "../lib/program.js";
import { Calflora } from "../lib/tools/calflora.js";
import { Exceptions } from "../lib/exceptions.js";
Expand All @@ -12,6 +10,7 @@ import { INat } from "../lib/tools/inat.js";
import { JepsonEFlora } from "../lib/tools/jepsoneflora.js";
import { RPI } from "../lib/tools/rpi.js";
import { Config } from "../lib/config.js";
import { Taxa } from "../lib/taxa.js";

const TOOLS = {
CALFLORA: "calflora",
Expand All @@ -32,7 +31,6 @@ const ALL_TOOLS = [
TOOLS.TEXT,
];

const OPT_LOADER = "loader";
const OPT_TOOL = "tool";

const TOOLS_DATA_DIR = "./external_data";
Expand All @@ -52,7 +50,7 @@ async function build(program, options) {

const exceptions = new Exceptions(options.datadir);
const config = new Config(options.datadir);
const taxa = await getTaxa(options);
const taxa = await Taxa.loadTaxa(options);

const errorLog = new ErrorLog(options.outputdir + "/log.tsv", true);
for (const tool of tools) {
Expand Down Expand Up @@ -120,29 +118,6 @@ async function build(program, options) {
errorLog.write();
}

/**
* @param {import("commander").OptionValues} options
*/
async function getTaxa(options) {
const errorLog = new ErrorLog(options.outputdir + "/errors.tsv", true);

const loader = options[OPT_LOADER];
let taxa;
if (loader) {
const taxaLoaderClass = await import("file:" + path.resolve(loader));
taxa = await taxaLoaderClass.TaxaLoader.loadTaxa(options, errorLog);
} else {
taxa = new Taxa(
Program.getIncludeList(options.datadir),
errorLog,
options.showFlowerErrors,
);
}

errorLog.write();
return taxa;
}

const program = Program.getProgram();
program.addOption(
new Option(
Expand All @@ -159,10 +134,6 @@ program.option(
"--ef-lognotes",
"When running the jepson-eflora tool, include eFlora notes, invalid names, etc. in the log file.",
);
program.option(
"--loader <path>",
"The path (relative to the current directory) of the JavaScript file containing the TaxaLoader class. If not provided, the default TaxaLoader will be used.",
);
program.option("--update", "Update taxa.csv to remove errors if possible.");
program.addHelpText(
"after",
Expand Down
Loading

0 comments on commit 93d11f1

Please sign in to comment.