forked from Raruku/Tidal_Parameter_Mask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GALFIT_OUTPUT_READER.pl
executable file
·160 lines (117 loc) · 4.83 KB
/
GALFIT_OUTPUT_READER.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#! /usr/bin/perl
use strict;
use warnings;
use PDL;
use Text::CSV;
my @galaxy_fits = qw/1 2 4 a 14 aa/;
my @DataRelease = qw/DR7 S82/;
foreach my $DataRelease (@DataRelease) {
open my $inPositions, '<', "result_$DataRelease.csv" or die "cannot open result_$DataRelease.csv: $!";
my $input_positions = Text::CSV->new({'binary'=>1});
$input_positions->column_names($input_positions->getline($inPositions));
my $position_inputs = $input_positions->getline_hr_all($inPositions);
my @nyuID = map {$_->{'col0'}} @{$position_inputs};
foreach my $posCount (0 .. scalar @nyuID - 1) {
foreach my $galaxy_fits (@galaxy_fits) {
my $file = "p${nyuID[$posCount]}_$DataRelease.galfit_$galaxy_fits.out";
if (-e "$file") {
open my $fdIn, '<', $file or die "Unable to open $file: $!\n";
open my $fdOut, '>', "p${nyuID[$posCount]}_$DataRelease.galfit_$galaxy_fits.csv" or die "Unable to p${nyuID[$posCount]}_$DataRelease.galfit_$galaxy_fits.csv: $!\n";
print $fdOut "type,x,y,posFlag1,posFlag2,Mag,mag_Flag,Re,Re_Flag,sersicIndex,seric_Flag,axisRatio,ar_Flag,PosAng,pa_Flag,skipImage_Flag,Fit_Type\n";
while(1) {
# skip all lines until you reach the component listing
while(defined($_ = <$fdIn>) && $_ !~ /^# Component number:/){}
last if eof $fdIn;
<$fdIn> =~ /\)\s+?(\w+)\s+#/;
my $type = $1;
if($type eq 'sersic') {
&readSersicFit($fdIn,$fdOut);
} elsif ($type eq 'expdisk') {
&readDiskFit($fdIn,$fdOut);
} elsif ($type eq 'psf') {
&psf($fdIn,$fdOut);
} elsif ($type eq 'sky') {
&readSkyFit($fdIn,$fdOut);
} else {
print "Unknown component type: $type\n";
}
last if eof $fdIn;
}
}
sub readDiskFit(){
my ($fdIn,$fdOut) = @_;
<$fdIn> =~ /\)\s+(.*)#/;
my ($ra,$dec,$posFlag1,$posFlag2) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($integratedMag, $imFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($Re, $reFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($sersicIndex,$siFlag) = split(' ', $1);
# skip the next three lines
<$fdIn>;<$fdIn>;<$fdIn>;
<$fdIn> =~ /\)\s+(.*)#/;
my ($axisRatio,$arFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($posAng,$paFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($skipImageFlag) = split(' ', $1);
print $fdOut
join(',','expdisk',$ra,$dec,$posFlag1,$posFlag2,$integratedMag,$imFlag,$Re,$reFlag,$sersicIndex,$siFlag,$axisRatio,$arFlag,$posAng,$paFlag,$skipImageFlag),"\n";
}
sub psf(){
my ($fdIn,$fdOut) = @_;
<$fdIn> =~ /\)\s+(.*)#/;
my ($ra,$dec,$posFlag1,$posFlag2) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($integratedMag, $imFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($Re, $reFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($sersicIndex,$siFlag) = split(' ', $1);
# skip the next three lines
<$fdIn>;<$fdIn>;<$fdIn>;
<$fdIn> =~ /\)\s+(.*)#/;
my ($axisRatio,$arFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($posAng,$paFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($skipImageFlag) = split(' ', $1);
print $fdOut join(',','psf',$ra,$dec,$posFlag1,$posFlag2,$integratedMag,$imFlag,$Re,$reFlag,$sersicIndex,$siFlag,$axisRatio,$arFlag,$posAng,$paFlag,$skipImageFlag),"\n";
}
sub readSkyFit(){
my ($fdIn,$fdOut) = @_;
<$fdIn> =~ /\)\s+(.*)#/;
my ($bg,$bgFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($dSkyX, $dSkyXflag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($dSkyY, $dSkyYflag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($skipImageFlag) = split(' ', $1);
print $fdOut join(',','sky',$dSkyX,$dSkyY,$dSkyXflag,$dSkyYflag,$bg,$bgFlag,'0','0','0','0','0','0','0','0',$skipImageFlag),"\n";
}
#type,ra,dec,posFlag1,posFlag2,Mag,mag_Flag,Re,Re_Flag,sersicIndex,seric_Flag,axisRatio,ar_Flag,PosAng,pa_Flag,skipImage_Flag
sub readSersicFit(){
my ($fdIn,$fdOut) = @_;
<$fdIn> =~ /\)\s+(.*)#/;
my ($ra,$dec,$posFlag1,$posFlag2) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($integratedMag, $imFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($Re, $reFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($sersicIndex,$siFlag) = split(' ', $1);
# skip the next three lines
<$fdIn>;<$fdIn>;<$fdIn>;
<$fdIn> =~ /\)\s+(.*)#/;
my ($axisRatio,$arFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($posAng,$paFlag) = split(' ', $1);
<$fdIn> =~ /\)\s+(.*)#/;
my ($skipImageFlag) = split(' ', $1);
print $fdOut join(',','sersic',$ra,$dec,$posFlag1,$posFlag2,$integratedMag,$imFlag,$Re,$reFlag,$sersicIndex,$siFlag,$axisRatio,$arFlag,$posAng,$paFlag,$skipImageFlag),"\n";
}
}
}
}