Hello,
I'm a student at MIT working on a project (using SeaDAS ver 8.30 on an M2 Mac Sonoma 14.5), I'm trying to export my input file (which is an MTL.txt file) as a CSV. The steps I took to do this were as follows:
SeaDAS-Toolbox >> SeaDAS Processors >> l2gen
At this point, I input my MTL.txt file as the ifile, went to the "products" tab to select the relevant products for the project (rhos, color_a, cloud_albedo, diatoms_hirata, dinoflagellates_hirata, greenalgae_hirata, and primnesiophytes_hirata), selected "apply" and then "run."
Once l2gen finished running, I selected the output file in the "file manager" section and then took the following steps:
File >> Export >> CSV >> Export Product
After the file had finished exporting (which took approximately a half day), I opened the file (LANDSAT8_OLI.20180423T152010.L2.OC.csv) in Numbers (or Excel) and it had no data other than a header.
1. Why am I not able to export a .csv file with data? Am I missing a step when exporting from SeaDAS?
2. Additionally I am not able to open a .csv file using Numbers or excel but can access it in python. The error message I get is 'file too large.' Since I'm using python this isn't my primary issue, but I'm curious.
For context, I have not been able in the past to open other .csv files (exported from someone else) in Numbers. However, using python, I have been able to access the data (so I know it works). I also noticed after opening the file in Numbers that it had all of the same headers as the other CSV files, but beyond that, the rest of the file was empty (as was the file icon in Finder).
Any help would be greatly appreciated, thank you for your time!
Trouble Exporting a CSV File from SeaDAS
-
- Posts: 2
- Joined: Tue Sep 24, 2024 8:25 pm America/New_York
-
- Subject Matter Expert
- Posts: 114
- Joined: Fri Jun 03, 2022 10:54 am America/New_York
- Location: NASA GSFC
- Endorsed: 8 times
- Contact:
Re: Trouble Exporting a CSV File from SeaDAS
Hello,
Since you're working with Python, you may want to try the following Python code to convert Landsat 8 files to CSV instead of using SeaDAS. This should be a faster and more efficient approach:
Let me know if this helps.
Guoqing
Since you're working with Python, you may want to try the following Python code to convert Landsat 8 files to CSV instead of using SeaDAS. This should be a faster and more efficient approach:
Code: Select all
# install the netCDF4 and pandas package if necessary
pip install netCDF4 pandas
import netCDF4 as nc
import pandas as pd
import numpy as np
# Load the NetCDF file
file_path = "/LANDSAT8_OLI.20180423T152010.L2.OC.nc"
dataset = nc.Dataset(file_path, mode='r')
# List of variables in the NetCDF file
print(dataset.groups['geophysical_data'].variables.keys())
# For example, let’s extract some common variables like chlor_a (chlorophyll concentration)
chlor_a = dataset.groups['geophysical_data'].variables['chlor_a'][:]
lon = dataset.groups['navigation_data'].variables['longitude'][:]
lat = dataset.groups['navigation_data'].variables['latitude'][:]
# Convert NaN values to zeros or handle as needed
chlor_a = np.nan_to_num(chlor_a)
# Flatten the data arrays
chlor_a_flat = chlor_a.flatten()
lon_flat = lon.flatten()
lat_flat = lat.flatten()
# Create a Pandas DataFrame
data = pd.DataFrame({
'Longitude': lon_flat,
'Latitude': lat_flat,
'Chlorophyll': chlor_a_flat
})
# Export DataFrame to CSV
output_csv = "landsat8_oc_data.csv"
data.to_csv(output_csv, index=False)
print(f"Data successfully exported to {output_csv}")
Guoqing