.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/mag/hires_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_mag_hires_example.py: Plot High Resolution MAG Data ============================= Download, read and plot high resolution (hires) GOES-R Series Magnetometer (MAG) data .. GENERATED FROM PYTHON SOURCE LINES 7-16 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as mdates import cftime import netCDF4 as nc import os, sys, requests .. GENERATED FROM PYTHON SOURCE LINES 17-18 Download a day of GOES-16 data .. GENERATED FROM PYTHON SOURCE LINES 18-31 .. code-block:: Python dataurl = 'https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/goes16/l2/data/magn-l2-hires' subdir = '/2022/03/' filename = "dn_magn-l2-hires_g16_d20220325_v1-0-1.nc" if not os.path.exists(filename): with open(filename, "wb") as f: url_path = dataurl+subdir+filename print(url_path) r = requests.get(url_path) print(r) f.write(r.content) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Read the magnetic field strength from the netCDF file .. GENERATED FROM PYTHON SOURCE LINES 33-41 .. code-block:: Python with nc.Dataset(filename) as ncf: dts = cftime.num2pydate(ncf.variables['time'][:], ncf.variables['time'].units) B_total = ncf['b_total'][:] .. GENERATED FROM PYTHON SOURCE LINES 42-43 Plot the data .. GENERATED FROM PYTHON SOURCE LINES 43-56 .. code-block:: Python f,ax = plt.subplots(1,1,figsize=(8,4),dpi=200) ax.plot(dts,B_total,'b-') ax.set_ylabel('Magnetic Field Strength [nT]') #Format the times nicely locator = mdates.HourLocator(interval=3) ax.xaxis.set_major_locator(locator) ax.xaxis.set_minor_locator(mdates.HourLocator()) ax.xaxis.set_major_formatter(mdates.ConciseDateFormatter(locator)) plt.show() .. image-sg:: /examples/mag/images/sphx_glr_hires_example_001.png :alt: hires example :srcset: /examples/mag/images/sphx_glr_hires_example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.272 seconds) .. _sphx_glr_download_examples_mag_hires_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hires_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hires_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: hires_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_