0

I am using data from cdasws to plot dynamic spectra. I am following the example found here https://cdaweb.gsfc.nasa.gov/WebServices/REST/jupyter/CdasWsExample.html

This is my code which I have modified to obtain a dynamic spectra for STEREO.

from cdasws import CdasWs
from cdasws.datarepresentation import DataRepresentation
import matplotlib.pyplot as plt
cdas = CdasWs()
import numpy as np

datasets = cdas.get_datasets(observatoryGroup='STEREO')

for index, dataset in enumerate(datasets):
    print(dataset['Id'], dataset['Label'])

variables = cdas.get_variables('STEREO_LEVEL2_SWAVES')
for variable_1 in variables:
    print(variable_1['Name'], variable_1['LongDescription'])

data = cdas.get_data('STEREO_LEVEL2_SWAVES', ['avg_intens_ahead'],
                     '2020-07-11T02:00:00Z', '2020-07-11T03:00:00Z',
                     dataRepresentation = DataRepresentation.XARRAY)[1]
print(data)

plt.figure(figsize = (15,7))
# plt.ylim(100,1000)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
plt.yscale('log')
sorted_data.transpose().plot()
plt.xlabel("Time",size=18)
plt.ylabel("Frequency (kHz)",size=18)
plt.show()

Using this code gives a plot that looks something like this,

Dynamic spectrum

My question is, is there anyway of plotting this spectrum only for a particular frequency? For example, I want to plot just the intensity values at 636 kHz, is there any way I can do that?

Any help is greatly appreciated, I dont understand xarray, I have never worked with it before.

Edit -

Using the command,

data_stereo.avg_intens_ahead.loc[:,625].plot()

generates a plot that looks like, enter image description here

While this is useful, what I needed is;

for the dynamic spectrum, if i choose a particular frequency like 600khz, can it display something like this (i have just added white boxes to clarify what i mean) -

enter image description here

3
  • You can select data by label with data.sel(frequency=636). See the docs on Indexing and selecting data. Once you have only the data you want, you can plot it with .plot. Commented Feb 7, 2023 at 12:10
  • @MichaelDelgado thank you for your help! this is what i used, data_stereo.avg_intens_ahead.loc[:,625].plot() and it generates a plot. Im editting my original post to show what plot I get, but its not what i needed. Im editing my original post to clarify my doubt Commented Feb 7, 2023 at 12:13
  • @MichaelDelgado Thanks a lot! the last command worked very well!! Commented Feb 8, 2023 at 12:14

1 Answer 1

1

If you still want the plot to be 2D, but to include a subset of your data along one of the dimensions, you can provide an array of indices or a slice object. For example:

data_stereo.avg_intens_ahead.sel(
    frequency=[625]
).plot()

Or

# include a 10% band on either side
data_stereo.avg_intens_ahead.sel(
    frequency=slice(625*0.9, 625*1.1)
).plot()

Alternatively, if you would actually like your plot to show white space outside this selected area, you could mask your data with where:

data_stereo.avg_intens_ahead.where(
    data_stereo.frequency==625
).plot()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.