<commit_before>"""Various computations"""

import numpy as np
from scipy import integrate
from . import misc


def dt_dt(sdat, tstart=None, tend=None):
    """Derivative of temperature"""
    tseries = sdat.tseries_between(tstart, tend)
    time = tseries['t'].values
    temp = tseries['Tmean'].values
    dtdt = (temp[2:] - temp[:-2]) / (time[2:] - time[:-2])
    return dtdt, time[1:-1]


def ebalance(sdat, tstart=None, tend=None):
    """Energy balance"""
    tseries = sdat.tseries_between(tstart, tend)
    rbot, rtop = misc.get_rbounds(sdat.steps.last)
    if rbot != 0:  # spherical
        coefsurf = (rtop / rbot)**2
        volume = rbot * (1 - (rtop / rbot)**3) / 3
    else:
        coefsurf = 1.
        volume = 1.
    dtdt, time = dt_dt(sdat, tstart, tend)
    ftop = tseries['ftop'].values * coefsurf
    fbot = tseries['fbot'].values
    ebal = ftop[1:-1] - fbot[1:-1] - volume * dtdt
    return ebal, time


def r_edges(step):
    """Cell border"""
    rbot, rtop = misc.get_rbounds(step)
    centers = step.rprof.loc[:, 'r'].values + rbot
    # assume walls are mid-way between T-nodes
    # could be T-nodes at center between walls
    edges = (centers[:-1] + centers[1:]) / 2
    edges = np.insert(edges, 0, rbot)
    edges = np.append(edges, rtop)
    return edges, edges


def delta_r(step):
    """Cells thickness"""
    edges, _ = r_edges(step)
    return (edges[1:] - edges[:-1]), None

<commit_msg>Use first order t-derivative to compute ebalance<commit_after>"""Various computations"""

import numpy as np
from scipy import integrate
from . import misc


def dt_dt(sdat, tstart=None, tend=None):
    """Derivative of temperature"""
    tseries = sdat.tseries_between(tstart, tend)
    time = tseries['t'].values
    temp = tseries['Tmean'].values
    dtdt = (temp[1:] - temp[:-1]) / (time[1:] - time[:-1])
    return dtdt, time[:-1]


def ebalance(sdat, tstart=None, tend=None):
    """Energy balance"""
    tseries = sdat.tseries_between(tstart, tend)
    rbot, rtop = misc.get_rbounds(sdat.steps.last)
    if rbot != 0:  # spherical
        coefsurf = (rtop / rbot)**2
        volume = rbot * (1 - (rtop / rbot)**3) / 3
    else:
        coefsurf = 1.
        volume = 1.
    dtdt, time = dt_dt(sdat, tstart, tend)
    ftop = tseries['ftop'].values * coefsurf
    fbot = tseries['fbot'].values
    ebal = ftop[:-1] - fbot[:-1] - volume * dtdt
    return ebal, time


def r_edges(step):
    """Cell border"""
    rbot, rtop = misc.get_rbounds(step)
    centers = step.rprof.loc[:, 'r'].values + rbot
    # assume walls are mid-way between T-nodes
    # could be T-nodes at center between walls
    edges = (centers[:-1] + centers[1:]) / 2
    edges = np.insert(edges, 0, rbot)
    edges = np.append(edges, rtop)
    return edges, edges


def delta_r(step):
    """Cells thickness"""
    edges, _ = r_edges(step)
    return (edges[1:] - edges[:-1]), None


{'fraction_non_alphanumeric': 0.15835065835065834, 'fraction_numerical': 0.0148995148995149, 'mean_word_length': 2.8908355795148246, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2090222', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1052, 'n_words': 268}