Skip to content

Commit

Permalink
Merge pull request #74 from e-koch/master
Browse files Browse the repository at this point in the history
Updates to some examples scripts; Change numpy version for Travis
  • Loading branch information
e-koch committed Oct 13, 2015
2 parents 86e1c29 + 5738a13 commit 10c41da
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ install:
- source activate test

# Now install dependencies
- conda install --yes numpy
- conda install --yes numpy==1.9.0
- conda install --yes scipy
- conda install --yes matplotlib
- conda install --yes pandas
- conda install --yes statsmodels
- conda install --yes scikit-learn
- conda install --yes astropy==0.4rc1
- conda install --yes astropy

# Use pip to install development versions
- pip install git+https://github.com/dendrograms/astrodendro.git
Expand Down
36 changes: 26 additions & 10 deletions Examples/analysis_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import numpy as np
import turbustat.analysis as ta
from turbustat.statistics import statistics_list
import os
import subprocess
import sys
Expand Down Expand Up @@ -106,20 +107,21 @@
print "Making distance plots."

ta.comparison_plot(path, comparisons=good_comparison,
out_path=path+"Distance Plots/")
out_path=path+"Distance Plots/",
design_matrix=design_matrix)

# Run the R-script to fit the data to the model

# Must have 0_0 and 2_2 comparisons to run

if not "0_0" in good_comparison and not "2_2" in comparison_plot:
if "0_0" not in good_comparison and "2_2" not in good_comparison:
raise StandardError("Model fitting requires 0_0 and 2_2 to be available.")

os.chdir(path)

print "Fitting model of given design."

subprocess.call(['Rscript', path+"FactorialAnalysis.R"])
subprocess.call(['Rscript', "FactorialAnalysis.R"])

# This should create two output tables of the whole dataset.

Expand All @@ -128,23 +130,37 @@
print "Running metric validation."

subprocess.call(['Rscript',
"/Users/eric/Dropbox/code_development/TurbuStat/Examples/noise_validation.r",
os.path.join(turbustat_path, "Examples/noise_validation.r"),
path, "10000"])

subprocess.call(['Rscript',
"/Users/eric/Dropbox/code_development/TurbuStat/Examples/signal_validation.r",
os.path.join(turbustat_path, "Examples/signal_validation.r"),
path, "10000"])

# Finally, create the model plots

print "Creating model plots."

execfile(turbustat_path+"Examples/effect_plots.py")
execfile(os.path.join(turbustat_path, "Examples/effect_plots.py"))

effect_plots(path+"DataforFits.csv", path+"ResultsFactorial.csv", save=True,
out_path=path+'Model Plots/')
# Remove PDF_AD from the list

map_all_results(path+"ResultsFactorial.csv", save=True, normed=True,
out_path=path+'Model Plots/')
statistics_list.remove("PDF_AD")

effect_plots("DataforFits.csv", "ResultsFactorial.csv", save=True,
out_path='Model Plots/')

# Only show results of the good statistics
good_stats = ["Cramer", "DeltaVariance", "Dendrogram_Hist",
"Dendrogram_Num", "PCA", "PDF_Hellinger", "SCF", "VCA", "VCS",
"VCS_Density", "VCS_Velocity", "Skewness", "Kurtosis"]

# THE ASPECT RATIO IS FUNKY
# NEED TO ADJUST BY HAND
# Use: p.ion(), and set save_name=None to alter by-hand

map_all_results("ResultsFactorial.csv", normed=False, max_order=2,
save_name="map_all_results.pdf",
out_path='Model Plots/', statistics=good_stats)

print "Finished!"
10 changes: 5 additions & 5 deletions Examples/effect_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ def map_all_results(effects_file, min_zscore=2.0, save_name=None,
10,
2)

p.figure(figsize=(16, 7))
p.imshow(values, vmin=0, vmax=10, cmap=milagro,
interpolation="nearest")
p.xticks(np.arange(len(model_effects)), model_effects, rotation=90,
fontsize=18)
p.yticks(np.arange(len(statistics)), stat_labels, fontsize=18)
fontsize=24)
p.yticks(np.arange(len(statistics)), stat_labels, fontsize=24)
cbar = p.colorbar(fraction=0.05, shrink=0.9)
cbar.ax.set_ylabel(r'$t$-value', size=18)
cbar.ax.tick_params(labelsize=18)
cbar.ax.set_ylabel(r'$t$-value', size=24)
cbar.ax.tick_params(labelsize=24)
# Avoid white lines in the pdf rendering
cbar.solids.set_edgecolor("face")

p.axes().set_aspect('auto')
p.tight_layout()

# Save if save_name has been given
Expand Down
9 changes: 5 additions & 4 deletions Examples/make_distance_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
obs_to_fid_path, comparisons=obs_to_fid_comparisons,
out_path=os.path.join(obs_to_fid_path, "Distance Plots"),
num_fids=5, design_matrix=design_matrix, obs_to_fid=True, legend=False,
obs_legend=True,
statistics=["Cramer", "DeltaVariance", "Dendrogram_Hist",
"Dendrogram_Num", "PCA", "PDF_Hellinger", "SCF", "VCA", "VCS",
"VCS_Density", "VCS_Velocity"])
"Dendrogram_Num", "PCA", "SCF", "VCA", "VCS",
"VCS_Density", "VCS_Velocity", "Skewness", "Kurtosis"])

# Des to Obs

Expand All @@ -61,5 +62,5 @@
num_fids=3, design_matrix=design_matrix,
legend_labels=["Oph A", "IC 348", "NGC 1333"],
statistics=["Cramer", "DeltaVariance", "Dendrogram_Hist",
"Dendrogram_Num", "PCA", "PDF_Hellinger", "SCF", "VCA", "VCS",
"VCS_Density", "VCS_Velocity"])
"Dendrogram_Num", "PCA", "SCF", "VCA", "VCS",
"VCS_Density", "VCS_Velocity", "Skewness", "Kurtosis"])
38 changes: 38 additions & 0 deletions Examples/make_obs_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# Create data tables of the observational results
# Run from Dropbox/AstroStatistics/Full Factorial/Observational Results/

import os
import shutil

from turbustat.analysis.convert_results import concat_convert_HDF5
from turbustat.analysis import convert_format


# Obs to Fids

path = "Obs_to_Fid/"
hdf5_path = "Obs_to_Fid/HDF5/"

convert_format(hdf5_path, 0)
shutil.move(hdf5_path+"complete_distances_face_0.csv", path)

convert_format(hdf5_path, 1)
shutil.move(hdf5_path+"complete_distances_face_1.csv", path)

convert_format(hdf5_path, 2)
shutil.move(hdf5_path+"complete_distances_face_2.csv", path)

# Des to Obs

hdf5_path = "Des_to_Obs/HDF5/"

concat_convert_HDF5(hdf5_path, face=0, interweave=True, average_axis=0)
shutil.move(os.path.join(hdf5_path, "des_0.csv"), "Des_to_Obs")
shutil.move("Des_to_Obs/des_0.csv", "Des_to_Obs/des_0_obs.csv")

concat_convert_HDF5(hdf5_path, face=2, interweave=True, average_axis=0)
shutil.move(os.path.join(hdf5_path, "des_2.csv"), "Des_to_Obs")
shutil.move("Des_to_Obs/des_2.csv", "Des_to_Obs/des_2_obs.csv")

# Make plots using make_distance_plots.py
2 changes: 1 addition & 1 deletion Examples/noise_validation.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
args = commandArgs(TRUE)

startTime = Sys.time()
setwd(args[1])
# setwd(args[1])

FidDes00 = read.csv('distances_0_0.csv', header = T)
FidFid00 = read.csv('fiducials_0_0.csv', header = T)
Expand Down
2 changes: 1 addition & 1 deletion Examples/signal_validation.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
args = commandArgs(TRUE)

startTime = Sys.time()
setwd(args[1])
# setwd(args[1])

FidDes00 = read.csv('distances_0_0.csv', header = T)
FidDes22 = read.csv('distances_2_2.csv', header = T)
Expand Down
13 changes: 7 additions & 6 deletions turbustat/analysis/comparison_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,10 @@ def _plotter(ax, data, fid_data, num_fids, title, stat, bottom, left,
ax.plot(x_vals, y_vals, "-o", label="Fiducial " + str(i),
alpha=0.6)
# Set title in upper left hand corner
ax.annotate(title, xy=(0, 1), xytext=(12, -6), va='top',
xycoords='axes fraction', textcoords='offset points',
fontsize=12, alpha=0.75)
ax.set_title(title, fontsize=12)
# ax.annotate(title, xy=(1, 0), xytext=(0.9, 0.05), va='top',
# xycoords='axes fraction', textcoords='axes fraction',
# fontsize=12, alpha=0.75)
if left:
# Set the ylabel using the stat name. Replace underscores
ax.set_ylabel(stat.replace("_", " ")+"\nDistance", fontsize=10,
Expand Down Expand Up @@ -313,11 +314,11 @@ def _plotter(ax, data, fid_data, num_fids, title, stat, bottom, left,
if legend:
ax.legend(loc="upper right", prop={'size': 10})
if labels is None:
ax.set_xlim([-1, num_design + num_fids + 5])
ax.set_xlim([-1, num_design + num_fids + 8])
ax.set_xticks(np.append(x_vals, x_fid_vals))
ax.set_xticklabels(xtick_labels+fid_labels, rotation=90, size=12)
else:
ax.set_xlim([-2, num_design + num_fids + 5])
ax.set_xlim([-2, num_design + num_fids + 8])
xticks = np.append([-1], np.append(x_vals, x_fid_vals))
ax.set_xticks(xticks)
ax.set_xticklabels(labels+fid_labels, rotation=90, size=12)
Expand All @@ -338,7 +339,7 @@ def _horiz_obs_plot(ax, data, num_fids, shading=False, legend=False):
"ic348.13co.fits": "IC 348"}

# Also needs to be generalized
colors = ["r", "g", "b"]
colors = ["g", "r", "b"]

x_vals = ax.axis()[:2]

Expand Down

0 comments on commit 10c41da

Please sign in to comment.