Skip to content

Commit

Permalink
Fix bugs with PSM forward
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhu2e committed Apr 18, 2024
1 parent ff8b553 commit 9585dc5
Show file tree
Hide file tree
Showing 6 changed files with 971 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cfr/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,10 @@ def plot(self, **kwargs):
if len(self.da.dims) == 3:
t_value = self.da.time.values[0]
elif len(self.da.dims) == 2:
t_value = self.da.time.values
try:
t_value = self.da.time.values
except:
t_value = ''

try:
date_str = '-'.join(str(t_value).split('-')[:2])
Expand Down
1 change: 1 addition & 0 deletions cfr/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def get_pseudo(self, psm=None, signal=None, calibrate=True,
noise = utils.colored_noise(**_colored_noise_kws)

self.pseudo.value += noise / np.std(noise) * sigma
self.pseudo.R = np.var(noise)
if verbose: utils.p_success(f'>>> ProxyRecord.pseudo added with {noise} noise (SNR={SNR}).')

if match_var or match_mean:
Expand Down
13 changes: 11 additions & 2 deletions cfr/reconjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,20 +476,29 @@ def calib_psms(self, ptype_psm_dict=None, ptype_season_dict=None, ptype_clim_dic
if verbose:
p_success(f'>>> {self.proxydb.nrec_tags("calibrated")} records tagged "calibrated" with ProxyRecord.psm created')

def forward_psms(self, verbose=False, **kwargs):
def forward_psms(self, verbose=False, ptype_forward_dict=None):
''' Forward the PSMs.
Args:
verbose (bool, optional): print verbose information. Defaults to False.
'''
ptype_forward_dict_default = {}
if ptype_forward_dict is not None: ptype_forward_dict_default.update(ptype_forward_dict)
ptype_forward_dict = self.io_cfg(
'ptype_forward_dict', ptype_forward_dict_default,
verbose=verbose)

pdb_calib = self.proxydb.filter(by='tag', keys={'calibrated'})

for pid, pobj in tqdm(pdb_calib.records.items(), total=pdb_calib.nrec, desc='Forwarding the PSMs'):
for vn in pobj.psm.climate_required:
if 'clim' not in pobj.__dict__ or f'model.{vn}' not in pobj.clim:
pobj.get_clim(self.prior[vn], tag='model')

pobj.pseudo = pobj.psm.forward(**kwargs)
if pobj.ptype in ptype_forward_dict:
pobj.pseudo = pobj.psm.forward(**ptype_forward_dict[pobj.ptype])
else:
pobj.pseudo = pobj.psm.forward()

if verbose:
p_success(f'>>> ProxyRecord.pseudo created for {pdb_calib.nrec} records')
Expand Down
8 changes: 5 additions & 3 deletions cfr/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def setlabel(ax, label, loc=2, borderpad=0.6, **kwargs):
def plot_field_map(field_var, lat, lon, levels=50, add_cyclic_point=True,
title=None, title_size=20, title_weight='normal', figsize=[10, 8],
plot_proxydb=False, proxydb=None, plot_proxydb_lgd=False, proxydb_lgd_kws=None,
proxy_marker=None, proxy_color=None,
proxy_marker=None, proxy_color=None, modern_topo=True,
site_lats=None, site_lons=None, site_marker='o',
site_markersize=50, site_color=sns.xkcd_rgb['amber'],
projection='Robinson', transform=ccrs.PlateCarree(),
Expand Down Expand Up @@ -408,8 +408,10 @@ def plot_field_map(field_var, lat, lon, levels=50, add_cyclic_point=True,
else:
ax.set_global()

ax.add_feature(cfeature.LAND, facecolor=land_color, edgecolor=land_color, zorder=land_zorder)
ax.add_feature(cfeature.OCEAN, facecolor=ocean_color, edgecolor=ocean_color, zorder=ocean_zorder)
if modern_topo:
ax.add_feature(cfeature.LAND, facecolor=land_color, edgecolor=land_color, zorder=land_zorder)
ax.add_feature(cfeature.OCEAN, facecolor=ocean_color, edgecolor=ocean_color, zorder=ocean_zorder)

if add_coastlines:
ax.coastlines(zorder=99)

Expand Down
948 changes: 948 additions & 0 deletions docsrc/notebooks/test-lmr-cli.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='cfr', # required
version='2024.4.4',
version='2024.4.17',
description='cfr: a Python package for Climate Field Reconstruction',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down Expand Up @@ -43,6 +43,7 @@
'pathos',
'fbm',
'pyvsl',
'pybaywatch',
],
'ml': [
'scikit-learn',
Expand Down

0 comments on commit 9585dc5

Please sign in to comment.