<commit_before># -*- coding: utf-8 -*-
"""
Created on Thu Dec 11 11:37:39 2014

@author: sm1fg

    Construct the magnetic network and generate the adjustments to the
    non-magnetic atmosphere for mhs equilibrium.

"""
import numpy as np
import astropy.units as u
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from scipy.interpolate import RectBivariateSpline

#============================================================================
# locate flux tubes and footpoint strength
#============================================================================
def get_flux_tubes(
                   model_pars,
                   coords,
                   option_pars
                  ):
    """ Obtain an array of x,y coordinates and corresponding vertical
    component value for the photospheric magnetic field  """

    xi, yi, Si = [[0.]]*u.Mm,  [[0.]]*u.Mm,  [[0.1]]*u.T  # x,y,Bz(r=0,z=0)

    # parameters for matching Mumford,Fedun,Erdelyi 2014
    if option_pars['l_mfe']:
        Si = [[0.13]]*u.T # 150mT SI units
    # parameters for matching Gent,Fedun,Mumford,Erdelyi 2014
    elif option_pars['l_single']:
        Si = [[0.1]]*u.T # 100mT SI units
    # parameters for matching Gent,Fedun,Erdelyi 2014 flux tube pair
    elif option_pars['l_tube_pair']:
        xi, yi, Si = (
                      u.Quantity([
                                [  1.0],
                                [  1.0],
                                [-0.95],
                                [-1.05]
                               ], unit=u.Mm),
                      u.Quantity([
                                [ 0.00],
                                [ 0.00],
                                [  .15],
                                [-0.15]
                               ], unit=u.Mm),
                      u.Quantity([
                                [  50e-3],
                                [  50e-3],
                                [  50e-3],
                                [  50e-3]
                               ], unit=u.T)
                     )# 50mT SI
    # parameters for matching Gent,Fedun,Erdelyi 2014 twisted flux tubes
    elif option_pars['l_multi_twist']:
        xi, yi, Si = (
                      u.Quantity([
                                [ 0.34],
                                [ 0.07],
                                [  .14],
                                [-0.31]
                               ], unit=u.Mm),
                      u.Quantity([
                                [ 0.20],
                                [ 0.33],
                                [ 0.04],
                                [-0.34]
                               ], unit=u.Mm),
                      u.Quantity([
                                [  50e-3],
                                [  50e-3],
                                [  50e-3],
                                [  50e-3]
                               ], unit=u.T)
                     )# 50mT SI
    elif option_pars['l_multi_netwk']:
        xi, yi, Si = (
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.5/model_pars['nftubes']]] * model_pars['nftubes'], 
                       unit=u.T),                       
            )
        x1 = [-1.75, -0.75, 1.25,  1.00, -0.75]
        y1 = [-1.00,  0.50, 0.50, -1.50,  1.70]
        xi[  : 3] += x1[0] * u.Mm
        xi[3 : 6] += x1[1] * u.Mm
        xi[6 : 9] += x1[2] * u.Mm
        xi[9 :12] += x1[3] * u.Mm
        xi[12:15] += x1[4] * u.Mm
        yi[  : 3] += y1[0] * u.Mm
        yi[3 : 6] += y1[1] * u.Mm
        yi[6 : 9] += y1[2] * u.Mm
        yi[9 :12] += y1[3] * u.Mm
        yi[12:15] += y1[4] * u.Mm
        for xj in xi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
        for xj in yi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
    elif option_pars['l_multi_lanes']:
        xi, yi, Si = (
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.54/model_pars['nftubes']]] * model_pars['nftubes'], 
                       unit=u.T),                       
            )
        x1 = [-1.875, -1.125, -0.375, 0.375,  1.125, 1.875]
        xi[  : 3] += x1[0] * u.Mm
        xi[3 : 6] += x1[1] * u.Mm
        xi[6 : 9] += x1[2] * u.Mm
        xi[9 :12] += x1[3] * u.Mm
        xi[12:15] += x1[4] * u.Mm
        xi[16:18] += x1[5] * u.Mm
        for xj in xi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
        for xj in yi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
    else:
        raise ValueError("in get_flux_tubes axial parameters need to be defined")

    return xi, yi, Si

#-----------------------------------------------------------------------------
#
def get_hmi_flux_tubes(
                model_pars, option_pars,
                indx, 
                dataset = 'hmi_m_45s_2014_07_06_00_00_45_tai_magnetogram_fits', 
                sunpydir = os.path.expanduser('~/sunpy/data/'),
                savedir = os.path.expanduser('~/figs/hmi/'),
                l_newdata = False
               ):
    """ indx is 4 integers: lower and upper indices each of x,y coordinates 
#    dataset of the form 'hmi_m_45s_2014_07_06_00_00_45_tai_magnetogram_fits'
#    """
    from sunpy.net import vso
    import sunpy.map
    client = vso.VSOClient()
    results = client.query(vso.attrs.Time("2014/07/05 23:59:50",
                                          "2014/07/05 23:59:55"), 
                           vso.attrs.Instrument('HMI'),
                           vso.attrs.Physobs('LOS_magnetic_field'))
    #print results.show()                       

    if l_newdata:
        if not os.path.exits(sunpydir):
            raise ValueError("in get_hmi_map set 'sunpy' dir for vso data\n"+ 
        "for large files you may want link to local drive rather than network")<commit_msg>Set flux tube parameters for paper2d, working on hmi<commit_after># -*- coding: utf-8 -*-
"""
Created on Thu Dec 11 11:37:39 2014

@author: sm1fg

    Construct the magnetic network and generate the adjustments to the
    non-magnetic atmosphere for mhs equilibrium.

"""
import numpy as np
import astropy.units as u
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from scipy.interpolate import RectBivariateSpline

#============================================================================
# locate flux tubes and footpoint strength
#============================================================================
def get_flux_tubes(
                   model_pars,
                   coords,
                   option_pars
                  ):
    """ Obtain an array of x,y coordinates and corresponding vertical
    component value for the photospheric magnetic field  """

    xi, yi, Si = [[0.]]*u.Mm,  [[0.]]*u.Mm,  [[0.1]]*u.T  # x,y,Bz(r=0,z=0)

    # parameters for matching Mumford,Fedun,Erdelyi 2014
    if option_pars['l_mfe']:
        Si = [[0.13]]*u.T # 150mT SI units
    # parameters for matching Gent,Fedun,Mumford,Erdelyi 2014
    elif option_pars['l_single']:
        Si = [[0.1]]*u.T # 100mT SI units
    # parameters for matching Gent,Fedun,Erdelyi 2014 flux tube pair
    elif option_pars['l_tube_pair']:
        xi, yi, Si = (
                      u.Quantity([
                                [  1.0],
                                [  1.0],
                                [-0.95],
                                [-1.05]
                               ], unit=u.Mm),
                      u.Quantity([
                                [ 0.00],
                                [ 0.00],
                                [  .15],
                                [-0.15]
                               ], unit=u.Mm),
                      u.Quantity([
                                [  50e-3],
                                [  50e-3],
                                [  50e-3],
                                [  50e-3]
                               ], unit=u.T)
                     )# 50mT SI
    # parameters for matching Gent,Fedun,Erdelyi 2014 twisted flux tubes
    elif option_pars['l_multi_twist']:
        xi, yi, Si = (
                      u.Quantity([
                                [ 0.34],
                                [ 0.07],
                                [  .14],
                                [-0.31]
                               ], unit=u.Mm),
                      u.Quantity([
                                [ 0.20],
                                [ 0.33],
                                [ 0.04],
                                [-0.34]
                               ], unit=u.Mm),
                      u.Quantity([
                                [  50e-3],
                                [  50e-3],
                                [  50e-3],
                                [  50e-3]
                               ], unit=u.T)
                     )# 50mT SI
    elif option_pars['l_multi_netwk']:
        xi, yi, Si = (
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.5/model_pars['nftubes']]] * model_pars['nftubes'], 
                       unit=u.T),                       
            )
        x1 = [-1.75, -0.75, 1.25,  1.00, -0.75]
        y1 = [-1.00,  0.50, 0.50, -1.50,  1.70]
        xi[  : 3] += x1[0] * u.Mm
        xi[3 : 6] += x1[1] * u.Mm
        xi[6 : 9] += x1[2] * u.Mm
        xi[9 :12] += x1[3] * u.Mm
        xi[12:15] += x1[4] * u.Mm
        yi[  : 3] += y1[0] * u.Mm
        yi[3 : 6] += y1[1] * u.Mm
        yi[6 : 9] += y1[2] * u.Mm
        yi[9 :12] += y1[3] * u.Mm
        yi[12:15] += y1[4] * u.Mm
        for xj in xi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
        for xj in yi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
    elif option_pars['l_multi_lanes']:
        xi, yi, Si = (
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.]] * model_pars['nftubes'], unit=u.Mm),
            u.Quantity([
                       [0.475/model_pars['nftubes']]] * model_pars['nftubes'], 
                       unit=u.T),                       
            )
        x1 = [-2., -1.2, -0.4, 0.4,  1.2, 2.]
        xi[  : 3] += x1[0] * u.Mm
        xi[3 : 6] += x1[1] * u.Mm
        xi[6 : 9] += x1[2] * u.Mm
        xi[9 :12] += x1[3] * u.Mm
        xi[12:15] += x1[4] * u.Mm
        xi[16:18] += x1[5] * u.Mm
        for xj in xi:
            xj += np.random.uniform(-0.5,0.5) * u.Mm
        for xj in yi:
            xj += np.random.uniform(-0.25,0.25) * u.Mm
    else:
        raise ValueError("in get_flux_tubes axial parameters need to be defined")

    return xi, yi, Si

#-----------------------------------------------------------------------------
#
def get_hmi_flux_tubes(
                model_pars, option_pars,
                indx, 
                dataset = 'hmi_m_45s_2014_07_06_00_00_45_tai_magnetogram_fits', 
                sunpydir = os.path.expanduser('~/sunpy/data/'),
                savedir = os.path.expanduser('~/figs/hmi/'),
                l_newdata = False
               ):
    """ indx is 4 integers: lower and upper indices each of x,y coordinates 
#    dataset of the form 'hmi_m_45s_2014_07_06_00_00_45_tai_magnetogram_fits'
#    """
    from sunpy.net import vso
    import sunpy.map
    client = vso.VSOClient()
    results = client.query(vso.attrs.Time("2014/07/05 23:59:50",
                                          "2014/07/05 23:59:55"), 
                           vso.attrs.Instrument('HMI'),
                           vso.attrs.Physobs('LOS_magnetic_field'))
    #print results.show()                       

    if l_newdata:
        if not os.path.exits(sunpydir):
            raise ValueError("in get_hmi_map set 'sunpy' dir for vso data\n"+ 
        "for large files you may want link to local drive rather than network")
{'fraction_non_alphanumeric': 0.16273241713823766, 'fraction_numerical': 0.05319320937752627, 'mean_word_length': 1.0594306642250708, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '967865', 'n_tokens_mistral': 4418, 'n_tokens_neox': 3800, 'n_words': 819}