-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIF_file_read_to_array_to_csv_w_loop.py
75 lines (50 loc) · 2.04 KB
/
SIF_file_read_to_array_to_csv_w_loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
## Import numpy -- needed for array creation
# Import netCDF4 -- needed to read .nc4 file
# troubleshooting note: May want to import HDF5 library to read .nc4 file
import numpy as np
import netCDF4 as nc
import os
directory = r'C:/Users/maria/Downloads/'
# Create variable for the .nc4 SIF file to be oopened
for filename in os.listdir(directory):
if filename.endswith(".nc4") :
SIF_file = "C:/Users/maria/Desktop/JPL/Projects/OCO3_Files/" + filename
# else:
# continue
#Create variable of full SIF file dataset
SIF_dataset = nc.Dataset(SIF_file)
############################
# testing push and pull #
############################
############################
# pulling back to local #
############################
# Create variables of everything we want in the csv.
# In this case it's Daily_SIF_757nm, Latitude, and Longitude
# Note to self : Learn complete gridding process in python using Cartopy
Daily_SIF_757nm = SIF_dataset['Daily_SIF_757nm']
SoundingID = SIF_dataset['Metadata/SoundingId']
Latitude = SIF_dataset['Latitude']
Longitude = SIF_dataset['Longitude']
#Create an individual csv file for each variable of each SIF file!
#a = np.asarray(Daily_SIF_757nm)
#np.savetxt("SIF757_190806.csv", a, delimiter=",")
#import os
#directory = r'C:/Users/maria/Downloads/'
#for filename in os.listdir(directory):
# if filename.endswith(".nc4") :
#print(os.path.join(directory, filename))
a = np.asarray(Longitude)
b = np.asarray(Latitude)
c = np.asarray(Daily_SIF_757nm)
np.savetxt("Longitude_" +filename + ".csv", a, delimiter=",")
np.savetxt("Latitude_" +filename + ".csv", b, delimiter=",")
np.savetxt("SIF757nm_" +filename + ".csv",c, delimiter=",")
else:
continue
#SIF_file.close