import pyaurorax
import datetime
import pprint
import pandas as pd
# search for conjunctions between any THEMIS-ASI intrument and any Swarm instrument
start = datetime.datetime(2020, 1, 1, 0, 0, 0)
end = datetime.datetime(2020, 1, 1, 6, 59, 59)
ground = [
{"programs": ["themis-asi"]}
]
space = [
{"programs": ["swarm"]}
]
distance = 500
# perform search
s = pyaurorax.conjunctions.search(start,
end,
distance,
ground=ground,
space=space,
verbose=True)
# output data as a pandas dataframe
conjunctions = [c.__dict__ for c in s.data]
df = pd.DataFrame(conjunctions)
df.sort_values("start")
# set up a search for conjunctions between any THEMIS-ASI or REGO instrument, and
# any Swarm instrument with north B trace region = "north polar cap"
start = datetime.datetime(2019, 2, 1, 0, 0, 0)
end = datetime.datetime(2019, 2, 10, 23, 59, 59)
ground = [{
"programs": ["themis-asi", "rego"]
}]
space = [{
"programs": ["swarm"],
"ephemeris_metadata_filters": {
"logical_operator": "AND",
"expressions": [
{
"key": "nbtrace_region",
"operator": "=",
"values": ["north polar cap"]
}
]
}
}]
# perform search
s = pyaurorax.conjunctions.search(start,
end,
distance,
ground=ground,
space=space,
verbose=True)
# output data as a pandas dataframe
conjunctions = [c.__dict__ for c in s.data]
df = pd.DataFrame(conjunctions)
df.sort_values("start")
# search for conjunctions between any REGO instrument, any TREx instrument,
# any Swarm spacecraft, and any THEMIS spacecraft
#
# we call this a search for "quadruple conjunctions"
start = datetime.datetime(2020, 1, 1, 0, 0, 0)
end = datetime.datetime(2020, 1, 4, 23, 59, 59)
ground = [
{"programs": ["rego"]},
{"programs": ["trex"]}
]
space = [
{"programs": ["swarm"]},
{"programs": ["themis"]}
]
advanced_distances = {
"ground1-ground2": None,
"ground1-space1": 500,
"ground1-space2": 500,
"ground2-space1": 500,
"ground2-space2": 500,
"space1-space2": None
}
# perform search
s = pyaurorax.conjunctions.search(start,
end,
advanced_distances,
ground=ground,
space=space,
verbose=True)
# output data as a pandas dataframe
conjunctions = [c.__dict__ for c in s.data]
df = pd.DataFrame(conjunctions)
df.sort_values("start")
# search for conjunctions between Swarm A or Swarm B, and
# any THEMIS spacecraft with the south B trace region = "south polar cap"
start = datetime.datetime(2019, 1, 1, 0, 0, 0)
end = datetime.datetime(2019, 1, 1, 23, 59, 59)
space = [
{"programs": ["themis"]},
{
"programs": ["swarm"],
"platforms": ["swarma", "swarmb"],
"hemisphere": ["southern"],
"ephemeris_metadata_filters": {
"logical_operator": "AND",
"expressions": [
{
"key": "sbtrace_region",
"operator": "=",
"values": ["south polar cap"]
}
]
}
}
]
distance = 500
#perform search
s = pyaurorax.conjunctions.search(start,
end,
distance,
space=space,
verbose=True)
# output data as a pandas dataframe
conjunctions = [c.__dict__ for c in s.data]
df = pd.DataFrame(conjunctions)
df.sort_values("start")
Under the hood, the AuroraX API performs a conjunction search asynchronously. Note that this does not mean that it can be done using a Python async method; it means that PyAuroraX does more than just a single HTTP request against the AuroraX API when doing a search. With the API operating this way, it adds some more complexity within PyAuroraX but also opens the search up to some very important capabilities. The main capability enabled by this architecture is the ablity to perform queries for a large timeframe, and/or between a large number of data sources. Queries like this can easily take several minutes. A conventional HTTP request would normally timeout because of this, ultimately failing to complete the search.
Instead of using the pyaurorax.conjunctions.search
method which wraps all logic into an easy function, you can also perform a conjunction search step-by-step if you want more control over the process. Below, we do a search in this manner.
# set up the search parameters
start = datetime.datetime(2020, 1, 1, 0, 0, 0)
end = datetime.datetime(2020, 1, 1, 6, 59, 59)
ground = [
{"programs": ["themis-asi"]}
]
space = [
{"programs": ["swarm"]}
]
distance = 500
# create a Search object
s = pyaurorax.conjunctions.Search(start,
end,
distance,
ground=ground,
space=space)
print(s)
# execute the search
s.execute()
print(s)
# get request status
s.update_status()
pprint.pprint(s.status)
# view just the logs for the request (update the status beforehand, but we do that in the above cell)
pprint.pprint(s.logs)
# wait for the data
s.wait()
s.update_status()
# get data
s.get_data()
# show data as pandas dataframe
data_products = [d.__dict__ for d in s.data]
df = pd.DataFrame(data_products)
df.sort_values("start")