phenology / springtime

Spatiotemporal phenology research with interpretable models
https://springtime.readthedocs.io
Apache License 2.0
3 stars 2 forks source link

Add sample data generation #189

Closed Peter9192 closed 8 months ago

Peter9192 commented 10 months ago

Would be nice to have something like this as a utility shipped with the code to test transformations/feature extractions and model compatibility:

import pandas as pd
import numpy as np
import geopandas as gpd

# Generate test data
# random observations for 10 points:
obs = gpd.GeoDataFrame(
    data = {
        'year': np.arange(2000, 2010),
        'DOY_firstbloom': np.random.randint(120, 180, size=10),
        'geometry': gpd.GeoSeries.from_xy(*np.random.randn(2, 10))
        },
)

# dummy temperature data for each of these years/locations, for each DOY
get_temperature = lambda year, geometry: pd.Series(np.random.randn(365), index=np.arange(1, 366), name='temperature')
weather = obs.apply(lambda row: get_temperature(row.year, row.geometry), axis=1)

# Combine them
combined = pd.concat([obs, weather], axis=1)

# Or combine as series (more succint and easier to work with - is this preferable?)
combined = obs.assign(temperature=[pd.Series(v) for v in weather.values])