transform_BuDS_or_BDBS_GalfitFile |
beanshell |
it reads galfit configuration file if its components are: disk, bulb, bar and sky or disk, bulb and sky. Scriptimport java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
resultTable = "x_disk,y_disk,Mag_disk,hR_disk,ba_disk,PA_disk,x_bul,y_bul,Mag_bul," +
"re_bul,n_bul,ba_bul,PA_bul,x_bar,y_bar,Mag_bar,re_bar,n_bar,ba_bar,PA_bar\n";
if(galfitFileContent.length() > 0 ){
String x="",y="",mag="",hR="",ba="",pa="",re="",n="";
String [] components = galfitFileContent.split("# Component number:");
//System.out.println("Iteration");
//System.out.println("number of elements: "+components.length);
//System.out.println("---- Component 1:\n"+components[1]);
String number = "([-0123456789.]+)";
//Take data from component 1
String expression = ".*1"+Pattern.quote(")")+"\\s+"+number+"\\s+"+number+".*"; // Position x, y
expression += ".*3"+Pattern.quote(")")+"\\s+"+number+".*"; // Integrated magnitude
expression += ".*4"+Pattern.quote(")")+"\\s+"+number+".*"; // R_s (disk scale-length) [pix]
expression += ".*5"+Pattern.quote(")")+"\\s+"+number+".*"; // sersic index n
//expression += "[.\\s]+";
expression += ".*9"+Pattern.quote(")")+"\\s+"+number+".*"; // Axis ratio (b/a)
expression += ".*10"+Pattern.quote(")")+"\\s+"+number+".*"; // Position angle
Pattern pattern1 = Pattern.compile(expression, Pattern.DOTALL);
//http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html
//array for a row
//Float [] values = new Float[20];
Matcher matcher1 = pattern1.matcher(components[1]);
//expdisk disk
while (matcher1.find()) {
x = matcher1.group(1);
y = matcher1.group(2);
mag = matcher1.group(3);
hR = matcher1.group(4);
ba = matcher1.group(6);
pa = matcher1.group(7);
resultTable += x + "," + y + "," + mag + "," + hR + "," + ba + "," + pa + ",";
//values[0] = Float.valueOf(x);
//values[1] = Float.valueOf(y);
//values[2] = Float.valueOf(mag);
//values[3] = Float.valueOf(hR);
//values[4] = Float.valueOf(ba);
//values[5] = Float.valueOf(pa);
}
matcher1 = pattern1.matcher(components[2]);
//sersic bulbo
while (matcher1.find()) {
x = matcher1.group(1);
y = matcher1.group(2);
mag = matcher1.group(3);
re = matcher1.group(4);
n = matcher1.group(4);
ba = matcher1.group(6);
pa = matcher1.group(7);
resultTable += x + "," + y + "," + mag + "," + re + "," + n + "," + ba + "," + pa + ",";
//values[6] = Float.valueOf(x);
//values[7] = Float.valueOf(y);
//values[8] = Float.valueOf(mag);
//values[9] = Float.valueOf(re);
//values[10] = Float.valueOf(n);
//values[11] = Float.valueOf(ba);
//values[12] = Float.valueOf(pa);
}
System.out.println("Components: "+components.length);
if(components.length == 5){
//sersic bar
matcher1 = pattern1.matcher(components[3]);
while (matcher1.find()) {
x = matcher1.group(1);
y = matcher1.group(2);
mag = matcher1.group(3);
re = matcher1.group(4);
n = matcher1.group(4);
ba = matcher1.group(6);
pa = matcher1.group(7);
resultTable += x + "," + y + "," + mag + "," + re + "," + n + "," + ba + "," + pa + "\n";
//values[13] = Float.valueOf(x);
//values[14] = Float.valueOf(y);
//values[15] = Float.valueOf(mag);
//values[16] = Float.valueOf(re);
//values[17] = Float.valueOf(n);
//values[18] = Float.valueOf(ba);
//values[19] = Float.valueOf(pa);
System.out.println(x+"-"+y);
}
}else{
x="-999.0000";y="-999.0000";mag="-99.0";ba="-99.0";pa="-99.0";re="-99.0";n="-99.0";
resultTable += x + "," + y + "," + mag + "," + re + "," + n + "," + ba + "," + pa + "\n";
}
}else{
resultTable += "-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-999.0000,-99.0,-99.0,-99.0,-99.0,-99.0";
} |
Comments (0)
No comments yet
Log in to make a comment