diff options
Diffstat (limited to 'store/works/life/gpcp/GpcpConverter.py')
-rw-r--r-- | store/works/life/gpcp/GpcpConverter.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/store/works/life/gpcp/GpcpConverter.py b/store/works/life/gpcp/GpcpConverter.py new file mode 100644 index 0000000..7aadd44 --- /dev/null +++ b/store/works/life/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") |