CHAMP MAG

CHAMP MAG#

Abstract: Accesing CHAMP magnetic products, provided by GFZ

Rother, Martin; Michaelis, Ingo (2019): CH-ME-3-MAG - CHAMP 1 Hz Combined Magnetic Field Time Series (Level 3). GFZ Data Services. https://doi.org/10.5880/GFZ.2.3.2019.004

%load_ext watermark
%watermark -i -v -p viresclient,pandas,xarray,matplotlib
Python implementation: CPython
Python version       : 3.11.6
IPython version      : 8.18.0

viresclient: 0.15.0
pandas     : 2.1.3
xarray     : 2023.12.0
matplotlib : 3.8.2
from viresclient import SwarmRequest
import datetime as dt
import numpy as np
import matplotlib.pyplot as plt
request = SwarmRequest()
request.available_collections("MAG_CHAMP", details=False)
{'MAG_CHAMP': ['CH_ME_MAG_LR_3']}
request.available_measurements("CH_ME_MAG_LR_3")
['F',
 'B_VFM',
 'B_NEC',
 'Flags_Position',
 'Flags_B',
 'Flags_q',
 'Mode_q',
 'q_ICRF_CRF']
request = SwarmRequest("https://disc.vires.services/ows")
request.set_collection("CH_ME_MAG_LR_3")
# request.set_collection("SW_OPER_MAGA_LR_1B")
request.set_products(
    measurements=[
        # 'F',
        "B_NEC",
        # 'B_FGM',
        # 'q_ASC_CRF',
        # 'ASC_MODE',
        # 'ASC_STAT',
        # 'GEO_STAT',
        # 'FGM_FLAGS'
    ],
    models=["CHAOS"],
    sampling_step="PT10S",
    auxiliaries=["OrbitNumber"],
    # auxiliaries=["OrbitNumber", "OrbitDirection", "QDOrbitDirection", "MLT"]
)
data = request.get_between(
    start_time="2002-01-01T00:00:00Z",
    end_time="2002-02-01T00:01:00Z",
    asynchronous=True,
)
ds = data.as_xarray()
ds["B_NEC_res_Model"] = ds["B_NEC"] - ds["B_NEC_CHAOS"]
ds
2026-03-04T11:45:23.919275Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.442s
2026-03-04T11:45:23.919275Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.442s
Token invalid.
Setting access token for https://disc.vires.services/ows...
Generate a token at https://disc.vires.services/accounts/tokens/
No input method available. Unable to set token.
2026-03-04T11:45:24.364041Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.441s
2026-03-04T11:45:24.364041Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.441s
Token invalid.
Setting access token for https://disc.vires.services/ows...
Generate a token at https://disc.vires.services/accounts/tokens/
No input method available. Unable to set token.
2026-03-04T11:45:24.811841Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.444s
2026-03-04T11:45:24.811841Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.444s
Token invalid.
Setting access token for https://disc.vires.services/ows...
Generate a token at https://disc.vires.services/accounts/tokens/
No input method available. Unable to set token.
2026-03-04T11:45:25.263313Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.447s
2026-03-04T11:45:25.263313Z ERROR WPS10Service: 403 POST https://disc.vires.services/ows 0.447s
Token invalid.
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/viresclient/_wps/wps.py:385, in WPS10Service._retrieve(self, request, response_handler, error_handler)
    384 try:
--> 385     with closing(urlopen(request)) as file_in:
    386         output = (response_handler or self._default_handler)(file_in)

File /opt/conda/lib/python3.11/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    215     opener = _opener
--> 216 return opener.open(url, data, timeout)

File /opt/conda/lib/python3.11/urllib/request.py:525, in OpenerDirector.open(self, fullurl, data, timeout)
    524     meth = getattr(processor, meth_name)
--> 525     response = meth(req, response)
    527 return response

File /opt/conda/lib/python3.11/urllib/request.py:634, in HTTPErrorProcessor.http_response(self, request, response)
    633 if not (200 <= code < 300):
--> 634     response = self.parent.error(
    635         'http', request, response, code, msg, hdrs)
    637 return response

File /opt/conda/lib/python3.11/urllib/request.py:563, in OpenerDirector.error(self, proto, *args)
    562 args = (dict, 'default', 'http_error_default') + orig_args
--> 563 return self._call_chain(*args)

File /opt/conda/lib/python3.11/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    495 func = getattr(handler, meth_name)
--> 496 result = func(*args)
    497 if result is not None:

File /opt/conda/lib/python3.11/urllib/request.py:643, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
    642 def http_error_default(self, req, fp, code, msg, hdrs):
--> 643     raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

AuthenticationError                       Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/viresclient/_client.py:500, in ClientRequest._get(self, request, asynchronous, response_handler, message, show_progress, leave_progress_bar, content_type, headers)
    499     else:
--> 500         return self._wps_service.retrieve(
    501             request,
    502             handler=response_handler,
    503             content_type=content_type,
    504             headers=headers,
    505         )
    506 except WPSError:

File /opt/conda/lib/python3.11/site-packages/viresclient/_wps/wps.py:106, in retry.<locals>._retry.<locals>._retry_wrapper(self, *args, **kwargs)
    105 try:
--> 106     return method(self, *args, **kwargs)
    108 except WPSError:

File /opt/conda/lib/python3.11/site-packages/viresclient/_wps/wps.py:177, in WPS10Service.retrieve(self, request, handler, content_type, headers)
    172 headers = {
    173     **self.headers,
    174     **self._headers_to_bytes(headers or {}),
    175     "Content-Type": content_type or self.DEFAULT_CONTENT_TYPE,
    176 }
--> 177 return self._retrieve(
    178     Request(self.url, request, headers), handler, self.error_handler
    179 )

File /opt/conda/lib/python3.11/site-packages/viresclient/_wps/wps.py:394, in WPS10Service._retrieve(self, request, response_handler, error_handler)
    393 if error_handler:
--> 394     return error_handler(error)
    395 raise

File /opt/conda/lib/python3.11/site-packages/viresclient/_wps/wps.py:351, in WPS10Service.error_handler(cls, http_error)
    350 if http_error.status in [401, 403]:
--> 351     raise AuthenticationError
    352 try:

AuthenticationError: Perhaps credentials are missing or invalid. 

During handling of the above exception, another exception occurred:

AuthenticationError                       Traceback (most recent call last)
File /opt/conda/lib/python3.11/site-packages/viresclient/_client.py:300, in ClientRequest.__init__(self, url, token, config, logging_level, server_type)
    299 try:
--> 300     self.list_jobs()
    301     invalid_token = False

File /opt/conda/lib/python3.11/site-packages/viresclient/_client.py:674, in ClientRequest.list_jobs(self)
    673 request = template.render().encode("UTF-8")
--> 674 response = self._get(request, asynchronous=False, show_progress=False)
    675 return json.loads(response.decode("UTF-8"))

File /opt/conda/lib/python3.11/site-packages/viresclient/_client.py:513, in ClientRequest._get(self, request, asynchronous, response_handler, message, show_progress, leave_progress_bar, content_type, headers)
    512 except AuthenticationError:
--> 513     raise AuthenticationError(AUTH_ERROR_TEXT)

AuthenticationError: Perhaps credentials are missing or invalid. 
Invalid token? Set with viresclient.set_token().
For more details, see:
https://viresclient.readthedocs.io/en/latest/config_details.html

During handling of the above exception, another exception occurred:

AuthenticationError                       Traceback (most recent call last)
Cell In[6], line 1
----> 1 request = SwarmRequest("https://disc.vires.services/ows")
      2 request.set_collection("CH_ME_MAG_LR_3")
      3 # request.set_collection("SW_OPER_MAGA_LR_1B")

File /opt/conda/lib/python3.11/site-packages/viresclient/_client_swarm.py:1641, in SwarmRequest.__init__(self, url, token, config, logging_level)
   1638 def __init__(
   1639     self, url=None, token=None, config=None, logging_level=DEFAULT_LOGGING_LEVEL
   1640 ):
-> 1641     super().__init__(url, token, config, logging_level, server_type="Swarm")
   1643     self._available = self._get_available_data()
   1644     self._request_inputs = SwarmWPSInputs()

File /opt/conda/lib/python3.11/site-packages/viresclient/_client.py:306, in ClientRequest.__init__(self, url, token, config, logging_level, server_type)
    304 attempts += 1
    305 if attempts > 3:
--> 306     raise AuthenticationError(AUTH_ERROR_TEXT)
    307 set_token(url)
    308 self._wps_service = self._create_service_proxy_(
    309     config, url, None, None, token
    310 )

AuthenticationError: Perhaps credentials are missing or invalid. 
Invalid token? Set with viresclient.set_token().
For more details, see:
https://viresclient.readthedocs.io/en/latest/config_details.html
ds["B_NEC_res_Model"].plot.line(x="Timestamp")
cdf = data._contents[0].open_cdf()
cdf.varattsget("B_NEC")