Remote Access#
Madrigal database can be accessed from python by using the Madrigal python remote data access API to download one or multiple experiments.
import madrigalWeb.madrigalWeb
import os
#Credentials
user_fullname = 'Student Example'
user_email = 'isr.summer.school@gmail.com'
user_affiliation= 'ISR Summer School 2020'
madrigalUrl='http://cedar.openmadrigal.org'
data = madrigalWeb.madrigalWeb.MadrigalData(madrigalUrl)
Specify the Radar you want to access by its code and the timeframe for the experiment/experiments you want to retrieve.
PFISR radar code = 61
RISR-N radar code = 91
To retrieve all radars,run the script:
code = 61
year = 2024
month = 1
day = 8
hour1 = 7
hour2 = 13
min1 =1
expList = data.getExperiments(code,year,month,day,hour1,min1,0,year,month,day,hour2,0,0)
for exp in expList:
print(str(exp))
id: 100011616
realUrl: https://cedar.openmadrigal.org/showExperiment/?experiment_list=100011616
url: https://cedar.openmadrigal.org/madtoc/experiments4/2024/pfa/08jan24a
name: Themis36 - Auroral and convection measurements
siteid: 10
sitename: CEDAR
instcode: 61
instname: Poker Flat IS Radar
startyear: 2024
startmonth: 1
startday: 8
starthour: 7
startmin: 1
startsec: 4
endyear: 2024
endmonth: 1
endday: 8
endhour: 18
endmin: 0
endsec: 0
isLocal: True
madrigalUrl: http://https://cedar.openmadrigal.org/
PI: Asti Bhatt
PIEmail: asti.bhatt@sri.com
uttimestamp: 1735095302
access: 2
Madrigal version: 3.0
Download the file
fileList = data.getExperimentFiles(expList[0].id)
for file0 in fileList:
print(os.path.basename(file0.name),'\t', file0.kindat, '\t',file0.kindatdesc)
pfa20240108.001_ac_nenotr_01min.001.h5 1000201 None
pfa20240108.001_ac_fit_01min.001.h5 2000201 None
pfa20240108.001_ac_nenotr_03min.001.h5 1000203 None
pfa20240108.001_ac_fit_03min.001.h5 2000203 None
pfa20240108.001_ac_nenotr_05min.001.h5 1000205 None
pfa20240108.001_ac_fit_05min.001.h5 2000205 None
pfa20240108.001_ac_nenotr_10min.001.h5 1000210 None
pfa20240108.001_ac_fit_10min.001.h5 2000210 None
pfa20240108.001_ac_nenotr_15min.001.h5 1000215 None
pfa20240108.001_ac_fit_15min.001.h5 2000215 None
pfa20240108.001_ac_nenotr_20min.001.h5 1000220 None
pfa20240108.001_ac_fit_20min.001.h5 2000220 None
pfa20240108.001_lp_nenotr_01min.001.h5 1000101 None
pfa20240108.001_lp_fit_01min.001.h5 2000101 None
pfa20240108.001_lp_nenotr_03min.001.h5 1000103 None
pfa20240108.001_lp_fit_03min.001.h5 2000103 None
pfa20240108.001_lp_nenotr_05min.001.h5 1000105 None
pfa20240108.001_lp_fit_05min.001.h5 2000105 None
pfa20240108.001_lp_nenotr_10min.001.h5 1000110 None
pfa20240108.001_lp_fit_10min.001.h5 2000110 None
pfa20240108.001_lp_nenotr_15min.001.h5 1000115 None
pfa20240108.001_lp_fit_15min.001.h5 2000115 None
pfa20240108.001_lp_nenotr_20min.001.h5 1000120 None
pfa20240108.001_lp_fit_20min.001.h5 2000120 None
pfa20240108.001_lp_vvels_01min.001.h5 3000101 None
pfa20240108.001_lp_vvels_03min.001.h5 3000103 None
pfa20240108.001_lp_vvels_05min.001.h5 3000105 None
# Download the file that we need to run these examples
os.makedirs('../data', exist_ok=True)
filepath= '../data/pfa20240108.001_lp_fit_01min.001.h5 '
if not os.path.exists(filepath):
fileList = data.getExperimentFiles(expList[0].id)
for file0 in fileList:
if file0.kindatdesc == 'Fitted - Long Pulse (F-region) - 1 min':
file2download = file0.name
break
print('Downloading data file...')
file = data.downloadFile(file2download, filepath,
user_fullname, user_email, user_affiliation,'hdf5')
print('...Done!')
else:
print(f"File {filepath} already downloaded")
Downloading data file...
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[8], line 15
11 break
13 print('Downloading data file...')
---> 15 file = data.downloadFile(file2download, filepath,
16 user_fullname, user_email, user_affiliation,'hdf5')
17 print('...Done!')
19 else:
NameError: name 'file2download' is not defined