aboutsummaryrefslogtreecommitdiff
path: root/gpcp/GpcpConverter.py
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-05-26 13:45:32 +0800
committercrupest <crupest@outlook.com>2022-05-26 13:45:32 +0800
commited13ea187b3076ceaa5b1bf7af39e797d2a045ec (patch)
tree21daea4386e17e0e621c7606f2caa2907bf80c68 /gpcp/GpcpConverter.py
parentf1d954258d32596796cc0802fa7cc183136518f4 (diff)
downloadlife-ed13ea187b3076ceaa5b1bf7af39e797d2a045ec.tar.gz
life-ed13ea187b3076ceaa5b1bf7af39e797d2a045ec.tar.bz2
life-ed13ea187b3076ceaa5b1bf7af39e797d2a045ec.zip
...
Diffstat (limited to 'gpcp/GpcpConverter.py')
-rw-r--r--gpcp/GpcpConverter.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/gpcp/GpcpConverter.py b/gpcp/GpcpConverter.py
new file mode 100644
index 0000000..7aadd44
--- /dev/null
+++ b/gpcp/GpcpConverter.py
@@ -0,0 +1,29 @@
+import pandas
+from pandas import DataFrame
+import xarray as xr
+import os
+import os.path
+
+latitude = 30
+longitude = 114
+
+data_dir = os.path.join(os.path.dirname(__file__), "GpcpData")
+files = os.listdir(data_dir)
+files = [os.path.join(data_dir, f) for f in files if f.endswith(".nc")]
+files.sort()
+
+result = DataFrame([], columns=["date", "prec"], dtype="object")
+
+for file in files:
+ data_set = xr.open_dataset(file)
+ df = data_set.to_dataframe()
+ data_set.close()
+ df = df.query(
+ f"latitude == {latitude} & longitude == {longitude} & nv == 1")
+ df = df.reset_index()
+ df = df.drop(columns=["latitude", "longitude", "nv",
+ "lat_bounds", "lon_bounds", "time_bounds"])
+ df = df.rename(columns={"time": "date", "precip": "prec"})
+ result = pandas.concat([result, df], ignore_index=True)
+
+result.to_csv("./out.csv")