could not convert string ‘Wavelength‘ to float64 at row 0, column 1.

如果是碰到这个报错,说明导入的数据集内有不能转成float64的字符或者tap,空格等等,删掉即可。

打开notepad然后ctrl+f,替换

### Python Code for Simulating Hyperspectral Data and Generating Vegetation Maps Simulating hyperspectral data involves creating a dataset that mimics the spectral characteristics observed by sensors such as those on Sentinel-2 satellites. Below is an example of how to simulate high-resolution hyperspectral data using Python, followed by generating vegetation maps specific to boreal regions like Alaska. #### Key Libraries Used The following libraries are essential for this task: - `numpy`: For numerical operations. - `matplotlib`: To visualize results. - `rasterio` or `geopandas`: Handling geospatial raster datasets. - `scipy`: Interpolation techniques can be applied here if needed. Here’s a sample implementation: ```python import numpy as np import matplotlib.pyplot as plt from scipy.interpolate import interp1d import rasterio # Define Spectral Bands Similar to Sentinel-2 (in nanometers) sentinel_bands_nm = { 'B02': 490, 'B03': 560, 'B04': 665, 'B08': 705, 'B8A': 740, 'B11': 1610, 'B12': 2190 } def generate_hyperspectral_data(num_samples=100, num_bands=200): """ Generate synthetic hyperspectral data with random values across bands. """ wavelengths = np.linspace(400, 2500, num_bands) # Wavelength range similar to Sentinel-2 reflectance_values = np.random.rand(num_samples, num_bands) * 0.8 + 0.2 # Randomized reflectance return wavelengths, reflectance_values def interpolate_to_sentinel(wavelengths, reflectance_values, sentinel_bands_nm): """ Resample simulated hyperspectral data into Sentinel-like bands. """ interpolated_reflectances = {} for band_name, wavelength in sentinel_bands_nm.items(): interpolator = interp1d(wavelengths, reflectance_values.T, kind='cubic', fill_value="extrapolate") interpolated_reflectances[band_name] = interpolator(wavelength).T return interpolated_reflectances wavelengths, reflectance_values = generate_hyperspectral_data() interpolated_reflectances = interpolate_to_sentinel(wavelengths, reflectance_values, sentinel_bands_nm) # Example Visualization: Plotting Band B04 Reflectance Values plt.figure(figsize=(10, 6)) plt.plot(interpolated_reflectances['B04'][0], label=f"B04 ({sentinel_bands_nm['B04']} nm)", color='red') plt.title('Interpolated Reflectance Value for Sentinel-2 Band B04') plt.xlabel('Sample Index') plt.ylabel('Reflectance') plt.legend() plt.show() # Save Generated Rasters Using RasterIO with rasterio.open( "boreal_vegetation_map.tif", "w", driver="GTiff", height=reflectance_values.shape[0], width=reflectance_values.shape[1], count=len(sentinel_bands_nm), dtype=rasterio.float32, crs="+proj=latlong", # CRS placeholder; adjust based on actual region transform=rasterio.transform.from_bounds(-180, -90, 180, 90, width=reflectance_values.shape[1], height=reflectance_values.shape[0]) ) as dst: for idx, band_name in enumerate(sentinel_bands_nm.keys(), start=1): dst.write_band(idx, interpolated_reflectances[band_name].astype(rasterio.float32)) print(f"Hyperspectral simulation completed! File saved as 'boreal_vegetation_map.tif'.") ``` This script generates artificial hyperspectral data representing typical boreal forest spectra[^1]. It then resamples these spectra onto the standard Sentinel-2 bands through interpolation methods provided by SciPy's `interp1d`. Additionally, it saves generated rasters compatible with GIS tools via `RasterIO`, ensuring compatibility when analyzing real-world geographic extents corresponding to Alaskan boreal zones[^2]. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值