| import streamlit as st |
| import h5py |
| import os |
|
|
| |
| filename = r'C:\Users\Lenovo\Desktop\Machine-Learning\Soil Moisture\SMAP_L4_SM_aup_20230121T000000_Vv7030_001.h5' |
| with h5py.File(filename, 'r') as test_file: |
| print(list(test_file.keys())) |
| |
|
|
| |
| if not os.path.isfile(filename): |
| st.error("File not found: " + filename) |
| else: |
| try: |
| |
| with h5py.File(filename, 'r') as h5: |
| |
| st.write("Keys in the HDF5 file:", list(h5.keys())) |
| |
| |
| for key in h5.keys(): |
| st.write(f"Exploring group: {key}") |
| for dataset_name in h5[key].keys(): |
| dataset = h5[key][dataset_name] |
| st.write(f" - {dataset_name}: shape {dataset.shape}, type {dataset.dtype}") |
|
|
| except Exception as e: |
| st.error(f"An error occurred: {str(e)}") |
|
|
| import h5py |
| import numpy as np |
| import pandas as pd |
| import streamlit as st |
| import plotly.express as px |
|
|
| with h5py.File(filename, 'r', swmr=False) as h5: |
| |
| filename = 'Soil Moisture\SMAP_L4_SM_aup_20230121T000000_Vv7030_001.h5' |
| with h5py.File(filename, 'r') as h5: |
| |
| soil_moisture = h5['Analysis_Data/sm_surface_analysis'][:] |
| lat = h5['cell_lat'][:] |
| lon = h5['cell_lon'][:] |
| time = h5['time'][:] |
| |
| |
| df = pd.DataFrame({ |
| 'Latitude': lat.flatten(), |
| 'Longitude': lon.flatten(), |
| 'Soil Moisture': soil_moisture.flatten() |
| }) |
| |
| |
| st.title("Soil Moisture Data Dashboard") |
| st.write("This dashboard displays soil moisture levels based on latitude and longitude.") |
| |
| |
| min_lat, max_lat = st.slider("Select Latitude Range", float(df['Latitude'].min()), float(df['Latitude'].max()), (float(df['Latitude'].min()), float(df['Latitude'].max()))) |
| min_lon, max_lon = st.slider("Select Longitude Range", float(df['Longitude'].min()), float(df['Longitude'].max()), (float(df['Longitude'].min()), float(df['Longitude'].max()))) |
| |
| |
| filtered_data = df[(df['Latitude'] >= min_lat) & (df['Latitude'] <= max_lat) & (df['Longitude'] >= min_lon) & (df['Longitude'] <= max_lon)] |
| |
| |
| st.write(f"Displaying data for Latitude between {min_lat} and {max_lat} and Longitude between {min_lon} and {max_lon}") |
| st.dataframe(filtered_data) |
| |
| |
| fig = px.scatter_mapbox(filtered_data, lat='Latitude', lon='Longitude', color='Soil Moisture', |
| color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=3) |
| |
| |
| fig.update_layout(mapbox_style="open-street-map") |
| fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) |
| |
| st.plotly_chart(fig) |
|
|