#!/usr/bin/env python
# Authors of this code:
# Daniel A. Brandt, Ph.D., Michigan Tech Research Institute, daabrand@mtu.edu
# Aaron L. Bukowski, Ph.D., University of Michigan, abukowski@umich.edu
# Aaron J. Ridley, Ph.D., University of Michigan, ridley@umich.edu
# This file contains a suite of tools that do the following:
# 1. Download FISM2 data for a time period the user desires.
# 2. Rebin that data into the binning scheme the user desires (i.e. EUVAC-37, NEUVAC-59, or SOLOMON).
# 3. Outputs a FISM2 file with the rebinnined irradiances in the desired bins (for use by euv.cpp)
# Top-level imports:
import argparse
import numpy as np
from datetime import datetime, timedelta
import pathlib
import os, sys
import pooch
from netCDF4 import Dataset
import scipy.integrate as integ
# Directory management:
here = pathlib.Path(__file__).parent.resolve()
euvDir = here.parent.joinpath('share/run/UA/inputs')
# Physical constants:
h = 6.62607015e-34 # Planck's constant in SI units of J s
c = 299792458 # Speed of light in m s^-1
# Helper Functions:
def getFism2(dateStart, dateEnd, source, downloadDir=None):
"""
Given a starting date and an ending date, automatically download irradiance data from LISIRD for a specific source,
including FISM2 daily or FISM2 in the Standard Bands.
:param dateStart: str
The starting date for the data in YYYY-MM-DD format.
:param dateEnd: str
The ending date for the data in YYYY-MM-DD format.
:param source: str
The type of data to be obtained. Valid inputs are:
- FISM2 (for daily averages of FISM2 data)
- FISM2S (for daily averages of FISM2 standard bands, according to Solomon and Qian 2005)
:return times: ndarray
Datetime values for each spectrum.
:return wavelengths: ndarray
Wavelength bins (bin boundaries) for the spectral data.
:return irradiance: ndarray
A 2D array where each row is a spectrum at a particular time, and the columns are wavelength bands.
"""
# Converting the input time strings to datetimes:
try:
dateStartDatetime = datetime.strptime(dateStart, "%Y-%m-%d")
dateEndDatetime = datetime.strptime(dateEnd, "%Y-%m-%d")
except:
dateStartDatetime = datetime.strptime(dateStart, "%Y%m%d")
dateEndDatetime = datetime.strptime(dateEnd, "%Y%m%d")
# Check if the user has asked for a source that can be obtained:
validSources = ['FISM2', 'FISM2S']
if source not in validSources:
raise ValueError("Variable 'source' must be either 'FISM2' or 'FISM2S.")
# If the download directory is not specified, set it to the top directory that the package is in:
if downloadDir is None:
downloadDir = os.getcwd()
# Download the most recent file for the corresponding source and read it in:
if source == 'FISM2':
url = 'https://lasp.colorado.edu/eve/data_access/eve_data/fism/daily_hr_data/daily_data.nc'
fname = 'FISM2_daily_data.nc'
urlObtain(url, loc=downloadDir, fname=fname) # hash='dbee404e1c75689b47691b8a4a733236bb66abbdc0f01b8cbd8236f69fe9d469'
datetimes, wavelengths, irradiance, uncertainties = obtainFism2(os.path.join(downloadDir, fname))
else:
url = 'https://lasp.colorado.edu/eve/data_access/eve_data/fism/daily_bands/daily_bands.nc'
fname = 'FISM2_daily_bands.nc'
urlObtain(url, loc=downloadDir, fname=fname) # hash='27e3183f8ad6b289de191a63d3feada64c9d3f6b2973315ceda4a42c41638465'
datetimes, wavelengths, irradiance, uncertainties = obtainFism2(os.path.join(downloadDir, fname), bands=True)
# Subset the data according to user demands:
validInds = np.where((datetimes >= dateStartDatetime) & (datetimes