diff --git a/hypercoast/hypercoast.py b/hypercoast/hypercoast.py index 9785092..532ae1d 100644 --- a/hypercoast/hypercoast.py +++ b/hypercoast/hypercoast.py @@ -234,3 +234,14 @@ def spectral_to_df(self, **kwargs): df = pd.DataFrame(self._spectral_data, **kwargs) return df + + def spectral_to_csv(self, filename, index=True, **kwargs): + """Saves the spectral data to a CSV file. + + Args: + filename (str): The output CSV file. + index (bool, optional): Whether to write the index. Defaults to True. + """ + df = self.spectral_to_df() + df = df.rename_axis("band") + df.to_csv(filename, index=index, **kwargs) diff --git a/hypercoast/ui.py b/hypercoast/ui.py index 64be4f6..94fb626 100644 --- a/hypercoast/ui.py +++ b/hypercoast/ui.py @@ -3,8 +3,8 @@ import ipyleaflet import ipywidgets as widgets -import matplotlib.pyplot as plt import numpy as np +from bqplot import pyplot as plt from IPython.core.display import display @@ -87,12 +87,22 @@ def handle_interaction(**kwargs): "wavelengths" ].values - self._host_map._spectral_data[f"({lat:.4f},{lon:.4f})"] = da.values + self._host_map._spectral_data[f"({lat:.4f} {lon:.4f})"] = da.values da[da < 0] = np.nan - fig, ax = plt.subplots() - da.plot.line(ax=ax) - display(fig) + # fig, ax = plt.subplots() + # da.plot.line(ax=ax) + # display(fig) + fig_margin = {"top": 20, "bottom": 35, "left": 50, "right": 20} + fig = plt.figure( + # title=None, + fig_margin=fig_margin, + layout={"width": "500px", "height": "300px"}, + ) + plt.plot(da.coords[da.dims[0]].values, da.values) + plt.xlabel("Wavelength (nm)") + plt.ylabel("Reflectance") + plt.show() self._host_map.default_style = {"cursor": "crosshair"}