mth5.clients.geomag

Created on Mon Nov 14 13:58:44 2022

@author: jpeacock

Classes

GeomagClient

Get geomagnetic data from observatories.

USGSGeomag

Module Contents

class mth5.clients.geomag.GeomagClient(**kwargs)[source]

Get geomagnetic data from observatories.

key words

  • observatory: Geogmangetic observatory ID

  • type: type of data to get ‘adjusted’

  • start: start date time to request UTC

  • end: end date time to request UTC

  • elements: components to get

  • sampling_period: samples between measurements in seconds

  • format: JSON or IAGA2002

type = 'adjusted'[source]
property sampling_period[source]
property elements[source]
format = 'json'[source]
property observatory[source]
property start[source]
property end[source]
property user_agent[source]

User agent for the URL request

Returns:

DESCRIPTION

Return type:

TYPE

get_chunks()[source]

Get the number of chunks of allowable sized to request, includes the elements

So the max length is the maximum time period that can be requested but includes the number of elements in the request. So if the max length is 172800 seconds and the sampling period is 1 second, then the maximum number of elements that can be requested is 172800 / (1 * len(elements)).

Returns:

DESCRIPTION

Return type:

TYPE

get_data(run_id='001')[source]

Get data from geomag client at USGS based on the request. This might have to be done in chunks depending on the request size. The returned output is a json object, which we should turn into a ChannelTS object

For now read into a pandas dataframe and then into a ChannelTS

In the future, if the request is large, think about writing directly to an MTH5 for better efficiency.

Returns:

DESCRIPTION

Return type:

TYPE

class mth5.clients.geomag.USGSGeomag(**kwargs)[source]
save_path[source]
mth5_filename = None[source]
interact = False[source]
request_columns = ['observatory', 'type', 'elements', 'sampling_period', 'start', 'end'][source]
h5_compression = 'gzip'[source]
h5_compression_opts = 4[source]
h5_shuffle = True[source]
h5_fletcher32 = True[source]
h5_data_level = 1[source]
mth5_file_mode = 'w'[source]
mth5_version = '0.2.0'[source]
property h5_kwargs[source]
validate_request_df(request_df)[source]

Make sure the input request dataframe has the appropriate columns

Parameters:

request_df (pandas.DataFrame) – request dataframe

Returns:

valid request dataframe

Return type:

pandas.DataFrame

add_run_id(request_df)[source]

Add run id to request df

Parameters:

request_df (pandas.DataFrame) – request dataframe

Returns:

add a run number to unique time windows for each observatory at each unique sampling period.

Return type:

pandas.DataFrame

make_mth5_from_geomag(request_df)[source]

Download geomagnetic observatory data from USGS webservices into an MTH5 using a request dataframe or csv file.

Parameters:

request_df (pandas.DataFrame, str or Path if csv file) –

DataFrame with columns

  • ’observatory’ –> Observatory code

  • ’type’ –> data type [ ‘variation’ | ‘adjusted’ | ‘quasi-definitive’ | ‘definitive’ ]

  • ’elements’ –> Elements to get [D, DIST, DST, E, E-E, E-N, F, G, H, SQ, SV, UK1, UK2, UK3, UK4, X, Y, Z]

  • ’sampling_period’ –> sample period [ 1 | 60 | 3600 ]

  • ’start’ –> Start time YYYY-MM-DDThh:mm:ss

  • ’end’ –> End time YYYY-MM-DDThh:mm:ss

Returns:

if interact is True an MTH5 object is returned otherwise the path to the file is returned

Return type:

Path or mth5.mth5.MTH5