def depletion_degrees(): with app.app_context(): ree_data = sample_ree(normalized=True) major_element_data = whole_rock_major_elements(dataframe=True) mineral_data = xenolith_minerals("normalized_weight") model = DepletionModel(argv[1]) _ = [get_spinel_data(s) for s in mineral_data] spinel_data = DataFrame.from_dict(_).set_index('id') ree_fit = model.fit_HREE(ree_data) # Solid composition data is in %wt of solid component Mg_fit = model.fit('Solid Composition', major_element_data, 'MgO') Al_fit = model.fit('Solid Composition', major_element_data, 'Al2O3') def series(): """ Rename series for consistency """ fits = (ree_fit, Mg_fit, Al_fit) names = ('ree', 'MgO', 'Al2O3') for fit, name in zip(fits, names): s = fit['mass'] s.name = name yield s masses = concat(list(series()), axis=1) depletion = (100 - masses).reset_index() return [r.to_dict() for i, r in depletion.iterrows()]
def create_data(): with app.app_context(): data = [ sample_temperatures(s, distinct=min, uncertainties=True) for s in xenoliths() ] with open(cache, "wb") as f: dump(data, f) return data
def ree_data(sample_id): with app.app_context(): s = Sample.query.get(sample_id) s.to_remove = for_removal[s.id] # Index of elements to remove from regression ix = N.in1d(rare_earths, s.to_remove) s.X, s.Y = ree_pyroxene(s, 1.5) # Pressure in GPa s.res = regress(s.X[~ix], s.Y[~ix]) s.temperature = temperature(s.res) return s
def run_model(): fig, ax = plt.subplots(figsize=(4, 3.5)) with app.app_context(): data = sample_ree(normalized=True) colors = sample_colors() model = DepletionModel(argv[1]) ree_scatter(ax, model, data, colors) ax.set_xlabel(r'HREE depletion degrees (%)') ax.set_ylabel(r'Mass ratio: re-enriching fluid/sample') ax.set_xlim([0, 20]) ax.set_ylim([0, 0.012]) fig.savefig('output/ree-trends.pdf', bbox_inches='tight')
import numpy as N from uncertainties import ufloat from figurator import tex_renderer, write_file from xenoliths import app from data import ree_data, summary_data template = tex_renderer.get_template("temperature.tex") with app.app_context(): text = template.render(samples=summary_data()) write_file("build/temperatures.tex", text)
def run_model(src, dst, clinopyroxene=False): with app.app_context(): data = sample_ree(normalized=True, mode='whole_rock') colors = sample_colors() model = DepletionModel(src) depleted = model.fit_HREE(data) trace = model.tables['Solid Trace'] fig, ax = subplots(1, 1, figsize=(3.5, 3.5)) ax.plot(trace.Temperature, trace.Pressure / 1e4, 'k') ax.set_ylabel(r'Pressure (GPa)') ax.set_xlabel("Temperature (\u00b0C)") df = concat([depleted, colors], axis=1) ax.scatter(df.Temperature, df.Pressure / 1e4, color="white", s=50, zorder=8) ax.scatter(df.Temperature, df.Pressure / 1e4, color=df.color, s=20, zorder=10) for i, row in df.iterrows(): y = 0 x = 5 if i in ['CK-3', 'CK-7']: x -= 28 y -= 5 ax.annotate(i, xy=(row.Temperature, row.Pressure / 1e4), color=row.color, xytext=(x, y), textcoords='offset points') ax.set_ylim([2.5, 0]) ax.set_xlim([1230, 1350]) ax.annotate("garnet out", xy=(1345, 2.05), xytext=(-28, 2), textcoords='offset points', size=7, style='italic') ax.annotate("start: DMM at 3.0 GPa, 1350ºC", xy=(1340, 2.5), xytext=(-15, 2), textcoords='offset points', ha='right', va='bottom', size=7) ax.annotate("↓", xy=(1340, 2.5), rotation=25, xytext=(-7, 2), textcoords='offset points', ha='right', va='bottom', size=10) update_axes(ax) fig.savefig(dst, bbox_inches='tight')
def sample_colors(): with app.app_context(): samples = xenoliths() return [s.color for s in samples]
def run_model(src, dst, clinopyroxene=False): with app.app_context(): data = sample_ree(normalized=True, mode='cpx' if clinopyroxene else 'whole_rock') colors = sample_colors() model = DepletionModel(src) if clinopyroxene: depleted = model.fit_HREE(data, table='clinopyroxene_0 trace') else: depleted = model.fit_HREE(data) enrichment, multiplier = model.enrichment(data, depleted) # Create primitive-mantle normalized dataset Sun_PM = get_melts_data('literature/Sun_McDonough_PM.melts') PM_trace = Sun_PM.trace.ix[:, 0] # Add NMORB NMORB = get_melts_data('literature/NMORB_trace.melts') NMORB_trace = ree_only(NMORB.trace.transpose() / PM_trace) # Alkali basalt alkali = read_table('literature/Farmer_1995-Alkali-basalt.txt', comment="#", index_col=0) alkali /= PM_trace alkali_trace = ree_only(alkali) vals = [element(i) for i in data.columns] d = ree_only(depleted) grid = dict(height_ratios=(4.5, 1), hspace=0.1, right=0.99, left=0.16) fig, (ax1, ax2) = subplots(2, 1, figsize=(3.5, 6), gridspec_kw=grid) def create_main_axis(ax): for i, row in d.iterrows(): c = colors.ix[row.name][0] # Plot real data series = data.ix[row.name] u = series.map(lambda x: x.n) s = series.map(lambda x: x.s) ax.fill_between(vals, u - s, u + s, facecolor=c, edgecolor='none', alpha=0.2) def plot(name, x, y, **kwargs): if i == 'CK-3': kwargs['label'] = name else: kwargs['label'] = "" p = ax.plot(x, y, color=c, **kwargs) if clinopyroxene: s = 'clinopyroxene' else: s = 'whole-rock' plot('Measured ' + s, vals, u) # Plot calculated best fit plot("Modeled depleted", d.columns, row, linestyle='--', linewidth=1) v = enrichment.ix[row.name] if i == 'CK-2': # Don't include CK-2 because it isn't depleted, so results are spurious. continue plot("Enriching melt", d.columns, v, linestyle=':', linewidth=1) # Plot NMORB ax.fill_between(NMORB_trace.columns, NMORB_trace.ix[0, :], NMORB_trace.ix[0, :] - 0.5, color='#bbbbbb', linewidth=1.5, zorder=-5, label="") ax.fill_between(alkali_trace.columns, alkali_trace.min(), alkali_trace.max(), facecolor='#dddddd', edgecolor='none', zorder=-10, label="") ax.set_ylim(.01, 100) ax.set_xlim(element('La') - 0.1, element('Lu')) ax.yaxis.set_ticklabels( ["{:g}".format(v) for v in ax.yaxis.get_ticklocs()]) ax.set_ylabel("Rare-earth element abundance / Primitive Mantle") ax.xaxis.set_ticks(vals) ax.xaxis.set_ticklabels(data.columns) ax.set_yscale('log') ax.text(element('Ce') - 0.5, 40, "Alkali basalt", rotation=-28, color='#888888') ax.text(element('La'), 5, "NMORB", rotation=15, color='#888888') legend = ax.legend(loc="upper right") fr = legend.get_frame() fr.set_lw(0.5) create_main_axis(ax1) update_axes(ax1) fig.subplots_adjust(top=0.99, right=0.99) ree_scatter(ax2, model, data, colors) ax2.set_ylim([0, 1.2]) ax2.set_xlabel(r'HREE depletion degrees (%)') ax2.set_ylabel("Enriching fluid\nassimilated (%)") ax2.yaxis.set_label_coords(-0.1, 0.22) update_axes(ax2) axis_labels(ax1, ax2, pad=.16, fontsize=14) fig.savefig(dst, bbox_inches='tight')