Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DivinorWieldor opened this issue May 10, 2024 · 0 comments
Open

Comments

@DivinorWieldor
Copy link

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}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant