<commit_before># -*- coding: utf-8 -*-
"""
Created on Sun Feb 15 22:05:21 2015

@author: jensv
"""

import equil_solver as es
import newcomb_simple as new
import numpy as np
from copy import deepcopy
from datetime import datetime
import os
import json
import sys
sys.path.append('../../provenance_scripts/')
import call_provenance as cp
import sqlite3


def scan_lambda_k_space(lambda_a_space, k_a_space,
                        xi_factor=1., magnetic_potential_energy_ratio=1.,
                        offset=1E-3, r_0=0., init_value=(0.0, 1.0),
                        rtol=None, max_step=1E-2,
                        nsteps=1000, method='lsoda', suppress_output=True,
                        diagnose=False, stiff=False, use_jac=True,
                        **kwargs):
    r"""
    Scans space given by lambda_a_space and k_a_space for m=0, 1 stability and
    saves several 2D numpy arrays (stability maps) to an npz file.
    """
    call_parameters = locals()
    func_name = 'scan_lambda_k_space'

    sing_search_points = 1000
    suydam_end_offset = offset

    k_a_points = np.linspace(k_a_space[0], k_a_space[1], num=k_a_space[2])
    lambda_a_points = np.linspace(lambda_a_space[0], lambda_a_space[1],
                                  num=lambda_a_space[2])

    lambda_a_mesh, k_a_mesh = np.meshgrid(lambda_a_points, k_a_points)

    mesh_shape = lambda_a_mesh.shape

    delta_map = {-1: np.zeros(mesh_shape),
                 0: np.zeros(mesh_shape)}

    sub_stability_maps = {-1: np.ones(mesh_shape),
                          0: np.ones(mesh_shape)}

    stability_maps = {'external': deepcopy(sub_stability_maps),
                      'd_w': deepcopy(sub_stability_maps),
                      'd_w_norm': deepcopy(sub_stability_maps),
                      'suydam': deepcopy(sub_stability_maps)}

    for i, lambda_a in enumerate(lambda_a_points):
        print('lambda_bar:', lambda_a)
        for j, k_a in enumerate(k_a_points):
            for m in [-1, 0]:
                profile = es.UnitlessSmoothedCoreSkin(k_bar=k_a,
                                                      lambda_bar=lambda_a,
                                                      **kwargs)


                params = {'k': k_a, 'm': float(m), 'r_0': r_0, 'a': 1.,
                          'b': 'infinity'}
                params_wo_splines = deepcopy(params)
                params.update(profile.get_tck_splines())
                params.update({'xi_factor': xi_factor,
                               'magnetic_potential_energy_ratio': magnetic_potential_energy_ratio,
                               'beta_0': profile.beta_0(),
                               'core_radius': profile.core_radius,
                               'transition_width': profile.transition_width,
                               'skin_width': profile.skin_width,
                               'points_core': profile.points_core,
                               'points_transition': profile.points_transition,
                               'points_skin': profile.points_skin,
                               'epsilon': profile.epsilon})
                results = new.stability(params, offset, suydam_end_offset,
                                        sing_search_points=sing_search_points,
                                        suppress_output=suppress_output,
                                        xi_given=init_value,
                                        rtol=rtol, max_step=max_step,
                                        nsteps=nsteps, method=method,
                                        diagnose=diagnose, stiff=stiff,
                                        use_jac=use_jac)
                stable_external = results[0]
                stable_suydam = results[1]
                delta_w = results[2]
                xi = results[4]
                xi_der = results[5]

                delta = xi_der[-1] / xi[-1]

                delta_map[m][j][i] = delta

                if delta_w is not None:
                    stability_maps['d_w'][m][j][i] = delta_w
                    stability_maps['d_w_norm'][m][j][i] = delta_w
                else:
                    stability_maps['d_w'][m][j][i] = np.nan
                    stability_maps['d_w_norm'][m][j][i] = np.nan

                if not stable_external:
                    stability_maps['external'][m][j][i] = 0.
                if stable_external and delta_w is None:
                    stability_maps['external'][m][j][i] = -1.
                if not stable_suydam:
                    stability_maps['suydam'][m][j][i] = 0.<commit_msg>Improve fomatting print statement, add adaptive step flag.<commit_after># -*- coding: utf-8 -*-
"""
Created on Sun Feb 15 22:05:21 2015

@author: jensv
"""

import equil_solver as es
import newcomb_simple as new
import numpy as np
from copy import deepcopy
from datetime import datetime
import os
import json
import sys
sys.path.append('../../provenance_scripts/')
import call_provenance as cp
import sqlite3


def scan_lambda_k_space(lambda_a_space, k_a_space,
                        xi_factor=1., magnetic_potential_energy_ratio=1.,
                        offset=1E-3, r_0=0., init_value=(0.0, 1.0),
                        rtol=None, max_step=1E-2,
                        nsteps=1000, method='lsoda', suppress_output=True,
                        diagnose=False, stiff=False, use_jac=True,
                        adapt_step_size=True,
                        **kwargs):
    r"""
    Scans space given by lambda_a_space and k_a_space for m=0, 1 stability and
    saves several 2D numpy arrays (stability maps) to an npz file.
    """
    call_parameters = locals()
    func_name = 'scan_lambda_k_space'

    sing_search_points = 1000
    suydam_end_offset = offset

    k_a_points = np.linspace(k_a_space[0], k_a_space[1], num=k_a_space[2])
    lambda_a_points = np.linspace(lambda_a_space[0], lambda_a_space[1],
                                  num=lambda_a_space[2])

    lambda_a_mesh, k_a_mesh = np.meshgrid(lambda_a_points, k_a_points)

    mesh_shape = lambda_a_mesh.shape

    delta_map = {-1: np.zeros(mesh_shape),
                 0: np.zeros(mesh_shape)}

    sub_stability_maps = {-1: np.ones(mesh_shape),
                          0: np.ones(mesh_shape)}

    stability_maps = {'external': deepcopy(sub_stability_maps),
                      'd_w': deepcopy(sub_stability_maps),
                      'd_w_norm': deepcopy(sub_stability_maps),
                      'suydam': deepcopy(sub_stability_maps)}

    for i, lambda_a in enumerate(lambda_a_points):
        print('lambda_bar = %.3f' % lambda_a)
        for j, k_a in enumerate(k_a_points):
            for m in [-1, 0]:
                profile = es.UnitlessSmoothedCoreSkin(k_bar=k_a,
                                                      lambda_bar=lambda_a,
                                                      **kwargs)


                params = {'k': k_a, 'm': float(m), 'r_0': r_0, 'a': 1.,
                          'b': 'infinity'}
                params_wo_splines = deepcopy(params)
                params.update(profile.get_tck_splines())
                params.update({'xi_factor': xi_factor,
                               'magnetic_potential_energy_ratio': magnetic_potential_energy_ratio,
                               'beta_0': profile.beta_0(),
                               'core_radius': profile.core_radius,
                               'transition_width': profile.transition_width,
                               'skin_width': profile.skin_width,
                               'points_core': profile.points_core,
                               'points_transition': profile.points_transition,
                               'points_skin': profile.points_skin,
                               'epsilon': profile.epsilon})
                results = new.stability(params, offset, suydam_end_offset,
                                        sing_search_points=sing_search_points,
                                        suppress_output=suppress_output,
                                        xi_given=init_value,
                                        rtol=rtol, max_step=max_step,
                                        nsteps=nsteps, method=method,
                                        diagnose=diagnose, stiff=stiff,
                                        use_jac=use_jac,
                                        adapt_step_size=adapt_step_size)
                stable_external = results[0]
                stable_suydam = results[1]
                delta_w = results[2]
                xi = results[4]
                xi_der = results[5]

                delta = xi_der[-1] / xi[-1]

                delta_map[m][j][i] = delta

                if delta_w is not None:
                    stability_maps['d_w'][m][j][i] = delta_w
                    stability_maps['d_w_norm'][m][j][i] = delta_w
                else:
                    stability_maps['d_w'][m][j][i] = np.nan
                    stability_maps['d_w_norm'][m][j][i] = np.nan

                if not stable_external:
                    stability_maps['external'][m][j][i] = 0.
                if stable_external and delta_w is None:
                    stability_maps['external'][m][j][i] = -1.
                if not stable_suydam:
                    stability_maps['suydam'][m][j][i] = 0.
{'fraction_non_alphanumeric': 0.09657087917957483, 'fraction_numerical': 0.013780578997970302, 'mean_word_length': 1.4747554850647635, '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': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '786997', 'n_tokens_mistral': 2756, 'n_tokens_neox': 2595, 'n_words': 497}