Attitude Generator Module#

Note

At the moment, only JUICE AGM API interface is publicly available. In the future, the module will be able to run AGM directly if you have it installed locally.

When you have a valid PTR, read from a file with read_ptr() or manually created, you can try to submit it to ESA Attitude Generator Module (AGM) to know if the new attitude is valid and retrieve the generated camera kernel (ck) and resolved ptr (when you have observations block without start or/and stop times).

List the available API endpoints#

To call AGM, you need to identify which metakernel will be use as your baseline. You can get the list of the available metakernels in POINTING_TOOL_ENDPOINTS dictionary. At the moment, only the JUICE_API endpoint is implemented.

from ptr import POINTING_TOOL_ENDPOINTS

POINTING_TOOL_ENDPOINTS['JUICE_API']
<PointingToolApi> https://juicept.esac.esa.int | Contexts:
- JUICE Planning Cruise
- JUICE CREMA 5.1 150lb_23_1
- JUICE CREMA 5.1 150lb_23_1 Cruise
- JUICE CREMA 5.0

Call AGM programmatically#

from ptr import agm_simulation

In addition to your PTR file, you need to tell AGM which metakernel to use (here JUICE CREMA 5.0) and which endpoint will be called (JUICE_API):

Tip

Instead of calling agm_simulation on example.ptx filename, you can provide a pointing request message directly.

You can also call AGM direct on the PRM object:

prm.simulate('JUICE CREMA 5.0', 'JUICE_API')
results = agm_simulation('JUICE CREMA 5.0', 'example.ptx', 'JUICE_API')

results

Success


    • AGM Endpoint: https://juicept.esac.esa.int/agm
    • Metakernel: juice_crema_5_0_v433_20230517_001
    • <prm>
        <body>
          <segment>
            <data>
              <timeline frame="SC">
                  <block ref="OBS">
                     <metadata>
                        <comment> Occultation by star HD157056 </comment>
                        <comment>PRIME=JANUS</comment>
                        <solarArrays>
                           <fixedRotationAngle units="deg">-50</fixedRotationAngle>
                        </solarArrays>
                     </metadata>
                     <startTime> 2032-07-02T04:18:40 </startTime>
                     <endTime> 2032-07-02T04:32:00 </endTime>
                     <attitude ref="inertial">
                        <boresight ref="SC_Zaxis" />
                        <phaseAngle ref="align">
                           <SCAxis frame="SC">
                              <x> 0 </x>
                              <y> -1 </y>
                              <z> 0 </z>
                           </SCAxis>
                           <inertialAxis ref="EU2SC" />
                        </phaseAngle>
                        <target frame="EME2000">
                           <lon units="deg"> 260.504 </lon>
                           <lat units="deg"> -24.999 </lat>
                        </target>
                     </attitude>
                  </block>
              </timeline>
            </data>
          </segment>
        </body>
      </prm>
    • CK: https://juicept.esac.esa.int/agm_output/20230719T224225812362/OUTPUT/test.ck
    • Resolved PTR: https://juicept.esac.esa.int/agm_output/20230719T224225812362/OUTPUT/PTR_RESOLVED.ptx
    • timeqxqyqzqw
      2032-07-02 04:18:40-0.6697849293295030.512532311424147-0.2516532457093460.474730894416243
      2032-07-02 04:18:50-0.6689255330119180.513653436760066-0.2524480347198440.47430872641707
      2032-07-02 04:19:00-0.6680775736453360.514755842514552-0.2532298591498220.473891777333449
      2032-07-02 04:19:10-0.6672408492367960.515839966385375-0.2539990152583270.473479966246825
      2032-07-02 04:19:20-0.666415161636480.516906233423171-0.254755790953610.473073213324211
      2032-07-02 04:19:30-0.6656003164498020.517955056498756-0.2555004660960080.472671439812071
      2032-07-02 04:19:40-0.6647961230462750.518986836628201-0.256233312701270.472274568076058
      2032-07-02 04:19:50-0.6640023944673090.520001963412049-0.2569545952262330.471882521589237
      2032-07-02 04:20:00-0.6632189473826030.521000815396116-0.2576645708001150.471495224942615
      2032-07-02 04:20:10-0.6624456020347330.52198376043278-0.2583634894573560.471112603848287
      2032-07-02 04:20:20-0.6616821821830630.522951156029093-0.2590515943622510.470734585140788
      2032-07-02 04:20:30-0.6609285150468460.523903349682626-0.2597291220259590.470361096776635
      2032-07-02 04:20:40-0.6601844312473550.524840679205902-0.2603963025164430.469992067832064
      2032-07-02 04:20:50-0.6594497647498190.525763473039079-0.261053359661050.469627428499415
      2032-07-02 04:21:00-0.6587243528052130.52667205055144-0.2617005112420690.469267110082237
      2032-07-02 04:21:10-0.6580080358914040.527566722332865-0.2623379691860650.468911044988946
      2032-07-02 04:21:20-0.6573006576547660.528447790474441-0.2629659397463380.468559166725633
      2032-07-02 04:21:30-0.6566020648514550.529315548839737-0.2635846236795510.468211409887674
      2032-07-02 04:21:40-0.6559121072893490.530170283325982-0.2641942164159440.4678677101507
      2032-07-02 04:21:50-0.655230637769720.531012272116748-0.2647949082242410.467528004260504
      2032-07-02 04:22:00-0.6545575120297690.531841785925199-0.2653868843705320.467192230022499
      2032-07-02 04:22:10-0.6538925886852820.532659088229203-0.2659703252720380.466860326290402
      2032-07-02 04:22:20-0.6532357291738070.533464435498253-0.2665454066456630.466532232954372
      2032-07-02 04:22:30-0.6525867976988290.534258077411932-0.2671122996511440.466207890928898
      2032-07-02 04:22:40-0.6519456611738110.535040257071698-0.2676711710300010.465887242139901
      Use print() to display all elements.
    • Session ID: 20230719T224225812362
    INFOAGEAttitude Generation Module initialization started
    INFOAGEAGE module setup started
    INFOAGEAGE module setup successfully completed
    INFOAGEAttitude Generation Module initialization completed
    INFOAGELoading Attitude Timeline
    INFOAGEChecking Attitude Timeline
    INFOAGEInitializing Attitude Timeline
    INFOAGETOTAL ENERGY for POINTING block from 2032-07-02T04:18:40Z to 2032-07-02T04:32:00Z
    INFOAGEAttitude from actual PTR: 149.242146 Wh
    INFOAGEAttitude from loaded CK: 271.070485 Wh
    WARNINGAGEThe provided pointing is generating less power than the loaded attitude from the CK
    INFOPIFXML PTR file: "PTR_RESOLVED.ptx" generated
    WARNINGPIFGenerating CK file with the following DEFAULT parameters:
    INFOPIFCK frame ID: -28001
    INFOPIFCK time step: 300 s
    INFOAGEWriting Attitude Spice CK File: test.ck
    INFOPIFCK file: "test.ck" generated
    INFOAGEWriting Attitude Text File

As you can see, this simulation was successful. You can expand the results and explore the log if you need more details.

Hint

The calculations are cached locally to avoid, duplication requests if PTR was already submitted.

If you need to save this ck locally, you can do:

results.ck.save('example.ck')
PosixPath('example.ck')

You can also download the resolved PTR computed by AGM:

results.ptr_resolved.save('agm_resolved.ptx')
PosixPath('agm_resolved.ptx')

Use AGM results with spiceypy#

The AGMResults object retrieved after the simulation (here results) is compatible with spiceypy and can be used as a regular kernel file.

spiceypy.furnsh(results)

In that case, the generated ck from the simulation will be download and put into the SPICE Pool.

Call AGM from the command line interface#

You can query AGM directly from the command line in Jupyter notebooks and in your terminal:

Hint

Remove the ! symbol to run this command in your terminal. But keep it if you run this cell into a Jupyter notebook.

!juice-agm --help
usage: juice-agm [-h] [--mk METAKERNEL] [--endpoint URL] [--quaternions]
                 [--ck FILENAME] [--ptr-resolved FILENAME] [--log]
                 [--no-cache] [--show-contexts]
                 [ptr]

Check ESA/JUICE PTR validity with AGM.

positional arguments:
  ptr                   PTR/PTX input file.

optional arguments:
  -h, --help            show this help message and exit
  --mk METAKERNEL       Metakernel to use with AGM (default: "JUICE CREMA 5.1
                        150lb_23_1").
  --endpoint URL        AGM API endpoint URL (default: `JUICE_API`).
  --quaternions         Display computed quaternions (optional).
  --ck FILENAME         CK output filename (optional).
  --ptr-resolved FILENAME
                        Resolved PTR output filename (optional).
  --log                 Display AGM log (optional).
  --no-cache            Disable cache (optional).
  --show-contexts       Show available metakernel contexts.

By default, the tool will use JUICE pointing tool as AGM API endpoint. In the future, it should be possible use locally hosted AGM instances to perform complex queries.

If you just need to test the validity of a ptr file you just have to do:

!juice-agm example.ptx
AGM simulation: Success

You can explicitly say with which metakernel you want to work with:

!juice-agm --mk "JUICE CREMA 5.1 150lb_23_1" example.ptx
AGM simulation: Success

If you are only interested by the quaternions, you can request them:

!juice-agm --quaternions example.ptx
AGM simulation: Success
Quaternions:
2032-07-02 04:18:40 | -0.6702890171016990 | 0.5118728898501500 | -0.2511859142208350 | 0.4749783307545070
2032-07-02 04:18:50 | -0.6694153917593120 | 0.5130148682898310 | -0.2519953018774310 | 0.4745494136768020
2032-07-02 04:19:00 | -0.6685535208717470 | 0.5141375414621040 | -0.2527913235649000 | 0.4741258534604500
2032-07-02 04:19:10 | -0.6677031949551090 | 0.5152413660193100 | -0.2535742882397790 | 0.4737075664721680
2032-07-02 04:19:20 | -0.6668642085278700 | 0.5163267852776990 | -0.2543444960581670 | 0.4732944701918790
2032-07-02 04:19:30 | -0.6660363600218620 | 0.5173942297122520 | -0.2551022386960040 | 0.4728864832087940
2032-07-02 04:19:40 | -0.6652194517909510 | 0.5184441173064390 | -0.2558477995679300 | 0.4724835252636250
2032-07-02 04:19:50 | -0.6644132900173030 | 0.5194768540167020 | -0.2565814541289960 | 0.4720855172385020
2032-07-02 04:20:00 | -0.6636176846660070 | 0.5204928341574300 | -0.2573034701213330 | 0.4716923811689290
2032-07-02 04:20:10 | -0.6628324494283460 | 0.5214924407846430 | -0.2580141078212040 | 0.4713040402484600
2032-07-02 04:20:20 | -0.6620574016637120 | 0.5224760460662280 | -0.2587136202777500 | 0.4709204188311170
2032-07-02 04:20:30 | -0.6612923623407100 | 0.5234440116388270 | -0.2594022535434250 | 0.4705414424318930
2032-07-02 04:20:40 | -0.6605371559770270 | 0.5243966889526350 | -0.2600802468969810 | 0.4701670377252110
2032-07-02 04:20:50 | -0.6597916105794090 | 0.5253344196031090 | -0.2607478330581950 | 0.4697971325420690
2032-07-02 04:21:00 | -0.6590555575825739 | 0.5262575356517269 | -0.2614052383958520 | 0.4694316558653690
2032-07-02 04:21:10 | -0.6583288317884930 | 0.5271663599346070 | -0.2620526831280370 | 0.4690705378242070
2032-07-02 04:21:20 | -0.6576112713050090 | 0.5280612063608870 | -0.2626903815160820 | 0.4687137096866590
2032-07-02 04:21:30 | -0.6569027174847550 | 0.5289423802001970 | -0.2633185420516170 | 0.4683611038516170
2032-07-02 04:21:40 | -0.6562030148644690 | 0.5298101783596531 | -0.2639373676369970 | 0.4680126538397720
2032-07-02 04:21:50 | -0.6555120111040100 | 0.5306648896517300 | -0.2645470557600340 | 0.4676682942834500
2032-07-02 04:22:00 | -0.6548295569262380 | 0.5315067950520410 | -0.2651477986622890 | 0.4673279609159250
2032-07-02 04:22:10 | -0.6541555060569090 | 0.5323361679485390 | -0.2657397835019750 | 0.4669915905598490
2032-07-02 04:22:20 | -0.6534897151655370 | 0.5331532743813659 | -0.2663231925108880 | 0.4666591211152980
2032-07-02 04:22:30 | -0.6528320438062200 | 0.5339583732750151 | -0.2668982031465000 | 0.4663304915469970
2032-07-02 04:22:40 | -0.6521823543597880 | 0.5347517166615080 | -0.2674649882382780 | 0.4660056418714170
2032-07-02 04:22:50 | -0.6515405119759410 | 0.5355335498965820 | -0.2680237161296050 | 0.4656845131431490
2032-07-02 04:23:00 | -0.6509063845168420 | 0.5363041118674360 | -0.2685745508142450 | 0.4653670474412870
2032-07-02 04:23:10 | -0.6502798425006030 | 0.5370636351942830 | -0.2691176520689350 | 0.4650531878551080
2032-07-02 04:23:20 | -0.6496607590464740 | 0.5378123464237921 | -0.2696531755806880 | 0.4647428784699610
2032-07-02 04:23:30 | -0.6490490098200340 | 0.5385504662168060 | -0.2701812730705120 | 0.4644360643525560
2032-07-02 04:23:40 | -0.6484444729799430 | 0.5392782095286900 | -0.2707020924123290 | 0.4641326915364630
2032-07-02 04:23:50 | -0.6478470291250620 | 0.5399957857840531 | -0.2712157777483140 | 0.4638327070072480
2032-07-02 04:24:00 | -0.6472565612425070 | 0.5407033990453830 | -0.2717224696003250 | 0.4635360586875580
2032-07-02 04:24:10 | -0.6466729546569130 | 0.5414012481755131 | -0.2722223049773150 | 0.4632426954223150
2032-07-02 04:24:20 | -0.6460960969802950 | 0.5420895269948820 | -0.2727154174794230 | 0.4629525669637420
2032-07-02 04:24:30 | -0.6455258780628710 | 0.5427684244333530 | -0.2732019373985320 | 0.4626656239564190
2032-07-02 04:24:40 | -0.6449621899448230 | 0.5434381246768430 | -0.2736819918154800 | 0.4623818179223810
2032-07-02 04:24:50 | -0.6444049268091440 | 0.5440988073087530 | -0.2741557046938800 | 0.4621011012463570
2032-07-02 04:25:00 | -0.6438539849349491 | 0.5447506474471530 | -0.2746231969712310 | 0.4618234271608520
2032-07-02 04:25:10 | -0.6433092626523190 | 0.5453938158765970 | -0.2750845866464850 | 0.4615487497316250
2032-07-02 04:25:20 | -0.6427706602973600 | 0.5460284791763170 | -0.2755399888653310 | 0.4612770238429260
2032-07-02 04:25:30 | -0.6422380801751520 | 0.5466547998359110 | -0.2759895159967710 | 0.4610082051863750
2032-07-02 04:25:40 | -0.6417114264914130 | 0.5472729364047360 | -0.2764332777341810 | 0.4607422502337190
2032-07-02 04:25:50 | -0.6411906053487880 | 0.5478830435623649 | -0.2768713811399740 | 0.4604791162419180
2032-07-02 04:26:00 | -0.6406755246803110 | 0.5484852722601710 | -0.2773039307415520 | 0.4602187612262010
2032-07-02 04:26:10 | -0.6401660942156689 | 0.5490797698216180 | -0.2777310285978750 | 0.4599611439494220
2032-07-02 04:26:20 | -0.6396622254418580 | 0.5496666800466220 | -0.2781527743691690 | 0.4597062239083000
2032-07-02 04:26:30 | -0.6391638315648320 | 0.5502461433123080 | -0.2785692653842700 | 0.4594539613199150
2032-07-02 04:26:40 | -0.6386708274716540 | 0.5508182966708520 | -0.2789805967060810 | 0.4592043171082050
2032-07-02 04:26:50 | -0.6381831296940000 | 0.5513832739435220 | -0.2793868611944960 | 0.4589572528909220
2032-07-02 04:27:00 | -0.6377006563719870 | 0.5519412058122160 | -0.2797881495677230 | 0.4587127309665210
2032-07-02 04:27:10 | -0.6372233272189950 | 0.5524922199078099 | -0.2801845504614970 | 0.4584707143013430
2032-07-02 04:27:20 | -0.6367510634873910 | 0.5530364408955190 | -0.2805761504863110 | 0.4582311665170510
2032-07-02 04:27:30 | -0.6362837879347050 | 0.5535739905578740 | -0.2809630342831210 | 0.4579940518780960
2032-07-02 04:27:40 | -0.6358214247908360 | 0.5541049878747319 | -0.2813452845770590 | 0.4577593352795200
2032-07-02 04:27:50 | -0.6353638997261341 | 0.5546295491005730 | -0.2817229822293610 | 0.4575269822350250
2032-07-02 04:28:00 | -0.6349111398195481 | 0.5551477878400920 | -0.2820962062882130 | 0.4572969588649070
2032-07-02 04:28:10 | -0.6344630735284250 | 0.5556598151203400 | -0.2824650340372540 | 0.4570692318846530
2032-07-02 04:28:20 | -0.6340196306581780 | 0.5561657394615150 | -0.2828295410432480 | 0.4568437685933340
2032-07-02 04:28:30 | -0.6335807423331140 | 0.5566656669450040 | -0.2831898012019020 | 0.4566205368624170
2032-07-02 04:28:40 | -0.6331463409678461 | 0.5571597012793860 | -0.2835458867823450 | 0.4563995051247400
2032-07-02 04:28:50 | -0.6327163602392550 | 0.5576479438644920 | -0.2838978684703280 | 0.4561806423636350
2032-07-02 04:29:00 | -0.6322907350592250 | 0.5581304938533380 | -0.2842458154100060 | 0.4559639181022940
2032-07-02 04:29:10 | -0.6318694015479021 | 0.5586074482122499 | -0.2845897952445230 | 0.4557493023932950
2032-07-02 04:29:20 | -0.6314522970076820 | 0.5590789017790140 | -0.2849298741552920 | 0.4555367658083640
2032-07-02 04:29:30 | -0.6310393598977780 | 0.5595449473192560 | -0.2852661169000910 | 0.4553262794283210
2032-07-02 04:29:40 | -0.6306305298091500 | 0.5600056755813611 | -0.2855985868502060 | 0.4551178148331040
2032-07-02 04:29:50 | -0.6302257474405160 | 0.5604611753491480 | -0.2859273460260530 | 0.4549113440922220
2032-07-02 04:30:00 | -0.6298249545742970 | 0.5609115334936430 | -0.2862524551322350 | 0.4547068397550910
2032-07-02 04:30:10 | -0.6294280940537330 | 0.5613568350226010 | -0.2865739735910680 | 0.4545042748418550
2032-07-02 04:30:20 | -0.6290351097600539 | 0.5617971631290620 | -0.2868919595754880 | 0.4543036228341470
2032-07-02 04:30:30 | -0.6286459465904219 | 0.5622325992381970 | -0.2872064700408060 | 0.4541048576661500
2032-07-02 04:30:40 | -0.6282605504364150 | 0.5626632230526880 | -0.2875175607554840 | 0.4539079537158500
2032-07-02 04:30:50 | -0.6278788681628200 | 0.5630891125970050 | -0.2878252863311880 | 0.4537128857963640
2032-07-02 04:31:00 | -0.6275008475871010 | 0.5635103442601350 | -0.2881297002517900 | 0.4535196291475240
2032-07-02 04:31:10 | -0.6271264374592410 | 0.5639269928371810 | -0.2884308549016290 | 0.4533281594275940
2032-07-02 04:31:20 | -0.6267555874422150 | 0.5643391315695460 | -0.2887288015928140 | 0.4531384527052100
2032-07-02 04:31:30 | -0.6263882480969750 | 0.5647468321794370 | -0.2890235905884790 | 0.4529504854535840
2032-07-02 04:31:40 | -0.6260243708463560 | 0.5651501649271010 | -0.2893152711425450 | 0.4527642345338350
2032-07-02 04:31:50 | -0.6256639079830010 | 0.5655491986186030 | -0.2896038915037720 | 0.4525796772007840

You can also save the generated CK file or/and resolved ptr file locally:

!juice-agm --ck example.ck --ptr-resolved agm_resolved.ptx example.ptx
AGM simulation: Success
AGM CK saved in `example.ck`.
AGM resolved PTR saved in `agm_resolved.ptx`.

You can also get the different metakernels context available on the Juice pointing api like this:

!juice-agm --show-contexts
JUICE_API metakernel contexts available:
- JUICE Planning Cruise
- JUICE CREMA 5.1 150lb_23_1
- JUICE CREMA 5.1 150lb_23_1 Cruise
- JUICE CREMA 5.0