-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change tab to space, fix PEP8 auto, prepare for black
We move to a 4 space format, Automatically fix Pep8 mistakes that can be auto fixed, and change the Flake8 setup.cfg to match what will happen under black. Currently line limit is set at 120 but that can be discussed.
- Loading branch information
Showing
45 changed files
with
5,605 additions
and
5,960 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ | |
from .config import load_config | ||
|
||
from .version import get_version | ||
|
||
__version__ = get_version(pep440=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,113 +12,116 @@ | |
from functools import lru_cache | ||
from ..config import load_config | ||
|
||
#-------------------------------------------------------------------------------------------------- | ||
|
||
# -------------------------------------------------------------------------------------------------- | ||
@lru_cache(maxsize=10) | ||
def get_catalog(target, radius=None, output='table'): | ||
""" | ||
Parameters: | ||
target (int or str): | ||
radius (float, optional): Radius around target in degrees to return targets for. | ||
outout (str, optional): Desired output format. Choises are 'table', 'dict', 'json'. | ||
Default='table'. | ||
Returns: | ||
dict: Dictionary with three members: | ||
- 'target': Information about target. | ||
- 'references': Table with information about reference stars close to target. | ||
- 'avoid': Table with stars close to target which should be avoided in FOV selection. | ||
.. codeauthor:: Rasmus Handberg <[email protected]> | ||
""" | ||
|
||
assert output in ('table', 'json', 'dict'), "Invalid output format" | ||
|
||
# Get API token from config file: | ||
config = load_config() | ||
token = config.get('api', 'token', fallback=None) | ||
if token is None: | ||
raise RuntimeError("No API token has been defined") | ||
|
||
# | ||
r = requests.get('https://flows.phys.au.dk/api/reference_stars.php', | ||
params={'target': target}, | ||
headers={'Authorization': 'Bearer ' + token}) | ||
r.raise_for_status() | ||
jsn = r.json() | ||
|
||
# Convert timestamps to actual Time objects: | ||
jsn['target']['inserted'] = Time(jsn['target']['inserted'], scale='utc') | ||
if jsn['target']['discovery_date'] is not None: | ||
jsn['target']['discovery_date'] = Time(jsn['target']['discovery_date'], scale='utc') | ||
|
||
if output in ('json', 'dict'): | ||
return jsn | ||
|
||
dict_tables = {} | ||
|
||
tab = Table( | ||
names=('targetid', 'target_name', 'target_status', 'ra', 'decl', 'redshift', 'redshift_error', 'discovery_mag', 'catalog_downloaded', 'pointing_model_created', 'inserted', 'discovery_date', 'project', 'host_galaxy', 'ztf_id', 'sntype'), | ||
dtype=('int32', 'str', 'str', 'float64', 'float64', 'float32', 'float32', 'float32', 'bool', 'bool', 'object', 'object', 'str', 'str', 'str', 'str'), | ||
rows=[jsn['target']]) | ||
|
||
tab['ra'].description = 'Right ascension' | ||
tab['ra'].unit = u.deg | ||
tab['decl'].description = 'Declination' | ||
tab['decl'].unit = u.deg | ||
dict_tables['target'] = tab | ||
|
||
for table_name in ('references', 'avoid'): | ||
tab = Table( | ||
names=('starid', 'ra', 'decl', 'pm_ra', 'pm_dec', 'gaia_mag', 'gaia_bp_mag', 'gaia_rp_mag', 'gaia_variability', 'B_mag', 'V_mag', 'H_mag', 'J_mag', 'K_mag', 'u_mag', 'g_mag', 'r_mag', 'i_mag', 'z_mag', 'distance'), | ||
dtype=('int64', 'float64', 'float64', 'float32', 'float32', 'float32', 'float32', 'float32', 'int32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float64'), | ||
rows=jsn[table_name]) | ||
|
||
tab['starid'].description = 'Unique identifier in REFCAT2 catalog' | ||
tab['ra'].description = 'Right ascension' | ||
tab['ra'].unit = u.deg | ||
tab['decl'].description = 'Declination' | ||
tab['decl'].unit = u.deg | ||
tab['pm_ra'].description = 'Proper motion in right ascension' | ||
tab['pm_ra'].unit = u.mas/u.yr | ||
tab['pm_dec'].description = 'Proper motion in declination' | ||
tab['pm_dec'].unit = u.mas/u.yr | ||
tab['distance'].description = 'Distance from object to target' | ||
tab['distance'].unit = u.deg | ||
|
||
tab['gaia_mag'].description = 'Gaia G magnitude' | ||
tab['gaia_bp_mag'].description = 'Gaia Bp magnitude' | ||
tab['gaia_rp_mag'].description = 'Gaia Rp magnitude' | ||
tab['gaia_variability'].description = 'Gaia variability classification' | ||
tab['B_mag'].description = 'Johnson B magnitude' | ||
tab['V_mag'].description = 'Johnson V magnitude' | ||
tab['H_mag'].description = '2MASS H magnitude' | ||
tab['J_mag'].description = '2MASS J magnitude' | ||
tab['K_mag'].description = '2MASS K magnitude' | ||
tab['u_mag'].description = 'u magnitude' | ||
tab['g_mag'].description = 'g magnitude' | ||
tab['r_mag'].description = 'r magnitude' | ||
tab['i_mag'].description = 'i magnitude' | ||
tab['z_mag'].description = 'z magnitude' | ||
|
||
# Add some meta-data to the table as well: | ||
tab.meta['targetid'] = int(dict_tables['target']['targetid']) | ||
|
||
dict_tables[table_name] = tab | ||
|
||
return dict_tables | ||
|
||
#-------------------------------------------------------------------------------------------------- | ||
""" | ||
Parameters: | ||
target (int or str): | ||
radius (float, optional): Radius around target in degrees to return targets for. | ||
outout (str, optional): Desired output format. Choises are 'table', 'dict', 'json'. | ||
Default='table'. | ||
Returns: | ||
dict: Dictionary with three members: | ||
- 'target': Information about target. | ||
- 'references': Table with information about reference stars close to target. | ||
- 'avoid': Table with stars close to target which should be avoided in FOV selection. | ||
.. codeauthor:: Rasmus Handberg <[email protected]> | ||
""" | ||
|
||
assert output in ('table', 'json', 'dict'), "Invalid output format" | ||
|
||
# Get API token from config file: | ||
config = load_config() | ||
token = config.get('api', 'token', fallback=None) | ||
if token is None: | ||
raise RuntimeError("No API token has been defined") | ||
|
||
# | ||
r = requests.get('https://flows.phys.au.dk/api/reference_stars.php', params={'target': target}, | ||
headers={'Authorization': 'Bearer ' + token}) | ||
r.raise_for_status() | ||
jsn = r.json() | ||
|
||
# Convert timestamps to actual Time objects: | ||
jsn['target']['inserted'] = Time(jsn['target']['inserted'], scale='utc') | ||
if jsn['target']['discovery_date'] is not None: | ||
jsn['target']['discovery_date'] = Time(jsn['target']['discovery_date'], scale='utc') | ||
|
||
if output in ('json', 'dict'): | ||
return jsn | ||
|
||
dict_tables = {} | ||
|
||
tab = Table(names=( | ||
'targetid', 'target_name', 'target_status', 'ra', 'decl', 'redshift', 'redshift_error', 'discovery_mag', | ||
'catalog_downloaded', 'pointing_model_created', 'inserted', 'discovery_date', 'project', 'host_galaxy', | ||
'ztf_id', 'sntype'), dtype=( | ||
'int32', 'str', 'str', 'float64', 'float64', 'float32', 'float32', 'float32', 'bool', 'bool', 'object', | ||
'object', 'str', 'str', 'str', 'str'), rows=[jsn['target']]) | ||
|
||
tab['ra'].description = 'Right ascension' | ||
tab['ra'].unit = u.deg | ||
tab['decl'].description = 'Declination' | ||
tab['decl'].unit = u.deg | ||
dict_tables['target'] = tab | ||
|
||
for table_name in ('references', 'avoid'): | ||
tab = Table(names=( | ||
'starid', 'ra', 'decl', 'pm_ra', 'pm_dec', 'gaia_mag', 'gaia_bp_mag', 'gaia_rp_mag', 'gaia_variability', | ||
'B_mag', 'V_mag', 'H_mag', 'J_mag', 'K_mag', 'u_mag', 'g_mag', 'r_mag', 'i_mag', 'z_mag', 'distance'), | ||
dtype=('int64', 'float64', 'float64', 'float32', 'float32', 'float32', 'float32', 'float32', 'int32', | ||
'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', 'float32', | ||
'float32', 'float64'), rows=jsn[table_name]) | ||
|
||
tab['starid'].description = 'Unique identifier in REFCAT2 catalog' | ||
tab['ra'].description = 'Right ascension' | ||
tab['ra'].unit = u.deg | ||
tab['decl'].description = 'Declination' | ||
tab['decl'].unit = u.deg | ||
tab['pm_ra'].description = 'Proper motion in right ascension' | ||
tab['pm_ra'].unit = u.mas / u.yr | ||
tab['pm_dec'].description = 'Proper motion in declination' | ||
tab['pm_dec'].unit = u.mas / u.yr | ||
tab['distance'].description = 'Distance from object to target' | ||
tab['distance'].unit = u.deg | ||
|
||
tab['gaia_mag'].description = 'Gaia G magnitude' | ||
tab['gaia_bp_mag'].description = 'Gaia Bp magnitude' | ||
tab['gaia_rp_mag'].description = 'Gaia Rp magnitude' | ||
tab['gaia_variability'].description = 'Gaia variability classification' | ||
tab['B_mag'].description = 'Johnson B magnitude' | ||
tab['V_mag'].description = 'Johnson V magnitude' | ||
tab['H_mag'].description = '2MASS H magnitude' | ||
tab['J_mag'].description = '2MASS J magnitude' | ||
tab['K_mag'].description = '2MASS K magnitude' | ||
tab['u_mag'].description = 'u magnitude' | ||
tab['g_mag'].description = 'g magnitude' | ||
tab['r_mag'].description = 'r magnitude' | ||
tab['i_mag'].description = 'i magnitude' | ||
tab['z_mag'].description = 'z magnitude' | ||
|
||
# Add some meta-data to the table as well: | ||
tab.meta['targetid'] = int(dict_tables['target']['targetid']) | ||
|
||
dict_tables[table_name] = tab | ||
|
||
return dict_tables | ||
|
||
|
||
# -------------------------------------------------------------------------------------------------- | ||
def get_catalog_missing(): | ||
|
||
# Get API token from config file: | ||
config = load_config() | ||
token = config.get('api', 'token', fallback=None) | ||
if token is None: | ||
raise Exception("No API token has been defined") | ||
|
||
# | ||
r = requests.get('https://flows.phys.au.dk/api/catalog_missing.php', | ||
headers={'Authorization': 'Bearer ' + token}) | ||
r.raise_for_status() | ||
return r.json() | ||
# Get API token from config file: | ||
config = load_config() | ||
token = config.get('api', 'token', fallback=None) | ||
if token is None: | ||
raise Exception("No API token has been defined") | ||
|
||
# | ||
r = requests.get('https://flows.phys.au.dk/api/catalog_missing.php', headers={'Authorization': 'Bearer ' + token}) | ||
r.raise_for_status() | ||
return r.json() |
Oops, something went wrong.