<commit_before># Licensed under an MIT open source license - see LICENSE

'''
Make histogram of surface brightness along the filaments.
'''

from astropy.io.fits import getdata, getheader
from astropy import convolution
from astropy.table import Table
from scipy.ndimage import distance_transform_edt
import os
import sys
import numpy as np
import matplotlib.pyplot as p
from pandas import DataFrame, Series


# Inputs
med_sb_plot = sys.argv[1]
if med_sb_plot == "T":
    med_sb_plot = True
else:
    med_sb_plot = False

mline_plot = sys.argv[2]
if mline_plot == "T":
    mline_plot = True
else:
    mline_plot = False

sfr_plot = sys.argv[3]
if sfr_plot == "T":
    sfr_plot = True
else:
    sfr_plot = False

sb_bkg_ratio = sys.argv[4]
if sb_bkg_ratio == "T":
    sb_bkg_ratio = True
else:
    sb_bkg_ratio = False

if med_sb_plot or mline_plot:
    import seaborn as sn
    sn.set_context('talk')
    sn.set_style("darkgrid")

folders = [f for f in os.listdir("degrade_all") if os.path.isdir(f) and
           f[-3:] == '350']

dists = {"pipeCenterB59-350": 145.,
         "polaris-350": 150.,
         "ic5146-350": 460.,
         "orionA-S-350": 400.,
         "lupusI-350": 150.,
         "orionB-350": 400.,
         "taurusN3-350": 140.,
         "aquilaM2-350": 260.,
         "orionA-C-350": 400.,
         "perseus04-350": 235.,
         "california_cntr-350": 450.,
         "california_east-350": 450.,
         "california_west-350": 450.,
         "chamaeleonI-350": 170.}

labels = {"pipeCenterB59-350": "Pipe",
          "polaris-350": "Polaris",
          "ic5146-350": "IC-5146",
          "orionA-S-350": "Orion-A South",
          "lupusI-350": "Lupus",
          "orionB-350": "Orion-B",
          "taurusN3-350": "Taurus",
          "aquilaM2-350": "Aquila",
          "orionA-C-350": "Orion-A Center",
          "perseus04-350": "Perseus",
          "california_cntr-350": "California Center",
          "california_east-350": "California East",
          "california_west-350": "California West",
          "chamaeleonI-350": "Chamaeleon"}

offsets = {"pipeCenterB59-350": 31.697,
           "polaris-350": 9.330,
           "ic5146-350": 20.728,
           "orionA-S-350": 35.219,
           "lupusI-350": 14.437,
           "orionB-350": 26.216,
           "taurusN3-350": 21.273,
           "aquilaM2-350": 85.452,
           "orionA-C-350": 32.616,
           "perseus04-350": 23.698,
           "california_cntr-350": 9.005,
           "california_east-350": 10.124,
           "california_west-350": 14.678,
           "chamaeleonI-350": -879.063}


def Mlin(I, del_x):
    return 1.234567 * I * del_x

all_points = []

mlin_points = []

ratios = {}

for num, fol in enumerate(folders):
    values = np.empty((0))
    per_fil_values = np.empty((0))
    reg_ratios = []

    # Open the skeleton and the image
    skeleton = getdata("degrade_all/"+fol+"/"+fol+"_skeletons.fits")

    data = Table.read("degrade_all/"+fol+"/"+fol+"_table.fits")
    # skeleton[skeleton > 1] = 1

    img = getdata(fol+".fits") + offsets[fol]
    hdr = getheader(fol+".fits")

    pix_size = np.abs(hdr['CDELT2']) * (np.pi/180.) * dists[fol]  # pc

    r = 460. / dists[fol]
    if r != 1.:
        conv = np.sqrt(r ** 2. - 1) * \
            (24.9 / np.sqrt(8*np.log(2)) / (np.abs(hdr["CDELT2"]) * 3600.))
        if conv > 1.0:
            kernel = convolution.Gaussian2DKernel(conv)
            img = convolution.convolve(img, kernel, boundary='fill',
                                       fill_value=np.NaN)

            pix_size = pix_size * r

    for lab in np.unique(skeleton[np.nonzero(skeleton)]):

        bkg = data['Background'][lab-1]

        if np.isnan(bkg):
            continue

        width = data['FWHM'][lab-1]
        pix_width = width / pix_size

        if med_sb_plot or sfr_plot:
            skel_pts = np.where(skeleton == lab)
            points = img[skel_pts] - bkg<commit_msg>Generalize to run in specific results folder<commit_after># Licensed under an MIT open source license - see LICENSE

'''
Make histogram of surface brightness along the filaments.
'''

from astropy.io.fits import getdata, getheader
from astropy import convolution
from astropy.table import Table
from scipy.ndimage import distance_transform_edt
import os
import sys
import numpy as np
import matplotlib.pyplot as p
from pandas import DataFrame, Series


# Inputs
med_sb_plot = sys.argv[1]
if med_sb_plot == "T":
    med_sb_plot = True
else:
    med_sb_plot = False

mline_plot = sys.argv[2]
if mline_plot == "T":
    mline_plot = True
else:
    mline_plot = False

sfr_plot = sys.argv[3]
if sfr_plot == "T":
    sfr_plot = True
else:
    sfr_plot = False

sb_bkg_ratio = sys.argv[4]
if sb_bkg_ratio == "T":
    sb_bkg_ratio = True
else:
    sb_bkg_ratio = False

if med_sb_plot or mline_plot:
    import seaborn as sn
    sn.set_context('talk')
    sn.set_style("darkgrid")

folders = [f for f in os.listdir(".") if os.path.isdir(f) and
           f[-3:] == '350']

dists = {"pipeCenterB59-350": 145.,
         "polaris-350": 150.,
         "ic5146-350": 460.,
         "orionA-S-350": 400.,
         "lupusI-350": 150.,
         "orionB-350": 400.,
         "taurusN3-350": 140.,
         "aquilaM2-350": 260.,
         "orionA-C-350": 400.,
         "perseus04-350": 235.,
         "california_cntr-350": 450.,
         "california_east-350": 450.,
         "california_west-350": 450.,
         "chamaeleonI-350": 170.}

labels = {"pipeCenterB59-350": "Pipe",
          "polaris-350": "Polaris",
          "ic5146-350": "IC-5146",
          "orionA-S-350": "Orion-A South",
          "lupusI-350": "Lupus",
          "orionB-350": "Orion-B",
          "taurusN3-350": "Taurus",
          "aquilaM2-350": "Aquila",
          "orionA-C-350": "Orion-A Center",
          "perseus04-350": "Perseus",
          "california_cntr-350": "California Center",
          "california_east-350": "California East",
          "california_west-350": "California West",
          "chamaeleonI-350": "Chamaeleon"}

offsets = {"pipeCenterB59-350": 31.697,
           "polaris-350": 9.330,
           "ic5146-350": 20.728,
           "orionA-S-350": 35.219,
           "lupusI-350": 14.437,
           "orionB-350": 26.216,
           "taurusN3-350": 21.273,
           "aquilaM2-350": 85.452,
           "orionA-C-350": 32.616,
           "perseus04-350": 23.698,
           "california_cntr-350": 9.005,
           "california_east-350": 10.124,
           "california_west-350": 14.678,
           "chamaeleonI-350": -879.063}


def Mlin(I, del_x):
    return 1.234567 * I * del_x

all_points = []

mlin_points = []

ratios = {}

for num, fol in enumerate(folders):
    values = np.empty((0))
    per_fil_values = np.empty((0))
    reg_ratios = []

    # Open the skeleton and the image
    skeleton = getdata(fol+"/"+fol+"_skeletons.fits")

    data = Table.read(fol+"/"+fol+"_table.fits")
    # skeleton[skeleton > 1] = 1

    img = getdata("../"+fol+".fits") + offsets[fol]
    hdr = getheader("../"+fol+".fits")

    pix_size = np.abs(hdr['CDELT2']) * (np.pi/180.) * dists[fol]  # pc

    r = 460. / dists[fol]
    if r != 1.:
        conv = np.sqrt(r ** 2. - 1) * \
            (24.9 / np.sqrt(8*np.log(2)) / (np.abs(hdr["CDELT2"]) * 3600.))
        if conv > 1.0:
            kernel = convolution.Gaussian2DKernel(conv)
            img = convolution.convolve(img, kernel, boundary='fill',
                                       fill_value=np.NaN)

            pix_size = pix_size * r

    for lab in np.unique(skeleton[np.nonzero(skeleton)]):

        bkg = data['Background'][lab-1]

        if np.isnan(bkg):
            continue

        width = data['FWHM'][lab-1]
        pix_width = width / pix_size

        if med_sb_plot or sfr_plot:
            skel_pts = np.where(skeleton == lab)
            points = img[skel_pts] - bkg
{'fraction_non_alphanumeric': 0.15258126195028682, 'fraction_numerical': 0.08030592734225621, 'mean_word_length': 2.192026037428804, 'pattern_counts': {'":': 92, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6735', 'n_tokens_mistral': 3390, 'n_tokens_neox': 2863, 'n_words': 605}