<commit_before>"""
Contains functions useful for analysing GOES/XRS data.

Each of the Geostationary Operational Environmental Satellite (GOES) series
since the mid-1970s has carried an X-Ray Sensor (XRS) which observes
full-disk-integrated solar flux in two broadband channels:
1--8 angstrom (long); and 0.5--4 angstrom (short).  For more information on
the GOES/XRS instrument, see Hanser & Sellers (1996).  GOES/XRS has become
the "standard candle" for solar coronal observations due its longevity and
consistency.  The GOES event list, based on GOES/XRS observations, has
become the standard solar flare catalogue.
See http://www.ngdc.noaa.gov/stp/solar/solarflares.html for information
on the GOES event list definitions and data.

The functions in this module provide useful software to analyse GOES/XRS
observations.  First they allow the GOES event list to be imported into a
python session (get_goes_event_list()).

They also allow the thermodynamic properties of the emitting solar plasma to
be determined.  Temperature and emission measure are obtained using
calculate_temperature_em(), which calls _goes_chianti_tem(), which in turn
calls _goes_get_chianti_temp() and _goes_get_chianti_em().  These two
functions currently rely on lookup tables relating the GOES fluxes to the
isothermal temperature and volume emission measure.  These tables were
calculated by functions in SolarSoftWare (SSW) using the CHIANTI atomic
physics database (Dere et al. 2009). For more detail, see the docstring of
calculate_temperature_em() and references therein.

The radiative loss rate of the soft X-ray-emitting plasma across all
wavelengths can be found with calculate_radiative_loss_rate().  This function
calls _calc_rad_loss() which, like _goes_get_chianti_temp() and
_goes_get_chianti_em(), makes use of a look up table calculated by fuctions
in SSW using CHIANTI.  This table relates the temperature and emission
measure of the emitting solar plasma to the thermal energy radiative over
all wavelengths.  For more information on how this is done, see
the docstring of _calc_rad_loss() and reference therein.

Meanwhile, the X-ray luminosity in the two GOES passbands can be
obtained by calculate_xray_luminosity().  To do so, this function calls
_goes_lx() and calc_xraylum().

References
----------
<NAME>., & <NAME>. 1996, Proc. SPIE, 2812, 344
<NAME>., et al. 2009 A&A, 498, 915 DOI: 10.1051/0004-6361/200911712

"""

from __future__ import absolute_import
from __future__ import division

import os.path
import datetime
import csv
import copy
import socket
from itertools import dropwhile

import numpy as np
from scipy import interpolate
from scipy.integrate import trapz, cumtrapz
import astropy.units as u
import pandas

from sunpy.net import hek
from sunpy.time import parse_time
from sunpy import config
from sunpy import lightcurve
from sunpy.util.net import check_download_file
from sunpy.sun import sun
from sunpy.util.unit_decorators import quantity_input

__all__ = ['get_goes_event_list', 'calculate_temperature_em',
           'calculate_radiative_loss_rate', 'calculate_xray_luminosity']

try:
    # Check required data files are present in user's default download dir
    # Define location where GOES data files are stored.
    # Manually resolve the hostname
    HOST = socket.gethostbyname_ex('hesperia.gsfc.nasa.gov')[-1][0]
except socket.gaierror:
    HOST = ''
GOES_REMOTE_PATH = "http://{0}/ssw/gen/idl/synoptic/goes/".format(HOST)
# Define location where data files should be downloaded to.
DATA_PATH = config.get("downloads", "download_dir")
# Define variables for file names
FILE_TEMP_COR = "goes_chianti_temp_cor.csv"
FILE_TEMP_PHO = "goes_chianti_temp_pho.csv"
FILE_EM_COR = "goes_chianti_em_cor.csv"
FILE_EM_PHO = "goes_chianti_em_pho.csv"<commit_msg>Corrected socket host name for hesperia server where GOES text files are stored.<commit_after>"""
Contains functions useful for analysing GOES/XRS data.

Each of the Geostationary Operational Environmental Satellite (GOES) series
since the mid-1970s has carried an X-Ray Sensor (XRS) which observes
full-disk-integrated solar flux in two broadband channels:
1--8 angstrom (long); and 0.5--4 angstrom (short).  For more information on
the GOES/XRS instrument, see Hanser & Sellers (1996).  GOES/XRS has become
the "standard candle" for solar coronal observations due its longevity and
consistency.  The GOES event list, based on GOES/XRS observations, has
become the standard solar flare catalogue.
See http://www.ngdc.noaa.gov/stp/solar/solarflares.html for information
on the GOES event list definitions and data.

The functions in this module provide useful software to analyse GOES/XRS
observations.  First they allow the GOES event list to be imported into a
python session (get_goes_event_list()).

They also allow the thermodynamic properties of the emitting solar plasma to
be determined.  Temperature and emission measure are obtained using
calculate_temperature_em(), which calls _goes_chianti_tem(), which in turn
calls _goes_get_chianti_temp() and _goes_get_chianti_em().  These two
functions currently rely on lookup tables relating the GOES fluxes to the
isothermal temperature and volume emission measure.  These tables were
calculated by functions in SolarSoftWare (SSW) using the CHIANTI atomic
physics database (Dere et al. 2009). For more detail, see the docstring of
calculate_temperature_em() and references therein.

The radiative loss rate of the soft X-ray-emitting plasma across all
wavelengths can be found with calculate_radiative_loss_rate().  This function
calls _calc_rad_loss() which, like _goes_get_chianti_temp() and
_goes_get_chianti_em(), makes use of a look up table calculated by fuctions
in SSW using CHIANTI.  This table relates the temperature and emission
measure of the emitting solar plasma to the thermal energy radiative over
all wavelengths.  For more information on how this is done, see
the docstring of _calc_rad_loss() and reference therein.

Meanwhile, the X-ray luminosity in the two GOES passbands can be
obtained by calculate_xray_luminosity().  To do so, this function calls
_goes_lx() and calc_xraylum().

References
----------
<NAME>., & <NAME>. 1996, Proc. SPIE, 2812, 344
<NAME>., et al. 2009 A&A, 498, 915 DOI: 10.1051/0004-6361/200911712

"""

from __future__ import absolute_import
from __future__ import division

import os.path
import datetime
import csv
import copy
import socket
from itertools import dropwhile

import numpy as np
from scipy import interpolate
from scipy.integrate import trapz, cumtrapz
import astropy.units as u
import pandas

from sunpy.net import hek
from sunpy.time import parse_time
from sunpy import config
from sunpy import lightcurve
from sunpy.util.net import check_download_file
from sunpy.sun import sun
from sunpy.util.unit_decorators import quantity_input

__all__ = ['get_goes_event_list', 'calculate_temperature_em',
           'calculate_radiative_loss_rate', 'calculate_xray_luminosity']

try:
    # Check required data files are present in user's default download dir
    # Define location where GOES data files are stored.
    # Manually resolve the hostname
    HOST = socket.gethostbyname_ex('hesperia.gsfc.nasa.gov')[0]
except socket.gaierror:
    HOST = ''
GOES_REMOTE_PATH = "http://{0}/ssw/gen/idl/synoptic/goes/".format(HOST)
# Define location where data files should be downloaded to.
DATA_PATH = config.get("downloads", "download_dir")
# Define variables for file names
FILE_TEMP_COR = "goes_chianti_temp_cor.csv"
FILE_TEMP_PHO = "goes_chianti_temp_pho.csv"
FILE_EM_COR = "goes_chianti_em_cor.csv"
FILE_EM_PHO = "goes_chianti_em_pho.csv"
{'fraction_non_alphanumeric': 0.06419494301061182, 'fraction_numerical': 0.01663828114764837, 'mean_word_length': 5.082868525896414, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4850836', 'n_tokens_mistral': 2466, 'n_tokens_neox': 2258, 'n_words': 913}