Commit 2d6c838a authored by Qusai Al Shidi's avatar Qusai Al Shidi 💬
Browse files

Merging my adapt branch

parents 3f9a436e 63fbd1ac
...@@ -10,7 +10,6 @@ TODO: Move pandas dependancy elsewhere. ...@@ -10,7 +10,6 @@ TODO: Move pandas dependancy elsewhere.
import datetime as dt import datetime as dt
import numpy as np import numpy as np
import pandas as pd
def read_wdc_ae(wdc_filename): def read_wdc_ae(wdc_filename):
...@@ -71,6 +70,7 @@ def read_omni_csv(filename, filtering=False, **kwargs): ...@@ -71,6 +70,7 @@ def read_omni_csv(filename, filtering=False, **kwargs):
""" """
import pandas as pd
# Read the csv files and set the index to dates # Read the csv files and set the index to dates
colnames = ['Time', 'Bx [nT]', 'By [nT]', 'Bz [nT]', colnames = ['Time', 'Bx [nT]', 'By [nT]', 'Bz [nT]',
'Vx [km/s]', 'Vy [km/s]', 'Vz [km/s]', 'Vx [km/s]', 'Vy [km/s]', 'Vz [km/s]',
...@@ -111,15 +111,16 @@ def write_imf_input(data, outfilename="IMF.dat", enable_rb=True, **kwargs): ...@@ -111,15 +111,16 @@ def write_imf_input(data, outfilename="IMF.dat", enable_rb=True, **kwargs):
Args: Args:
data: pandas.DataFrame object with solar wind data data: pandas.DataFrame object with solar wind data
outfilename: The output file name for ballistic solar wind data. \ outfilename: The output file name for ballistic solar wind data.
(default: "IMF.dat") (default: "IMF.dat")
enable_rb: Enables solar wind input for the radiation belt model. \ enable_rb: Enables solar wind input for the radiation belt model.
(default: True) (default: True)
Other paramaters: Other paramaters:
gse: (default=False) gse: (default=False)
Use GSE coordinate system for the file instead of GSM default. Use GSE coordinate system for the file instead of GSM default.
""" """
# Generate BATS-R-US solar wind input file # Generate BATS-R-US solar wind input file
with open(outfilename, 'w') as outfile: with open(outfilename, 'w') as outfile:
outfile.write("CSV files downloaded from ") outfile.write("CSV files downloaded from ")
...@@ -193,6 +194,9 @@ def read_gm_log(filename, colnames=None, index_by_time=True): ...@@ -193,6 +194,9 @@ def read_gm_log(filename, colnames=None, index_by_time=True):
geo["AL"].plot.line() geo["AL"].plot.line()
``` ```
""" """
import pandas as pd
# If column names were not specified # If column names were not specified
if not colnames: if not colnames:
with open(filename, 'r') as logfile: with open(filename, 'r') as logfile:
......
...@@ -131,7 +131,7 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs): ...@@ -131,7 +131,7 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs):
Downloads ADAPT magnetograms from ftp://gong2.nso.edu/adapt/maps/gong/ Downloads ADAPT magnetograms from ftp://gong2.nso.edu/adapt/maps/gong/
to a local directory. It will download all maps with the regex file to a local directory. It will download all maps with the regex file
pattern: adapt4[0,1]3*yyymmddhh pattern: adapt4[0,1]3*yyyymmddhh
Args: Args:
time (datetime.datetime): Time in which you want the magnetogram. time (datetime.datetime): Time in which you want the magnetogram.
...@@ -186,9 +186,8 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs): ...@@ -186,9 +186,8 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs):
try: try:
ftp.cwd(str(time.year)) ftp.cwd(str(time.year))
except ftplib.all_errors: except ftplib.all_errors:
raise NotADirectoryError('Cannot go to the specific year directory')
finally:
ftp.quit() ftp.quit()
raise NotADirectoryError('Cannot go to the specific year directory')
# ADAPT maps only contains the hours for even numbers # ADAPT maps only contains the hours for even numbers
if time.hour % 2 != 0: if time.hour % 2 != 0:
...@@ -201,7 +200,7 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs): ...@@ -201,7 +200,7 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs):
+ str(time.month).zfill(2) \ + str(time.month).zfill(2) \
+ str(time.day).zfill(2) \ + str(time.day).zfill(2) \
+ str(time.hour//2*2).zfill(2) + '*' + str(time.hour//2*2).zfill(2) + '*'
# adapt4[0,1]3*yyymmddhh # adapt4[0,1]3*yyyymmddhh
filenames = ftp.nlst(file_pattern) filenames = ftp.nlst(file_pattern)
...@@ -219,9 +218,8 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs): ...@@ -219,9 +218,8 @@ def download_magnetogram_adapt(time, map_type='fixed', **kwargs):
try: try:
ftp.retrbinary('RETR ' + filename, fhandle.write) ftp.retrbinary('RETR ' + filename, fhandle.write)
except ftplib.all_errors: except ftplib.all_errors:
raise FileNotFoundError('Cannot download ', filename)
finally:
ftp.quit() ftp.quit()
raise FileNotFoundError('Cannot download ', filename)
# unzip the file # unzip the file
if '.gz' in filename: if '.gz' in filename:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment