Skip to content

Commit

Permalink
Upgrade gridding method
Browse files Browse the repository at this point in the history
  • Loading branch information
angehung5 authored May 31, 2024
1 parent 5c94a72 commit 9fe6f80
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions python/global_data_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

import os
import sys
import monet
from datetime import datetime, timedelta, timezone

import monet
import numpy as np
import xarray as xr
from netCDF4 import Dataset
Expand Down Expand Up @@ -107,14 +107,18 @@ def write_varatt(var, attname, att):

def read_gfs_climatology(filename, basefile, varname):
readin = xr.open_dataset(filename)
readin = readin.set_coords(["lat", "lon"]).rename({"grid_xt":"x", "grid_yt":"y", "lat":"latitude", "lon":"longitude"})
readin = readin.set_coords(["lat", "lon"]).rename(
{"grid_xt":"x", "grid_yt":"y", "lat":"latitude", "lon":"longitude"}
)

nlev = len(readin.lev.data)

if varname == "pavd":
DATA = np.empty([nlev, basefile.zc.data.shape[1], basefile.zc.data.shape[2]])
for ll in np.arange(nlev):
DATA[ll, :, :] = basefile["zc"].monet.remap_nearest(readin[varname][0, ll, :, :]).data
DATA[ll, :, :] = (
basefile["zc"].monet.remap_nearest(readin[varname][0, ll, :, :]).data
)
else:
DATA = basefile["zc"].monet.remap_nearest(readin[varname][0, :, :]).data

Expand All @@ -126,8 +130,8 @@ def read_gfs_climatology(filename, basefile, varname):

def read_frp_local(filename, basefile):
readin = xr.open_dataset(filename)
readin = readin.rename({"Latitude":"y", "Longitude":"x"})
readin["x"] = readin["x"].where(readin["x"]>0, readin["x"]+360)
readin = readin.rename({"Latitude": "y", "Longitude": "x"})
readin["x"] = readin["x"].where(readin["x"] > 0, readin["x"] + 360)

grid_xt, grid_yt = np.meshgrid(readin["x"].data, readin["y"].data)
yt = xr.DataArray(grid_yt, dims=["y", "x"], name="latitude")
Expand Down Expand Up @@ -253,7 +257,9 @@ def read_frp_local(filename, basefile):
print("---- Checking variable dimensions...")
print("------------------------------------")
basefile = xr.open_dataset(f_met)
basefile = basefile.set_coords(["lat", "lon"]).rename({"grid_xt":"x", "grid_yt":"y", "lat":"latitude", "lon":"longitude"})
basefile = basefile.set_coords(["lat", "lon"]).rename(
{"grid_xt":"x", "grid_yt":"y", "lat":"latitude", "lon":"longitude"}
)

# dimension sizes
ntime = len(basefile["time"].data)
Expand Down

0 comments on commit 9fe6f80

Please sign in to comment.