Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Management command to load some Targets #1170

Closed
phycodurus opened this issue Feb 3, 2025 · 2 comments · Fixed by #1171
Closed

Management command to load some Targets #1170

phycodurus opened this issue Feb 3, 2025 · 2 comments · Fixed by #1171
Assignees
Labels
enhancement New feature or request

Comments

@phycodurus
Copy link
Contributor

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())

import csv
from tom_catalogs.harvesters.simbad import SimbadHarvester
from tom_targets.models import TargetList, 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 = []
with open('/path/to/messier-catalog.csv', 'r') as file:
    reader = csv.DictReader(file)
    for row in reader:
        messier_objects.append(row)

        
simbad = SimbadHarvester()
messier_targets = []
for m_obj in reversed(messier_objects):
    target_aliases = [] # list of other names for this target
    query_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.
    if target.name != query_name:
        # this target has a different name than it's query_name
        target_aliases.append(query_name)
        print(f'    SIMBAD refers to {query_name} as {target.name} -- adding alias')

    common_names = m_obj['Common name']
    if  common_names:
        # there are aliases in the CSV data
        # it could be one or more separatied by commas in a single string
        target_aliases += [alias.strip() for alias in common_names.split(',')]

    ncg_numbers = m_obj['NGC/IC number']
    if ncg_numbers:
        target_aliases += [alias.strip() for alias in ncg_numbers.split(',')]

    target_extras = {'Object type': m_obj['Object type']}

    target.save(extras=target_extras) #, names=target_aliases)

    for alias in target_aliases:
        target_name, created = TargetName.objects.get_or_create(target=target, name=alias)
        continue # skip prints below
        if created:
            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 them
messier_target_list, created = TargetList.objects.get_or_create(name="Messier Objects")
if created:
    print(f'created {messier_target_list} TargetList`')
else:
    print(f'TargetList {messier_target_list} exists')
for target in messier_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.

messier-catalog.csv

Messier number,NGC/IC number,Common name,Object type
M1,NGC 1952,Crab Nebula,Supernova remnant
M2,NGC 7089,,Globular cluster
M3,NGC 5272,,Globular cluster
M4,NGC 6121,Spider Globular Cluster,Globular cluster
M5,NGC 5904,Rose Cluster,Globular cluster
M6,NGC 6405,Butterfly Cluster,Open cluster
M7,NGC 6475,Ptolemy's Cluster,Open cluster
M8,NGC 6523,Lagoon Nebula,Nebula with cluster
M9,NGC 6333,,Globular cluster
M10,NGC 6254,,Globular cluster
M11,NGC 6705,Wild Duck Cluster,Open cluster
M12,NGC 6218,,Globular cluster
M13,NGC 6205,Great Hercules Cluster,Globular cluster
M14,NGC 6402,,Globular cluster
M15,NGC 7078,Great Pegasus Cluster,Globular cluster
M16,NGC 6611,Eagle Nebula,H II region nebula with cluster
M17,NGC 6618,"Omega, Swan, Horseshoe, Lobster, Checkmark Nebula",H II region nebula with cluster
M18,NGC 6613,Black Swan Cluster,Open cluster
M19,NGC 6273,,Globular cluster
M20,NGC 6514,Trifid Nebula,H II region nebula with cluster
M21,NGC 6531,Webb's Cross Cluster,Open cluster
M22,NGC 6656,Great Sagittarius Cluster,Globular cluster
M23,NGC 6494,,Open cluster
M24,IC 4715,Small Sagittarius Star Cloud,Milky Way star cloud
M25,IC 4725,,Open cluster
M26,NGC 6694,,Open cluster
M27,NGC 6853,Dumbbell Nebula,Planetary nebula
M28,NGC 6626,,Globular cluster
M29,NGC 6913,Cooling Tower Cluster,Open cluster
M30,NGC 7099,Jellyfish Cluster,Globular cluster
M31,NGC 224,Andromeda Galaxy,Spiral galaxy
M32,NGC 221,Andromeda Satellite #1,Dwarf elliptical galaxy
M33,NGC 598,Triangulum/Pinwheel Galaxy,Spiral galaxy
M34,NGC 1039,Spiral Cluster,Open cluster
M35,NGC 2168,Shoe-Buckle Cluster,Open cluster
M36,NGC 1960,Pinwheel Cluster,Open cluster
M37,NGC 2099,Salt and Pepper Cluster,Open cluster
M38,NGC 1912,Starfish Cluster,Open cluster
M39,NGC 7092,,Open cluster
M40,,Winnecke 4,Optical Double
M41,NGC 2287,Little Beehive Cluster,Open cluster
M42,NGC 1976,Great Orion Nebula,H II region nebula
M43,NGC 1982,De Mairan's Nebula,H II region nebula (part of the Orion Nebula)
M44,NGC 2632,Beehive Cluster, Praesepe,Open cluster
M45,,"Pleiades, Seven Sisters, Subaru",Open cluster
M46,NGC 2437,,Open cluster
M47,NGC 2422,,Open cluster
M48,NGC 2548,,Open cluster
M49,NGC 4472,,Elliptical galaxy
M50,NGC 2323,Heart-Shaped Cluster,Open cluster
M51,"NGC 5194, NGC 5195",Whirlpool Galaxy,Spiral galaxy
M52,NGC 7654,Scorpion Cluster,Open cluster
M53,NGC 5024,,Globular cluster
M54,NGC 6715,,Globular cluster
M55,NGC 6809,Specter Cluster,Globular cluster
M56,NGC 6779,,Globular cluster
M57,NGC 6720,Ring Nebula,Planetary nebula
M58,NGC 4579,,Barred Spiral galaxy
M59,NGC 4621,,Elliptical galaxy
M60,NGC 4649,,Elliptical galaxy
M61,NGC 4303,Swelling Spiral Galaxy,Spiral galaxy
M62,NGC 6266,Flickering Globular,Globular cluster
M63,NGC 5055,Sunflower Galaxy,Spiral galaxy
M64,NGC 4826,Black Eye Galaxy,Spiral galaxy
M65,NGC 3623,Leo Triplet (NGC 3623),Barred Spiral galaxy
M66,NGC 3627,Leo Triplet (NGC 3627),Barred Spiral galaxy
M67,NGC 2682,King Cobra, Golden Eye Cluster,Open cluster
M68,NGC 4590,,Globular cluster
M69,NGC 6637,,Globular cluster
M70,NGC 6681,,Globular cluster
M71,NGC 6838,Angelfish Cluster,Globular cluster
M72,NGC 6981,,Globular cluster
M73,NGC 6994,,Asterism
M74,NGC 628,Phantom Galaxy,Spiral galaxy
M75,NGC 6864,,Globular cluster
M76,"NGC 650, NGC 651",Little Dumbbell Nebula,Planetary nebula
M77,NGC 1068,Cetus A, Squid Galaxy,Spiral galaxy
M78,NGC 2068,,Diffuse nebula
M79,NGC 1904,,Globular cluster
M80,NGC 6093,,Globular cluster
M81,NGC 3031,Bode's Galaxy,Spiral galaxy
M82,NGC 3034,Cigar Galaxy,Starburst galaxy
M83,NGC 5236,Southern Pinwheel Galaxy,Barred Spiral galaxy
M84,NGC 4374,,Lenticular galaxy
M85,NGC 4382,,Lenticular galaxy
M86,NGC 4406,,Lenticular galaxy
M87,NGC 4486,Virgo A, Smoking Gun Galaxy,Elliptical galaxy
M88,NGC 4501,,Spiral galaxy
M89,NGC 4552,,Elliptical galaxy
M90,NGC 4569,,Spiral galaxy
M91,NGC 4548,,Barred Spiral galaxy
M92,NGC 6341,,Globular cluster
M93,NGC 2447,Critter Cluster,Open cluster
M94,NGC 4736,Crocodile Eye, Cat's Eye Galaxy,Spiral galaxy
M95,NGC 3351,,Barred Spiral galaxy
M96,NGC 3368,,Spiral galaxy
M97,NGC 3587,Owl Nebula,Planetary nebula
M98,NGC 4192,,Spiral galaxy
M99,NGC 4254,St. Catherine's Wheel,Spiral galaxy
M100,NGC 4321,Mirror Galaxy,Spiral galaxy
M101,NGC 5457,Pinwheel Galaxy,Spiral galaxy
M102,NGC 5866,Spindle Galaxy,Lenticular galaxy
M103,NGC 581,,Open cluster
M104,NGC 4594,Sombrero Galaxy,Spiral galaxy
M105,NGC 3379,,Elliptical galaxy
M106,NGC 4258,,Spiral galaxy
M107,NGC 6171,Crucifix Cluster,Globular cluster
M108,NGC 3556,Surfboard Galaxy,Barred Spiral galaxy
M109,NGC 3992,Vacuum Cleaner Galaxy,Barred Spiral galaxy
M110,NGC 205,,Dwarf elliptical galaxy
@phycodurus phycodurus converted this from a draft issue Feb 3, 2025
@phycodurus phycodurus moved this from Triage to Staged in TOM Toolkit Feb 3, 2025
@phycodurus phycodurus added the enhancement New feature or request label Feb 3, 2025
@jchate6
Copy link
Contributor

jchate6 commented Feb 4, 2025

I would really like to see a generic addtarget management command to tom_targets.

This command could take a --messier flag, but could also take just a target name to be use as a search parameter by the harvesters.

I'll write up more about what commandline options I'm thinking later.

@Fingel Fingel self-assigned this Feb 4, 2025
@Fingel Fingel moved this from Staged to Needs Review in TOM Toolkit Feb 4, 2025
@Fingel Fingel linked a pull request Feb 4, 2025 that will close this issue
@Fingel
Copy link
Contributor

Fingel commented Feb 4, 2025

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.

@jchate6 jchate6 moved this from Needs Review to In progress in TOM Toolkit Feb 4, 2025
@github-project-automation github-project-automation bot moved this from In progress to Closed in TOM Toolkit Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

3 participants