Skip to content

rnpn

This module contains functionality to download and load data from NPN. It uses rnpn as client.

Could use https://data.usanpn.org/observations/get-started to figure out which species/phenophases combis are available.

Example:

```python
from springtime.datasets.rnpn import (
    RNPN,
    npn_species,
    npn_phenophases
)

# List IDs and names for available species, phenophases
species = npn_species()
phenophases = npn_phenophases()

# Load dataset
dataset = RNPN(
    # Syringa vulgaris / common lilac
    species_ids={'name': 'lilac', 'items': [36]},
    phenophase_ids={'name': 'Leaves', 'items': [483]},
    years=[2010, 2012],
)
dataset.download()
gdf = dataset.load()

# or with area bounds
dataset = RNPN(
    years = [2010, 2011],
    area = {'name':'some', 'bbox':[-112, 30, -108, 35.0]}
)
```

Requires rnpn R package. Install with

install.packages("rnpn")

SpeciesByFunctionalType

Bases: BaseModel

Species by functional type.

PhenophasesByName

Bases: BaseModel

Phenophases by name.

RNPN

Bases: Dataset

Download and load data from NPN.

Attributes:

Name Type Description
years

timerange. For example years=[2000, 2002] downloads data for three years.

resample

Resample the dataset to a different time resolution. If None, no resampling.

species_ids Optional[Union[NamedIdentifiers, SpeciesByFunctionalType]]

formatted as a dictionary of the form {"name": "myname", "items": [id1, id2, ...]}. Alternatively, you can supply a valid functional type as a string. Use npn_species or npn_species_ids_by_functional_type to see options.

phenophase_ids Union[NamedIdentifiers, PhenophasesByName]

formatted as a dictionary of the form {"name": "myname", "items": [id1, id2, ...]}. Alternatively, you can supply a valid phenophase name as a string. Use npn_phenophases or npn_phenophase_ids_by_name to see options.

area Optional[NamedArea]

A dictionary of the form {"name": "yourname", "bbox": [xmin, ymin, xmax, ymax]}.

use_first bool

When true uses first_yes columns as value, otherwise the last "_yes"-columns.

aggregation_operator Literal['min', 'max', 'mean', 'median']

"min", "max", "mean", or "median" (default). How to aggregate in case of multiple observations per site/year

to_recipe()

Print out a recipe to reproduce this dataset.

download(timeout=30)

Download the data.

Parameters:

Name Type Description Default
timeout int

time in seconds to wait for a response of the npn server.

30

Raises:

Type Description
TimeoutError

If requests still fails after 3 attempts.

load()

Load the dataset into memory.

npn_species()

Get available species on npn.

Returns:

Type Description
DataFrame

Pandas dataframe with species_id and other species related fields.

npn_phenophases()

Get available phenophases on npn.

Returns:

Type Description
DataFrame

Pandas dataframe with phenophase_id and other phenophase related fields.

npn_stations()

Get available stations on npn.

Returns:

Type Description
GeoDataFrame

Dataframe with station_id and other station related fields.

npn_species_ids_by_functional_type(functional_type)

Lookup species ids by functional type.

npn_phenophase_ids_by_name(phenophase_name)

Lookup phenophase ids by name.