Skip to content

Commit

Permalink
updated processing compatibility with ismip6
Browse files Browse the repository at this point in the history
  • Loading branch information
pvankatwyk committed Oct 24, 2023
1 parent 5b671a7 commit 727256a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ main.py
run_gp.py
*.out
*.sh
supplemental/


.vscode/
Expand Down
23 changes: 18 additions & 5 deletions ise/data/processors/forcings.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ def add_sectors(self, grids: GridSectors):
self: AtmosphereForcing: AtmosphereForcing class with
sectors added.
"""
self.data = self.data.drop(labels=["lon_bnds", "lat_bnds", "lat2d", "lon2d"])
for col in ["lon_bnds", "lat_bnds", "lat2d", "lon2d"]:
try:
self.data = self.data.drop(labels=[col])
except ValueError:
pass
self.data = self.data.to_dataframe().reset_index(level="time", drop=True)
# merge forcing data with grid data
self.data = pd.merge(
Expand Down Expand Up @@ -358,7 +362,7 @@ def __init__(self, aogcm_dir: str):

# Load all data: thermal forcing, salinity, and temperature
files = get_all_filepaths(path=self.path, filetype="nc")

files = [f for f in files if "8km" in f]
if len(files) > 1: # if there is a "v2" file in the directory, use that one
for file in files:
if "v2" in file:
Expand All @@ -379,7 +383,11 @@ def add_sectors(self, grids: GridSectors):
Returns:
self: IceCollapse: IceCollapse class with sectors added.
"""
self.data = self.data.drop(labels=["lon", "lon_bnds", "lat", "lat_bnds"])
for col in ["lon_bnds", "lat_bnds", "lat2d", "lon2d"]:
try:
self.data = self.data.drop(labels=[col])
except ValueError:
pass
self.data = self.data.to_dataframe().reset_index(level="time", drop=False)
self.data = pd.merge(
self.data, grids.data, left_index=True, right_index=True, how="outer"
Expand All @@ -389,8 +397,10 @@ def add_sectors(self, grids: GridSectors):
columns=[
"time",
"mapping",
"lat",
"lon",
"lat_x",
"lat_y",
"lon_x",
"lon_y",
]
)
return self
Expand Down Expand Up @@ -473,6 +483,7 @@ def aggregate_atmosphere(
# Get all NC files that contain data from 1995-2100
filepaths = get_all_filepaths(path=directory, filetype="nc")
filepaths = [f for f in filepaths if "1995-2100" in f]
filepaths = [f for f in filepaths if "8km" in f]

# Useful progress prints
print("Files to be processed...")
Expand Down Expand Up @@ -536,6 +547,7 @@ def aggregate_ocean(
# Get all NC files that contain data from 1995-2100
filepaths = get_all_filepaths(path=directory, filetype="nc")
filepaths = [f for f in filepaths if "1995-2100" in f]
filepaths = [f for f in filepaths if "8km" in f]

# In the case of ocean forcings, use the filepaths of the files to determine
# which directories need to be used for OceanForcing processing. Change to
Expand Down Expand Up @@ -607,6 +619,7 @@ def aggregate_icecollapse(
# those directories rather than individual files.
aogcms = list(set([f.split("/")[-2] for f in filepaths]))
filepaths = [f"{directory}/{aogcm}/" for aogcm in aogcms]
# filepaths = [f for f in filepaths if "8km" in f]

# Useful progress prints
print("Files to be processed...")
Expand Down

0 comments on commit 727256a

Please sign in to comment.