Skip to content

Commit f603242

Browse files
committed
Changes for plotting.
1 parent 411be25 commit f603242

8 files changed

Lines changed: 1289 additions & 93 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.pyf
22
*.pyfe
33
*.so
4+
*.eps

build_micro.csh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ set FILES="${DIR}/wv_sat_methods.F90 ${DIR}/micro_mg_utils.F90 ${DIR}/micro_mg2_
4646
#are separated by spaces - the code still compiles if commas are used instead,
4747
#but it crashes when you try to load it into python.
4848

49-
set PUB_FNS='wv_sat_methods_init wv_sat_svp_water wv_sat_svp_ice wv_sat_svp_to_qsat wv_sat_qsat_water wv_sat_qsat_ice micro_mg_init micro_mg_tend calc_precip_frac micro_mg_utils_init ice_deposition_sublimation kk2000_liq_autoconversion ice_autoconversion immersion_freezing contact_freezing snow_self_aggregation accrete_cloud_water_snow secondary_ice_production accrete_rain_snow heterogeneous_rain_freezing accrete_cloud_water_rain self_collection_rain accrete_cloud_ice_snow evaporate_rain sublimate_snow bergeron_process_snow sedimentation avg_diameter rain_fall_speeds'
49+
set PUB_FNS='wv_sat_methods_init micro_mg_init micro_mg_tend calc_precip_frac micro_mg_utils_init'
5050

5151
#CREATE .pyf FILE WITH INTERFACES TO PYTHON:
5252
#=================
@@ -99,4 +99,4 @@ sed -i '/type unknown_type/,/type unknown_type/d' ${NM}.pyf
9999
#Note: -DHAVE_GAMMA_INTRINSICS #defines HAVE_GAMMA_INTRINSICS, which is
100100
#true for ifort and prevents an additional awkward dependency.
101101

102-
f2py -c --fcompiler=intelem -DHAVE_GAMMA_INTRINSICS ${NM}.pyf ${FILES}
102+
f2py -c --fcompiler=gnu95 -DHAVE_GAMMA_INTRINSICS ${NM}.pyf ${FILES}

jacobian2.py

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python
22

3+
import sys
4+
35
import numpy as np
46
import scipy.linalg as la
57
import scipy.stats as stats
@@ -14,8 +16,8 @@
1416

1517
from mg2_constants import *
1618

17-
HIST_FILE_NAME = "/g/g14/santos36/Data/MG2_data_collection.cam.h1.0001-01-06-00000.nc"
18-
CLUSTER_FILE_NAME = "/g/g14/santos36/Data/MG2_data_collection.10_cluster_labels.0001-01-06-00000.nc"
19+
HIST_FILE_NAME = "/home/santos/Data/MG2_data_collection.cam.h1.0001-01-06-00000.nc"
20+
CLUSTER_FILE_NAME = "/home/santos/Data/MG2_data_collection.10_cluster_labels.0001-01-06-00000.nc"
1921

2022
hfile = nc4.Dataset(HIST_FILE_NAME, 'r')
2123
cfile = nc4.Dataset(CLUSTER_FILE_NAME, 'r')
@@ -101,6 +103,12 @@
101103
frzdep_loc = np.empty((1, frzdep.shape[1]), order='F')
102104

103105
timestep = 1.e-8
106+
evap_col_steps = 1
107+
evap_steps = 1
108+
col_steps = 1
109+
auto_accr_steps = 1
110+
auto_steps = 1
111+
accr_steps = 1
104112

105113
# Indices for each variable in the state array.
106114
it = 0
@@ -187,6 +195,7 @@ def s_inv_mult(state):
187195
"iaccr",
188196
"rnagg",
189197
"snagg",
198+
"cnact",
190199
"anadj",
191200
]
192201
process_names = {
@@ -229,9 +238,10 @@ def mg2_tendencies(level, t, q, qc, nc, qi, ni, qr, nr, qs, ns):
229238
nrout2, nsout2, drout2, dsout2, freqs, freqr, nfice, qcrat, \
230239
nadjtot, ncmeitot, mnudeptot, nnudeptot, npsacwstot, nnuccctot, nnuccttot, \
231240
nsacwitot, nnuccrtot, mnuccritot, nnuccritot, npracstot, npratot, nprctot, \
232-
nprc1tot, npraitot, nprcitot, nsubrtot, nraggtot, nsaggtot, errstring, \
233-
prer_evap \
234-
= mg.micro_mg_tend(timestep, t[0,level], q[0,level], qc[0,level], qi[0,level], nc[0,level],
241+
nprc1tot, npraitot, nprcitot, nsubrtot, nraggtot, nsaggtot, subqr, subnr, \
242+
subdr, errstring, prer_evap \
243+
= mg.micro_mg_tend(evap_col_steps, evap_steps, col_steps, auto_accr_steps, auto_steps, accr_steps, timestep, t[0,level],
244+
q[0,level], qc[0,level], qi[0,level], nc[0,level],
235245
ni[0,level], qr[0,level], qs[0,level], nr[0,level], ns[0,level],
236246
relvar_loc[0,level], accre_enhan_loc[0,level], p_loc[0,level], pdel_loc[0,level],
237247
precipf_loc[0,level], liqcldf_loc[0,level], icecldf_loc[0,level], naai_loc[0,level],
@@ -386,37 +396,14 @@ def run_mg2(state, level):
386396
my_ns[0,level] = max(state[ins], 1.e-12)
387397
tends = mg2_tendencies(level, my_t, my_q, my_qc, my_nc, my_qi, my_ni, my_qr,
388398
my_nr, my_qs, my_ns)
389-
return s_inv_mult(tends["Total"])
399+
output = np.zeros((10*(len(ind)+1),))
400+
output[0:10] = s_inv_mult(tends["Total"])
401+
for i in range(len(ind)):
402+
output[10*(i+1):10*(i+2)] = s_inv_mult(tends[short_names[i]])
403+
return output
390404

391405
ind = np.arange(len(short_names))
392406

393-
column = 856
394-
395-
t_loc[:,:] = t[0,:,column]
396-
q_loc[:,:] = q[0,:,column]
397-
qc_loc[:,:] = qc[0,:,column]
398-
qi_loc[:,:] = qi[0,:,column]
399-
nc_loc[:,:] = nc[0,:,column]
400-
ni_loc[:,:] = ni[0,:,column]
401-
qr_loc[:,:] = qr[0,:,column]
402-
qs_loc[:,:] = qs[0,:,column]
403-
nr_loc[:,:] = nr[0,:,column]
404-
ns_loc[:,:] = ns[0,:,column]
405-
relvar_loc[:,:] = relvar[0,:,column]
406-
accre_enhan_loc[:,:] = accre_enhan[0,:,column]
407-
p_loc[:,:] = p[0,:,column]
408-
pdel_loc[:,:] = pdel[0,:,column]
409-
precipf_loc[:,:] = precipf[0,:,column]
410-
liqcldf_loc[:,:] = liqcldf[0,:,column]
411-
icecldf_loc[:,:] = icecldf[0,:,column]
412-
naai_loc[:,:] = naai[0,:,column]
413-
npccn_loc[:,:] = npccn[0,:,column]
414-
rndst_loc[:,:,:] = rndst[0,:,column:column+1,:].transpose([1, 0, 2])
415-
nacon_loc[:,:,:] = nacon[0,:,column:column+1,:].transpose([1, 0, 2])
416-
frzimm_loc[:,:] = frzimm[0,:,column]
417-
frzcnt_loc[:,:] = frzcnt[0,:,column]
418-
frzdep_loc[:,:] = frzdep[0,:,column]
419-
420407
def get_modes_at_level(level):
421408
state = np.zeros((10,))
422409
state[it] = t_loc[0,level]
@@ -433,15 +420,24 @@ def get_modes_at_level(level):
433420
qr_loc, nr_loc, qs_loc, ns_loc)
434421

435422
j_mg2 = ndt.Jacobian(run_mg2, method='forward', order=2)
436-
j_loc = s.dot(sq.dot(la.solve_triangular(sr, j_mg2(s_inv_mult(state),
437-
level).T, trans='T')).T)
423+
j_locs_dimless = j_mg2(s_inv_mult(state), level)
424+
j_loc = s.dot(sq.dot(la.solve_triangular(sr, j_locs_dimless[0:10,:].T, trans='T')).T)
438425
evals, evecs = la.eig(j_loc)
439426
# Sometimes la.eig spits out complex eigenvalues unnecessarily.
440427
if all(np.imag(evals) == 0.):
441428
evals = np.real(evals)
442429
if (np.imag(evecs) == 0.).all():
443430
evecs = np.real(evecs)
444-
return tends, evals, evecs
431+
associations = np.zeros((10, len(ind)))
432+
for i in range(len(ind)):
433+
j_proc_loc = s.dot(sq.dot(la.solve_triangular(sr, j_locs_dimless[10*(i+1):10*(i+2),:].T, trans='T')).T)
434+
j_proc_j_basis = la.solve(evecs, j_proc_loc.dot(evecs))
435+
associations[:,i] = np.abs(np.diag(j_proc_j_basis))
436+
for i in range(10):
437+
assoc_norm = la.norm(associations[i,:], 1)
438+
if assoc_norm != 0.:
439+
associations[i,:] /= assoc_norm
440+
return tends, evals, evecs, associations
445441

446442
def calculate_indices(tends, evals, evecs):
447443
strengths = la.solve(evecs, tends["Total"])
@@ -490,7 +486,7 @@ def evec_bar_graph(evals, strengths, participations):
490486
cutoff2 = 0.5
491487
cutoff3 = 0.9
492488
tend_cutoff = 1.e-10
493-
num_columns = 2048
489+
num_columns = 128
494490

495491
plt.autoscale(tight=True)
496492

@@ -514,7 +510,8 @@ def evec_bar_graph(evals, strengths, participations):
514510
singular_counter = 0
515511

516512
for column in range(num_columns):
517-
print("On column: ", column)
513+
# if column % 16 == 0:
514+
print("On column: ", column, file=sys.stderr)
518515
t_loc[:,:] = t[0,:,column]
519516
q_loc[:,:] = q[0,:,column]
520517
qc_loc[:,:] = qc[0,:,column]
@@ -544,7 +541,7 @@ def evec_bar_graph(evals, strengths, participations):
544541
icecldf_loc, mgncol=1, nlev=lev)
545542
for level in range(lev):
546543
c = label[0,level,column]
547-
tends, evals, evecs = get_modes_at_level(level)
544+
tends, evals, evecs, associations = get_modes_at_level(level)
548545
tot_t = tends["Total"]
549546
tend_norm = (abs(tot_t[iq]) + abs(tot_t[iqc]) + abs(tot_t[iqi]) +
550547
abs(tot_t[iqr]) + abs(tot_t[iqs])) / 2.
@@ -561,14 +558,14 @@ def evec_bar_graph(evals, strengths, participations):
561558
for i in range(len(evals)):
562559
evalues_all[c].append(np.real(evals[i]))
563560
for j in range(len(short_names)):
564-
if np.abs(participations[i,j]) >= cutoff1:
561+
if np.abs(associations[i,j]) >= cutoff1:
565562
evalues1[c][short_names[j]].append(np.real(evals[i]))
566-
if np.abs(participations[i,j]) >= cutoff2:
563+
if np.abs(associations[i,j]) >= cutoff2:
567564
if np.real(evals[i]) < -0.1:
568565
evalues2[c][short_names[j]].append(np.real(evals[i]))
569566
for j2 in range(len(short_names)):
570-
evalue_correlation[short_names[j]][short_names[j2]] += np.abs(participations[i,j2])
571-
if np.abs(participations[i,j]) >= cutoff3:
567+
evalue_correlation[short_names[j]][short_names[j2]] += np.abs(associations[i,j2])
568+
if np.abs(associations[i,j]) >= cutoff3:
572569
evalues3[c][short_names[j]].append(np.real(evals[i]))
573570

574571
#Convert the correlation sum to an average.
@@ -610,7 +607,7 @@ def evec_bar_graph(evals, strengths, participations):
610607
plt.xlabel("Eigenvalue (1/s)")
611608
plt.xlim(1./max_t, 1./min_t)
612609
plt.ylabel("Number of modes")
613-
plt.savefig('./time_hist_all_values_pos.eps')
610+
plt.savefig('./time_hist_all_values_pos_new.eps')
614611
plt.close()
615612

616613
# Histogram of all negative eigenvalues.
@@ -631,7 +628,7 @@ def evec_bar_graph(evals, strengths, participations):
631628
plt.xlabel("Eigenvalue (1/s)")
632629
plt.xlim(1./min_t, 1./max_t)
633630
plt.ylabel("Number of modes")
634-
plt.savefig('./time_hist_all_values_neg.eps')
631+
plt.savefig('./time_hist_all_values_neg_new.eps')
635632
plt.close()
636633

637634
# Histogram of all near-zero eigenvalues.
@@ -652,7 +649,7 @@ def evec_bar_graph(evals, strengths, participations):
652649
plt.xlim(-1./max_t, 1./max_t)
653650
plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))
654651
plt.ylabel("Number of modes")
655-
plt.savefig('./time_hist_all_values_n0.eps')
652+
plt.savefig('./time_hist_all_values_n0_new.eps')
656653
plt.close()
657654

658655
# Now broken out by cluster.
@@ -676,7 +673,7 @@ def evec_bar_graph(evals, strengths, participations):
676673
plt.ylabel("Cluster Index")
677674
plt.clim(vmin=0., vmax=0.2)
678675
plt.colorbar()
679-
plt.savefig('./time_hist_cluster_2D_pos.eps')
676+
plt.savefig('./time_hist_cluster_2D_pos_new.eps')
680677
plt.close()
681678

682679
# Histogram of all negative eigenvalues.
@@ -697,7 +694,7 @@ def evec_bar_graph(evals, strengths, participations):
697694
plt.ylabel("Cluster Index")
698695
plt.clim(vmin=0., vmax=0.2)
699696
plt.colorbar()
700-
plt.savefig('./time_hist_cluster_2D_neg.eps')
697+
plt.savefig('./time_hist_cluster_2D_neg_new.eps')
701698
plt.close()
702699

703700
# Histogram of all near-zero eigenvalues.
@@ -718,7 +715,7 @@ def evec_bar_graph(evals, strengths, participations):
718715
plt.ylabel("Cluster Index")
719716
plt.clim(vmin=0., vmax=0.2)
720717
plt.colorbar()
721-
plt.savefig('./time_hist_cluster_2D_n0.eps')
718+
plt.savefig('./time_hist_cluster_2D_n0_new.eps')
722719
plt.close()
723720

724721
# Now broken up by process.
@@ -748,7 +745,7 @@ def evec_bar_graph(evals, strengths, participations):
748745
plt.ylabel("Process")
749746
plt.clim(vmin=0., vmax=0.2)
750747
plt.colorbar()
751-
plt.savefig('./time_hist_process_2D_pos.eps')
748+
plt.savefig('./time_hist_process_2D_pos_new.eps')
752749
plt.close()
753750

754751
# Histogram of all negative eigenvalues.
@@ -777,7 +774,7 @@ def evec_bar_graph(evals, strengths, participations):
777774
plt.ylabel("Process")
778775
plt.clim(vmin=0., vmax=0.2)
779776
plt.colorbar()
780-
plt.savefig('./time_hist_process_2D_neg.eps')
777+
plt.savefig('./time_hist_process_2D_neg_new.eps')
781778
plt.close()
782779

783780
# Histogram of all near-zero eigenvalues.
@@ -806,7 +803,7 @@ def evec_bar_graph(evals, strengths, participations):
806803
plt.ylabel("Process")
807804
plt.clim(vmin=0., vmax=0.2)
808805
plt.colorbar()
809-
plt.savefig('./time_hist_process_2D_n0.eps')
806+
plt.savefig('./time_hist_process_2D_n0_new.eps')
810807
plt.close()
811808

812809
# Correlation array.
@@ -829,7 +826,7 @@ def evec_bar_graph(evals, strengths, participations):
829826
plt.subplots_adjust(left=0.25)
830827
plt.ylabel("Primary process")
831828
plt.colorbar()
832-
plt.savefig('./process_association.eps')
829+
plt.savefig('./process_association_new.eps')
833830
plt.close()
834831

835832

@@ -877,7 +874,7 @@ def evec_bar_graph(evals, strengths, participations):
877874
ax.tick_params('y', direction='out')
878875
plt.subplots_adjust(left=0.25)
879876
plt.colorbar()
880-
plt.savefig('./time_hist_2D_pos_c{}.eps'.format(c))
877+
plt.savefig('./time_hist_2D_pos_c{}_new.eps'.format(c))
881878
plt.close()
882879

883880
neg_evalues2 = {}
@@ -912,7 +909,7 @@ def evec_bar_graph(evals, strengths, participations):
912909
ax.tick_params('y', direction='out')
913910
plt.subplots_adjust(left=0.25)
914911
plt.colorbar()
915-
plt.savefig('./time_hist_2D_neg_c{}.eps'.format(c))
912+
plt.savefig('./time_hist_2D_neg_c{}_new.eps'.format(c))
916913
plt.close()
917914

918915
n0_evalues2 = {}
@@ -948,7 +945,7 @@ def evec_bar_graph(evals, strengths, participations):
948945
ax.tick_params('y', direction='out')
949946
plt.subplots_adjust(left=0.25)
950947
plt.colorbar()
951-
plt.savefig('./time_hist_2D_n0_c{}.eps'.format(c))
948+
plt.savefig('./time_hist_2D_n0_c{}_new.eps'.format(c))
952949
plt.close()
953950

954951

@@ -963,7 +960,7 @@ def evec_bar_graph(evals, strengths, participations):
963960
plt.title("Number of grid points with given net water mass tendency")
964961
plt.xlabel("Net water tendency")
965962
plt.ylabel("Number of grid points")
966-
plt.savefig('./tend_hist.eps')
963+
plt.savefig('./tend_hist_new.eps')
967964
plt.close()
968965

969966
# Log version of plot
@@ -975,7 +972,7 @@ def evec_bar_graph(evals, strengths, participations):
975972
plt.title("Number of grid points with given net water mass tendency")
976973
plt.xlabel("Net water tendency")
977974
plt.ylabel("Number of grid points")
978-
plt.savefig('./tend_hist_log.eps')
975+
plt.savefig('./tend_hist_log_new.eps')
979976
plt.close()
980977

981978
cutoff_score = stats.percentileofscore(tend_norms, tend_cutoff)

0 commit comments

Comments
 (0)