Skip to content

Pointing out another error in the hands-on tutorial notebook #38

@DivinorWieldor

Description

@DivinorWieldor

This issue is very similar to #34 . The addition of the labels "id" and "label" cause the plotting section to fail due to unexpected dimension size. The removal of these two indices fixes the execution of the cell.

This may not be the best solution though; detaching this removal process from the function would be most ideal.

Modifying cell 51 as such will fix this section of the code:

import numpy as np
import pandas as pd
import datetime
import matplotlib.pyplot as plt
import breizhcrops

level = "L1C" #@param ["L1C", "L2A"]

if level == "L1C":
    selected_bands = ['B1', 'B10', 'B11', 'B12', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B9']
elif level == "L2A":
    selected_bands = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B11', 'B12']

def get_interpolate_transform(interpolation_frequency, interpolation_method):

  def interpolate_transform(input_timeseries):
    #input_timeseries = raw_transform(input_timeseries)

    bands = allbands["L1C"].copy()
    bands.remove('label')
    bands.remove('id')
    data = pd.DataFrame(input_timeseries, columns=bands)
    data["doa"] = pd.to_datetime(data["doa"])
    data = data.set_index("doa")
    data = data.reindex(pd.date_range(start=datetime.datetime(data.index[0].year,1,1),
                                end=datetime.datetime(data.index[0].year,12,31),
                                freq=interpolation_frequency))
    data = data.interpolate(method=interpolation_method)
    data = data.fillna(method="ffill").fillna(method="bfill")
    data = data[selected_bands] * 1e-4
    return data
  return interpolate_transform

frequencies = ["1D","2D","9D"]
methods = ["linear", "nearest", "quadratic", "cubic"]

fig, axs = plt.subplots(len(methods), len(frequencies), figsize=(25,12), sharex=True, sharey=True)
axs = iter(np.array(axs).reshape(-1))

for method in methods:
  for freq in frequencies:
    transform = get_interpolate_transform(freq, method)
    ds = breizhcrops.BreizhCrops(region="belle-ile", level=level, transform=transform)
    x,y,i = ds[10]
    ax = next(axs)
    ax.set_ylim(0,1)
    ax.plot(x)
    ax.set_title(f"method {method}, frequency {freq}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions