- Notifications
You must be signed in to change notification settings - Fork9
Space Physics made EASY! A simple Python package to deal with main Space Physics WebServices (CDA,SSC,AMDA,..)
License
SciQLop/speasy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Speasy is a free and open-source Python package that makes it easy to find and load space physics data from a variety ofdata sources, whether it is online and public such asCDAWEB andAMDA,or any described archive, local or remote.This task, where any science project starts, would seem easy a priori but, considering the verydiverse array of missions and instrument nowaday available, proves to be one of the major bottleneck,especially for students and newcomers.Speasy solves this problem by providing asingle, easy-to-use interface to over 70 space missions and 65,000 products.
Don't want to write code? See our graphical interfaceSciQLop.
- Simple and intuitive API (
spz.get_data(...)
to get them all) - Speasy variables are like Pandas DataFrame with seemless conversion to/from it (as long as the shape is compatible)
- Speasy variables support numpy operations,see numpy operations example below
- Speasy variables filtering and resampling capabilities,see resampling example below
- Local cache to avoid redundant downloads
- Uses the SciQLOP ultra fast community cache server
- Full support ofAMDA API
- Can retrieve time-series fromAMDA,CDAWeb,CSA,SSCWeb
- Support data access from any local or remote archives described by YAML file.
- Also available asSpeasy.jl for Julia users
We want Speasy to be the best possible tool for space physics research. You can help us by:
- Answering our user surveyhere.
- Reporting bugs or requesting featureshere.
- Creating or participating in discussionshere.
Your feedback is essential to making Speasy a better tool for everyone.
Installing Speasy with pip (more details here):
$python -m pip install speasy#or$python -m pip install --user speasy
This simple code example shows how easy it is to get data using Speasy. The code imports the Speasy package and defines a variable named ace_mag. This variable stores the data for the ACE IMF product, for the time period from June 2, 2016 to June 5, 2016. The code then uses the Speasy plot() function to plot the data.
importnumpy.linalgimportspeasyasspzace_mag=spz.get_data('amda/imf',"2016-6-2","2016-6-5")ace_mag.plot();
Where amda is the webservice and imf is the product id you will get withthis request.
Using the dynamic inventory will produce the same result as the previous example, but it has the advantage of being easier to manipulate, since you can discover available data from your favorite Python environment completion tool, such as IPython or notebooks.
importspeasyasspzamda_tree=spz.inventories.data_tree.amdaace_mag=spz.get_data(amda_tree.Parameters.ACE.MFI.ace_imf_all.imf,"2016-6-2","2016-6-5")ace_mag.plot();
This code example shows how to use Speasy to plot multiple time series of space physics data from theMMS1 spacecraft on a single figure, with a shared x-axis. The code imports the Speasy package and theMatplotlib plotting library. It then creates a figure with six subplots, arranged in a single column. Next, it defines a list of products and axes to plot. Finally, it iterates over the list of products and axes, plotting each product on the corresponding axis. The code uses the Speasyget_data() function to load the data for each product, and thereplace_fillval_by_nan() function to replace any fill values with NaNs.
importspeasyasspzimportmatplotlib.pyplotaspltfig=plt.figure(figsize=(8,16),layout="constrained")gs=fig.add_gridspec(6,hspace=0,wspace=0)axes=gs.subplots(sharex=True)plots= [ (spz.inventories.tree.cda.MMS.MMS1.FGM.MMS1_FGM_SRVY_L2.mms1_fgm_b_gse_srvy_l2_clean,axes[0]), (spz.inventories.tree.cda.MMS.MMS1.SCM.MMS1_SCM_SRVY_L2_SCSRVY.mms1_scm_acb_gse_scsrvy_srvy_l2 ,axes[1]), (spz.inventories.tree.cda.MMS.MMS1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_bulkv_gse_fast,axes[2]), (spz.inventories.tree.cda.MMS.MMS1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_temppara_fast,axes[3]), (spz.inventories.tree.cda.MMS.MMS1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_tempperp_fast,axes[3]), (spz.inventories.tree.cda.MMS.MMS1.DES.MMS1_FPI_FAST_L2_DES_MOMS.mms1_des_energyspectr_omni_fast,axes[4]), (spz.inventories.tree.cda.MMS.MMS1.DIS.MMS1_FPI_FAST_L2_DIS_MOMS.mms1_dis_energyspectr_omni_fast,axes[5])]defplot_product(product,ax):values=spz.get_data(product,"2019-01-02T15","2019-01-02T22")values.replace_fillval_by_nan().plot(ax=ax)forpinplots:plot_product(p[0],p[1])plt.show()
More complex requests like this one are supported:
importspeasyasspzproducts= [spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_vth,spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_pdyn,spz.inventories.tree.amda.Parameters.Wind.SWE.wnd_swe_kp.wnd_swe_n,spz.inventories.tree.cda.Wind.WIND.MFI.WI_H2_MFI.BGSE,spz.inventories.tree.ssc.Trajectories.wind,]intervals= [["2010-01-02","2010-01-02T10"], ["2009-08-02","2009-08-02T10"]]data=spz.get_data(products,intervals)data
[[<speasy.products.variable.SpeasyVariable at 0x7f14662feb80>, <speasy.products.variable.SpeasyVariable at 0x7f146688a7c0>], [<speasy.products.variable.SpeasyVariable at 0x7f14660b0f40>, <speasy.products.variable.SpeasyVariable at 0x7f14660d1180>], [<speasy.products.variable.SpeasyVariable at 0x7f1465f6da80>, <speasy.products.variable.SpeasyVariable at 0x7f14660f43c0>], [<speasy.products.variable.SpeasyVariable at 0x7f14664d8dc0>, <speasy.products.variable.SpeasyVariable at 0x7f146619fd40>], [<speasy.products.variable.SpeasyVariable at 0x7f14660e63c0>, <speasy.products.variable.SpeasyVariable at 0x7f1465f0ba40>]]
Speasy variables support numpy operations, as shown in this example. The code imports the Speasy package and the NumPy library, and uses the Speasyget_data() function to load the magnetic field data for the MMS1 spacecraft for the time period from January 1, 2017 to January 1, 2017. The code then uses the NumPysqrt() andsum() functions to compute the norm of the magnetic field vector. Finally, the code uses the NumPyallclose() function to check if the computed norm is close to the provided total magnetic field norm (Bt) values.
importspeasyasspzimportnumpyasnpmms1_products=spz.inventories.tree.cda.MMS.MMS1b=spz.get_data(mms1_products.FGM.MMS1_FGM_SRVY_L2.mms1_fgm_b_gsm_srvy_l2,'2017-01-01T02:00:00','2017-01-01T02:00:15')b.replace_fillval_by_nan(inplace=True)# replace fill values by NaNbt=b["Bt"]b=b["Bx GSM","By GSM","Bz GSM"]computed_norm=np.sqrt(np.sum(b**2,axis=1))print(f"Type of b:{type(b)}\nType of computed_norm:{type(computed_norm)}\nType of bt:{type(bt)}")print(f"Is the computed norm close to the provided total magnetic field norm?{np.allclose(computed_norm,bt)}")
Type of b: <class 'speasy.products.variable.SpeasyVariable'>Type of computed_norm: <class 'speasy.products.variable.SpeasyVariable'>Type of bt: <class 'speasy.products.variable.SpeasyVariable'>Is the computed norm close to the provided total magnetic field norm? True
Speasy provides a simple way to filter and resample data. In this example, the code imports the Speasy package and theMatplotlib plotting library. It then uses the Speasyget_data() function to load the magnetic field and temperature data for the MMS1 spacecraft for the time period from January 1, 2017 to January 1, 2017. The code then uses the Speasyinterpolate() function to interpolate the temperature data to match the magnetic field data sampling rate. Finally, the code plots the magnetic field and temperature data on the same figure.
importspeasyasspzfromspeasy.signal.resamplingimportinterpolateimportmatplotlib.pyplotaspltmms1_products=spz.inventories.tree.cda.MMS.MMS1b,Tperp,Tpara=spz.get_data( [mms1_products.FGM.MMS1_FGM_SRVY_L2.mms1_fgm_b_gsm_srvy_l2,mms1_products.DIS.MMS1_FPI_FAST_L2_DIS_MOMS.mms1_dis_tempperp_fast,mms1_products.DIS.MMS1_FPI_FAST_L2_DIS_MOMS.mms1_dis_temppara_fast ],'2017-01-01T02:00:00','2017-01-01T02:00:15' )Tperp_interp,Tpara_interp=interpolate(b, [Tperp,Tpara])plt.figure()ax=b.plot()plt.plot(Tperp_interp.time,Tperp_interp.values,marker='+')plt.plot(Tpara_interp.time,Tpara_interp.values,marker='+')plt.tight_layout()
Check outSpeasy documentation andexamples.
- Speasy is not a plotting package.basic plotting capabilities are here for illustration purposes and making quick-and-dirty plots.It is not meant to produce publication ready figures, prefer using Matplotlib directly for example.
The development of Speasy is supported by theCDPP.
This package was created withCookiecutter and theaudreyr/cookiecutter-pypackageproject template.
About
Space Physics made EASY! A simple Python package to deal with main Space Physics WebServices (CDA,SSC,AMDA,..)