forked from Raruku/Tidal_Parameter_Mask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDSS_S82_R50_MASK.pl
162 lines (133 loc) · 4.71 KB
/
SDSS_S82_R50_MASK.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
161
162
# Tidal_Parameter_Mask
#Creates Fits files that uses SDSS Petrosian Radius to mask the outer 10xR50 and inter R50 areas.
use strict;
use warnings;
use PGPLOT;
use PDL;
use PDL::Graphics::PGPLOT;
use PDL::Graphics2D;
use PDL::Image2D;
use PDL::IO::FITS;;
use Text::CSV;
use Math::Trig 'pi';
use PDL::IO::Pic;
use PDL::Core;
use PDL::Graphics::IIS;
my $deg2rad = pi/180.;
use PDL::IO::Misc;
use PDL::Transform;
#use Astro::FITS::Header;
#use Astro::FITS::Header::CFITSIO;
$ENV{'PGPLOT_DIR'} = '/usr/local/pgplot';
$ENV{'PGPLOT_DEV'} = '/xs';
open my $SEX, '<', "result_S82.csv" or die "cannot open result_S82.csv: $!"; #open your input file containing all the required input files from SDSS SQL
my $inp = Text::CSV->new({'binary'=>1});
$inp->column_names($inp->getline($SEX));
my $parameter = $inp->getline_hr_all($SEX);
my @nyuID = map {$_->{'col0'}} @{$parameter};
my @A = map {$_->{'R50_r'}} @{$parameter};
my @B = map {$_->{'R50_r'}} @{$parameter};
foreach my $posCount (0 .. scalar @nyuID - 1)
{
print "p${nyuID[$posCount]}_S82.fits\n";
#NEW MASK USING SEXTRACTOR
open my $inPositions, '<', "p${nyuID[$posCount]}_S82.aper.csv" or die "cannot open p${nyuID[$posCount]}_S82.aper.csv: $!";
my $input_positions = Text::CSV->new({'binary'=>1});
$input_positions->column_names($input_positions->getline($inPositions));
my $inputs = $input_positions->getline_hr_all($inPositions);
#Make new varibles using the header (column name) for each column
#We will use this later to call certian values
my @N = map {$_->{'NUMBER'}} @{$inputs};
my @X = map {$_->{'X_IMAGE'}} @{$inputs};
my @Y = map {$_->{'Y_IMAGE'}} @{$inputs};
my @THETA = map {$_->{'THETA_IMAGE'}} @{$inputs};
##Open your image from a list
my $image = rfits("p${nyuID[$posCount]}_S82.fits"); #nyuID
##Display a image using the perl
#my $normal = PDL::Graphics2D->new('PGPLOT', {'device' => '/xs'});
## min, max
#$normal->fits_imag($image,1000,2000);
#Acquiring the dimensions in an image
my @dim = dims($image);
print join(',',@dim),"\n";
#join(',',@dim)
my $size_x = $dim[0];
my $size_y = $dim[1];
print "This image is $size_x x $size_y pixels";
print "\n";
#Naming varibles for stuff
my $e; #eccentricity
my $nx_pix;
my $ny_pix;
my $r_a;
my $r_b;
my $r_10a;
my $r_10b;
my $THETA;
my $K;
#-------------------
#Making a fake image for GALFIT and for visual confirmation
#-----------------
my $x = xvals(float(),$size_x,$size_y)+1;
my $y = yvals(float(),$size_x,$size_y)+1;
my $ellipse = zeroes($size_x,$size_y);
my $ellipse_2 = ones($size_x,$size_y);
my $ellipse_3 = zeroes($size_x,$size_y);
my $ellipse_4 = ones($size_x,$size_y);
foreach my $Count (0 .. scalar @N - 1)
{
if ($X[$Count] >= ($size_x/2 - 5) && $Y[$Count] >= ($size_y/2 - 5) && $Y[$Count] <= ($size_y/2 + 5) ##If statement to find the main galaxy in the center of the image
&& $X[$Count] <= ($size_x/2 + 5) && $Y[$Count] >= ($size_y/2 - 5) && $Y[$Count] <= ($size_y/2 + 5) )
{
$e = (1-((($B[$Count])**2)/(($A[$Count])**2)))**.5;
$nx_pix = $X[$Count];
$ny_pix = $Y[$Count];
$THETA = $deg2rad * -$THETA[$Count];
$K=1;
$r_a = $K*$A[$posCount];
$r_b = $K*$B[$posCount];
$r_10a = 10*$K*$A[$posCount];
$r_10b = 10*$K*$B[$posCount];
my $new_x = $x - $nx_pix;
my $new_y = $y - $ny_pix;
my $r_x = $new_x * cos(($THETA)) - $new_y * sin(($THETA));
my $r_y = $new_x * sin(($THETA)) + $new_y * cos(($THETA));
my $tmp = ($new_x /$r_a)**2 + ($new_y /$r_a)**2;
$tmp->where($tmp<=1) .= 1;
$tmp->where($tmp>1) .= 0;
$ellipse |= $tmp;
my $tmp_2 = ($new_x /$r_a)**2 + ($new_y /$r_a)**2;
$tmp_2->where($tmp_2<=1) .= 0;
$tmp_2->where($tmp_2>1) .= 1;
$ellipse_2 &= $tmp_2;
#10xSDSS Re
my $tmp_3 = ($new_x /$r_10a)**2 + ($new_y /$r_10a)**2;
$tmp_3->where($tmp_3<=1) .= 1;
$tmp_3->where($tmp_3>1) .= 0;
$ellipse_3 |= $tmp_3;
my $tmp_4 = ($new_x /$r_10a)**2 + ($new_y /$r_10a)**2;
$tmp_4->where($tmp_4<=1) .= 0;
$tmp_4->where($tmp_4>1) .= 1;
$ellipse_4 &= $tmp_4;
}
}
$ellipse->sethdr($image->hdr);
$ellipse->wfits("R50.${nyuID[$posCount]}_S82_1a.fits");
$ellipse_2->sethdr($image->hdr);
$ellipse_2->wfits("R50.${nyuID[$posCount]}_S82_1b.fits");
#10xRe
$ellipse_3->sethdr($image->hdr);
$ellipse_3->wfits("10R50.${nyuID[$posCount]}_S82_1a.fits");
$ellipse_4->sethdr($image->hdr);
$ellipse_4->wfits("10R50.${nyuID[$posCount]}_S82_1b.fits");
my $Mimage = $ellipse_2 * $ellipse_3;
$Mimage-> wfits("R50_Mask.p${nyuID[$posCount]}_S82.fits"); #make nyuID R50 mask
#R50 mask x Segmentation mask
my $Seg_image = rfits("p${nyuID[$posCount]}_S82.mask_1b.fits"); # SEG_Object Mask
#Full mask
my $Full_Mask = $Seg_image * $Mimage;
$Full_Mask-> wfits("Full_Mask.p${nyuID[$posCount]}_S82.fits");
#my $mask_image = PDL::Graphics2D->new('PGPLOT', {'device' => '/xs'});
#$mask_image->fits_imag($Mimage,0,1);
}
print "Finished\n";