Skip to content

Commit

Permalink
EOF analysis on model data
Browse files Browse the repository at this point in the history
  • Loading branch information
khider committed Jun 12, 2024
1 parent 49e2ef3 commit 605de5b
Show file tree
Hide file tree
Showing 5 changed files with 1,450 additions and 16 deletions.
Binary file added data/.DS_Store
Binary file not shown.
83 changes: 83 additions & 0 deletions notebooks/.virtual_documents/cesmLME.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@









import s3fs
import fsspec
import xarray as xr
import glob





URL = 'https://js2.jetstream-cloud.org:8001/'








path = f'pythia/cesmLME'











fs = fsspec.filesystem("s3", anon=True, client_kwargs=dict(endpoint_url=URL))


pattern = f's3://{path}/*.nc'


files = sorted(fs.glob(pattern))





files[0:2]


fileset = [fs.open(file) for file in files[0:2]]


data = xr.open_dataset(fileset[0])


data





# This works
dataMul = xr.open_mfdataset(fileset[:3], combine='by_coords')


dataMul












123 changes: 120 additions & 3 deletions notebooks/.virtual_documents/notebook-template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,134 @@



import sys
#To deal with model data
import s3fs
import fsspec
import xarray as xr
import glob

#To deal with proxy data
import pandas as pd
import numpy as np

#To deal with analysis
import pyleoclim as pyleo
from eofs.xarray import Eof

#Plotting and mapping
import cartopy.crs as ccrs
import matplotlib.pyplot as plt





# as well as any and all of your code cells
print("Hello world!")



URL = 'https://js2.jetstream-cloud.org:8001/' #Locate and read a file


path = f'pythia/cesmLME' # specify data location


fs = fsspec.filesystem("s3", anon=True, client_kwargs=dict(endpoint_url=URL))
pattern = f's3://{path}/*.nc'
files = sorted(fs.glob(pattern))





base_name = 'pythia/cesmLME/b.ie12.B1850C5CN.f19_g16.LME.002.cam.h0.'
time_period = '085001-184912'

names = [name for name in files if base_name in name and time_period in name]

names


fileset = [fs.open(file) for file in names]





%%time
for idx,item in enumerate(fileset):
ds_u = xr.open_dataset(item)
var_name = names[idx].split('.')[-3]
da = ds_u[var_name]
try:
ds[var_name]= da
except:
ds = da.to_dataset()
ds.attrs = ds_u.attrs
ds_u.close()
da.close()


ds





ds_geo = ds.sel(lat=slice(-27,27), lon=slice(250,330))





#ds_geo.to_netcdf(path='../data/LME.002.cam.h0.precip_iso.085001-184912.nc')


ds_geo





%%time
p16O = ds_geo['PRECRC_H216Or'] + ds_geo['PRECSC_H216Os'] + ds_geo['PRECRL_H216OR'] + ds_geo['PRECSL_H216OS']
p18O = ds_geo['PRECRC_H218Or'] + ds_geo['PRECSC_H218Os'] + ds_geo['PRECRL_H218OR'] + ds_geo['PRECSL_H218OS']

p16O = p16O.where(p16O > 1e-18, 1e-18)
p18O = p18O.where(p18O > 1e-18, 1e-18)

d18Op = (p18O / p16O - 1)*1000





d18Oa = d18Op - d18Op.mean(dim='time')





solver = Eof(d18Oa, weights=None)





eof1 = solver.eofsAsCovariance(neofs=1)





clevs = np.linspace(-2, 5, 20)
proj = ccrs.PlateCarree(central_longitude=290)
ax = plt.axes(projection=proj)
ax.coastlines()
#ax.set_global()
eof1[0].plot.contourf(ax=ax, levels = clevs, cmap=plt.cm.RdBu_r,
transform=ccrs.PlateCarree(), add_colorbar=True)
ax.set_title('EOF1 expressed as covariance', fontsize=16)
plt.show()



Expand Down
16 changes: 14 additions & 2 deletions notebooks/cesmLME.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "f7604cb4-59ec-4068-adeb-b79aadb50db7",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 's3fs'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01ms3fs\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mfsspec\u001b[39;00m\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mxarray\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mxr\u001b[39;00m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 's3fs'"
]
}
],
"source": [
"import s3fs\n",
"import fsspec\n",
Expand Down
Loading

0 comments on commit 605de5b

Please sign in to comment.