You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After I run make-tom.sh and have a TOM, I'd like to have some targets available to further explore the TOMToolkit functionality. How about a management command to do that like addmessierobects?
Here's a starting point:
messier.py
# to run this file:# update line#14 with path# $ cd /path/to/your/TOM# $ ./manage.py shell_plus# >>> exec(open('/path/to/this/file/messier.py').read())importcsvfromtom_catalogs.harvesters.simbadimportSimbadHarvesterfromtom_targets.modelsimportTargetList, TargetName# Read the CSV file into a list of dictionaries for the form:# {'Messier number': 'M90', 'NGC/IC number': 'NGC 4569', 'Common name': '', 'Object type': 'Spiral galaxy'}messier_objects= []
withopen('/path/to/messier-catalog.csv', 'r') asfile:
reader=csv.DictReader(file)
forrowinreader:
messier_objects.append(row)
simbad=SimbadHarvester()
messier_targets= []
form_objinreversed(messier_objects):
target_aliases= [] # list of other names for this targetquery_name=m_obj['Messier number']
simbad.query(query_name)
target=simbad.to_target()
#print(f'unsaved target: {target}')messier_targets.append(target) # for creating a group later# handle aliaes: Common names, NCG/IC numbers, and if SIMBAD resolves to# different name, then use that and create an alias for the Messier number.iftarget.name!=query_name:
# this target has a different name than it's query_nametarget_aliases.append(query_name)
print(f' SIMBAD refers to {query_name} as {target.name} -- adding alias')
common_names=m_obj['Common name']
ifcommon_names:
# there are aliases in the CSV data# it could be one or more separatied by commas in a single stringtarget_aliases+= [alias.strip() foraliasincommon_names.split(',')]
ncg_numbers=m_obj['NGC/IC number']
ifncg_numbers:
target_aliases+= [alias.strip() foraliasinncg_numbers.split(',')]
target_extras= {'Object type': m_obj['Object type']}
target.save(extras=target_extras) #, names=target_aliases)foraliasintarget_aliases:
target_name, created=TargetName.objects.get_or_create(target=target, name=alias)
continue# skip prints belowifcreated:
print(f'Added {target_name} to names for {target}')
else:
print(f'{target_name} already a name for {target}')
print(f'{target.name} is a {target_extras["Object type"]} AKA {target_aliases}')
# now create a TargetGroup for the Messier Objects and add themmessier_target_list, created=TargetList.objects.get_or_create(name="Messier Objects")
ifcreated:
print(f'created {messier_target_list} TargetList`')
else:
print(f'TargetList {messier_target_list} exists')
fortargetinmessier_targets:
messier_target_list.targets.add(target)
It may be better to convert this csv file to a dict and have it live inside messier.py.
I implemented this as just a simple seed for Targets when there are no Targets yet in the database.
I believe this solves the need for someone who has just set up their first TOM (and new to TOMs in general) and wants an easy way to get some targets so they can start exploring the system.
I think a general CLI for adding targets sounds good but feels like a different use case to me.
After I run
make-tom.sh
and have a TOM, I'd like to have some targets available to further explore the TOMToolkit functionality. How about a management command to do that likeaddmessierobects
?Here's a starting point:
messier.py
It may be better to convert this csv file to a dict and have it live inside
messier.py
.messier-catalog.csv
The text was updated successfully, but these errors were encountered: