Skip to content

Commit

Permalink
move find CMIP fun to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
beth182 committed May 1, 2024
1 parent be7e23b commit d865267
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 49 deletions.
33 changes: 32 additions & 1 deletion heat_scan/tools/pangeo_CMIP/pangeo_CMIP_funs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,35 @@ def cmip6_via_pangeo(zstore, plot=False):
# To plot the first time step
ds.tas.isel(time=0).plot()

return ds
return ds


def main_find_CMIP(year=None):
"""
:param save_path:
:return:
"""
# ToDo: docstring here

# ToDo: make function to search the csv for user's choices here - where the zstore is returned

# tasmax
# r1i1p1f1
# NOAA-GFDL
# ScenarioMIP
# ssp245
# day
zstore = 'gs://cmip6/CMIP6/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp245/r1i1p1f1/day/tasmax/gr1/v20180701/'
# zstore = 'gs://cmip6/CMIP6/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp585/r1i1p1f1/day/tasmax/gr1/v20180701/'
# zstore = 'gs://cmip6/CMIP6/ScenarioMIP/CCCma/CanESM5/ssp245/r1i1p2f1/day/tasmax/gn/v20190429/'
# zstore = 'gs://cmip6/CMIP6/ScenarioMIP/BCC/BCC-CSM2-MR/ssp245/r1i1p1f1/day/tasmax/gn/v20190318/'

# find the dataset
ds = cmip6_via_pangeo(zstore=zstore)

# if there is a target year, subset the dataset by that year
if year != None:
ds = ds.sel(time=ds.time.dt.year.isin([year]))

return ds
62 changes: 14 additions & 48 deletions heat_scan/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,24 @@
from heat_scan.transport import plotting_funs


def main_find_CMIP(year=None):
"""

:param save_path:
:return:
"""
# ToDo: function to search the csv for user's choices here

# where the zstore is returned

# tasmax
# r1i1p1f1
# NOAA-GFDL
# ScenarioMIP
# ssp245
# day
zstore = 'gs://cmip6/CMIP6/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp245/r1i1p1f1/day/tasmax/gr1/v20180701/'
# zstore = 'gs://cmip6/CMIP6/ScenarioMIP/NOAA-GFDL/GFDL-ESM4/ssp585/r1i1p1f1/day/tasmax/gr1/v20180701/'
# zstore = 'gs://cmip6/CMIP6/ScenarioMIP/CCCma/CanESM5/ssp245/r1i1p2f1/day/tasmax/gn/v20190429/'
# zstore = 'gs://cmip6/CMIP6/ScenarioMIP/BCC/BCC-CSM2-MR/ssp245/r1i1p1f1/day/tasmax/gn/v20190318/'
if __name__ == "__main__":
save_path = os.getcwd().replace('\\', '/') + '/'

# find the dataset
ds = pangeo_CMIP_funs.cmip6_via_pangeo(zstore=zstore)
# get data from a given year
# year = 2100
year = 2050
# year = 2015

# if there is a target year, subset the dataset by that year
if year != None:
ds = ds.sel(time=ds.time.dt.year.isin([year]))
# plot data
# straight variable at a given time
# plotting_funs.plt_straight_variable(ds=ds, year=year, save_path=save_path, time=210) # 210: summer?

return ds
# Count of days where variable is over a given threshold
# define threshold
threshold_temp = 30 + constants.convert_kelvin
plotting_funs.plt_count_over_threshold(ds=ds, threshold=threshold_temp, year=year, save_path=save_path)


save_path = os.getcwd().replace('\\', '/') + '/'






# get data from a given year
# year = 2100
year = 2050
# year = 2015


# plot data
# straight variable at a given time
# plotting_funs.plt_straight_variable(ds=ds, year=year, save_path=save_path, time=210) # 210: summer?


# Count of days where variable is over a given threshold
# define threshold
threshold_temp = 30 + constants.convert_kelvin
plotting_funs.plt_count_over_threshold(ds=ds, threshold=threshold_temp, year=year, save_path=save_path)

print('end')
print('end')

0 comments on commit d865267

Please sign in to comment.