Cls for fields generated with synalm disagree with input Cls and Cls for fields generated using synfast












1















I am generating random healpix maps from an input angular power spectrum Cl. If I use healpy.synalm, then healpy.alm2map, and finally test the map by running healpy.anafast on the generated map, the output and input power spectra do not agree, especially at high l, the output power spectrum is above the input (See plot produced by code below). If I directly use healpy.synfast, I get an output power spectrum that agrees with the input. The same applies if I use the alms from healpy.synfast and generate a map from the synfast alms using healpy.alm2map. When I look into the source code of synfast, it seems to just call synalm and alm2map, so I don't understand, why their results disagree. My test code looks like this:



import numpy as np
import matplotlib.pyplot as plt
import classy
import healpy as hp

NSIDE = 32


A_s=2.3e-9
n_s=0.9624
h=0.6711
omega_b=0.022068
omega_cdm=0.12029

params = {
'output': 'dCl, mPk',
'A_s': A_s,
'n_s': n_s,
'h': h,
'omega_b': omega_b,
'omega_cdm': omega_cdm,
'selection_mean': '0.55',
'selection_magnification_bias_analytic': 'yes',
'selection_bias_analytic': 'yes',
'selection_dNdz_evolution_analytic': 'yes'}

cosmo = classy.Class()
cosmo.set(params)
cosmo.compute()
theory_cl=cosmo.density_cl()['dd']

data_map,data_alm=hp.synfast(theory_cl[0],NSIDE,alm=True)
data_cl=hp.anafast(data_map)
plt.plot(np.arange(len(data_cl)),data_cl,label="synfast")
data_map=hp.alm2map(data_alm,NSIDE)
data_cl=hp.anafast(data_map)
plt.plot(np.arange(len(data_cl)),data_cl,label="synfast using alm")

data_alm=hp.synalm(theory_cl[0])
data_map=hp.alm2map(data_alm,NSIDE)
data_cl=hp.anafast(data_map)
plt.plot(np.arange(len(data_cl)),data_cl,label="synalm")

plt.plot(np.arange(min(len(data_cl),len(theory_cl[0]))),theory_cl[0][:len(data_cl)],label="Theory")
plt.xlabel(r'$ell$')
plt.ylabel(r'$C_ell$')
plt.legend()
plt.show()


The offset becomes larger for lower NSIDE.



Thank you very much for your help.










share|improve this question







New contributor




Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    1















    I am generating random healpix maps from an input angular power spectrum Cl. If I use healpy.synalm, then healpy.alm2map, and finally test the map by running healpy.anafast on the generated map, the output and input power spectra do not agree, especially at high l, the output power spectrum is above the input (See plot produced by code below). If I directly use healpy.synfast, I get an output power spectrum that agrees with the input. The same applies if I use the alms from healpy.synfast and generate a map from the synfast alms using healpy.alm2map. When I look into the source code of synfast, it seems to just call synalm and alm2map, so I don't understand, why their results disagree. My test code looks like this:



    import numpy as np
    import matplotlib.pyplot as plt
    import classy
    import healpy as hp

    NSIDE = 32


    A_s=2.3e-9
    n_s=0.9624
    h=0.6711
    omega_b=0.022068
    omega_cdm=0.12029

    params = {
    'output': 'dCl, mPk',
    'A_s': A_s,
    'n_s': n_s,
    'h': h,
    'omega_b': omega_b,
    'omega_cdm': omega_cdm,
    'selection_mean': '0.55',
    'selection_magnification_bias_analytic': 'yes',
    'selection_bias_analytic': 'yes',
    'selection_dNdz_evolution_analytic': 'yes'}

    cosmo = classy.Class()
    cosmo.set(params)
    cosmo.compute()
    theory_cl=cosmo.density_cl()['dd']

    data_map,data_alm=hp.synfast(theory_cl[0],NSIDE,alm=True)
    data_cl=hp.anafast(data_map)
    plt.plot(np.arange(len(data_cl)),data_cl,label="synfast")
    data_map=hp.alm2map(data_alm,NSIDE)
    data_cl=hp.anafast(data_map)
    plt.plot(np.arange(len(data_cl)),data_cl,label="synfast using alm")

    data_alm=hp.synalm(theory_cl[0])
    data_map=hp.alm2map(data_alm,NSIDE)
    data_cl=hp.anafast(data_map)
    plt.plot(np.arange(len(data_cl)),data_cl,label="synalm")

    plt.plot(np.arange(min(len(data_cl),len(theory_cl[0]))),theory_cl[0][:len(data_cl)],label="Theory")
    plt.xlabel(r'$ell$')
    plt.ylabel(r'$C_ell$')
    plt.legend()
    plt.show()


    The offset becomes larger for lower NSIDE.



    Thank you very much for your help.










    share|improve this question







    New contributor




    Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      1












      1








      1








      I am generating random healpix maps from an input angular power spectrum Cl. If I use healpy.synalm, then healpy.alm2map, and finally test the map by running healpy.anafast on the generated map, the output and input power spectra do not agree, especially at high l, the output power spectrum is above the input (See plot produced by code below). If I directly use healpy.synfast, I get an output power spectrum that agrees with the input. The same applies if I use the alms from healpy.synfast and generate a map from the synfast alms using healpy.alm2map. When I look into the source code of synfast, it seems to just call synalm and alm2map, so I don't understand, why their results disagree. My test code looks like this:



      import numpy as np
      import matplotlib.pyplot as plt
      import classy
      import healpy as hp

      NSIDE = 32


      A_s=2.3e-9
      n_s=0.9624
      h=0.6711
      omega_b=0.022068
      omega_cdm=0.12029

      params = {
      'output': 'dCl, mPk',
      'A_s': A_s,
      'n_s': n_s,
      'h': h,
      'omega_b': omega_b,
      'omega_cdm': omega_cdm,
      'selection_mean': '0.55',
      'selection_magnification_bias_analytic': 'yes',
      'selection_bias_analytic': 'yes',
      'selection_dNdz_evolution_analytic': 'yes'}

      cosmo = classy.Class()
      cosmo.set(params)
      cosmo.compute()
      theory_cl=cosmo.density_cl()['dd']

      data_map,data_alm=hp.synfast(theory_cl[0],NSIDE,alm=True)
      data_cl=hp.anafast(data_map)
      plt.plot(np.arange(len(data_cl)),data_cl,label="synfast")
      data_map=hp.alm2map(data_alm,NSIDE)
      data_cl=hp.anafast(data_map)
      plt.plot(np.arange(len(data_cl)),data_cl,label="synfast using alm")

      data_alm=hp.synalm(theory_cl[0])
      data_map=hp.alm2map(data_alm,NSIDE)
      data_cl=hp.anafast(data_map)
      plt.plot(np.arange(len(data_cl)),data_cl,label="synalm")

      plt.plot(np.arange(min(len(data_cl),len(theory_cl[0]))),theory_cl[0][:len(data_cl)],label="Theory")
      plt.xlabel(r'$ell$')
      plt.ylabel(r'$C_ell$')
      plt.legend()
      plt.show()


      The offset becomes larger for lower NSIDE.



      Thank you very much for your help.










      share|improve this question







      New contributor




      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I am generating random healpix maps from an input angular power spectrum Cl. If I use healpy.synalm, then healpy.alm2map, and finally test the map by running healpy.anafast on the generated map, the output and input power spectra do not agree, especially at high l, the output power spectrum is above the input (See plot produced by code below). If I directly use healpy.synfast, I get an output power spectrum that agrees with the input. The same applies if I use the alms from healpy.synfast and generate a map from the synfast alms using healpy.alm2map. When I look into the source code of synfast, it seems to just call synalm and alm2map, so I don't understand, why their results disagree. My test code looks like this:



      import numpy as np
      import matplotlib.pyplot as plt
      import classy
      import healpy as hp

      NSIDE = 32


      A_s=2.3e-9
      n_s=0.9624
      h=0.6711
      omega_b=0.022068
      omega_cdm=0.12029

      params = {
      'output': 'dCl, mPk',
      'A_s': A_s,
      'n_s': n_s,
      'h': h,
      'omega_b': omega_b,
      'omega_cdm': omega_cdm,
      'selection_mean': '0.55',
      'selection_magnification_bias_analytic': 'yes',
      'selection_bias_analytic': 'yes',
      'selection_dNdz_evolution_analytic': 'yes'}

      cosmo = classy.Class()
      cosmo.set(params)
      cosmo.compute()
      theory_cl=cosmo.density_cl()['dd']

      data_map,data_alm=hp.synfast(theory_cl[0],NSIDE,alm=True)
      data_cl=hp.anafast(data_map)
      plt.plot(np.arange(len(data_cl)),data_cl,label="synfast")
      data_map=hp.alm2map(data_alm,NSIDE)
      data_cl=hp.anafast(data_map)
      plt.plot(np.arange(len(data_cl)),data_cl,label="synfast using alm")

      data_alm=hp.synalm(theory_cl[0])
      data_map=hp.alm2map(data_alm,NSIDE)
      data_cl=hp.anafast(data_map)
      plt.plot(np.arange(len(data_cl)),data_cl,label="synalm")

      plt.plot(np.arange(min(len(data_cl),len(theory_cl[0]))),theory_cl[0][:len(data_cl)],label="Theory")
      plt.xlabel(r'$ell$')
      plt.ylabel(r'$C_ell$')
      plt.legend()
      plt.show()


      The offset becomes larger for lower NSIDE.



      Thank you very much for your help.







      healpy






      share|improve this question







      New contributor




      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Jan 18 at 16:00









      Benedict KalusBenedict Kalus

      61




      61




      New contributor




      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Sorry, I missed that synfast knows about NSIDE, so the lmax is by default based on NSIDE, whereas synalm does not know about it, so it takes the maximum l of the input spectrum as lmax. Setting lmax to 3 * NSIDE -1 in synalm resolves the discrepancy.






          share|improve this answer








          New contributor




          Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.




















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            Benedict Kalus is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257478%2fcls-for-fields-generated-with-synalm-disagree-with-input-cls-and-cls-for-fields%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Sorry, I missed that synfast knows about NSIDE, so the lmax is by default based on NSIDE, whereas synalm does not know about it, so it takes the maximum l of the input spectrum as lmax. Setting lmax to 3 * NSIDE -1 in synalm resolves the discrepancy.






            share|improve this answer








            New contributor




            Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

























              0














              Sorry, I missed that synfast knows about NSIDE, so the lmax is by default based on NSIDE, whereas synalm does not know about it, so it takes the maximum l of the input spectrum as lmax. Setting lmax to 3 * NSIDE -1 in synalm resolves the discrepancy.






              share|improve this answer








              New contributor




              Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                0












                0








                0







                Sorry, I missed that synfast knows about NSIDE, so the lmax is by default based on NSIDE, whereas synalm does not know about it, so it takes the maximum l of the input spectrum as lmax. Setting lmax to 3 * NSIDE -1 in synalm resolves the discrepancy.






                share|improve this answer








                New contributor




                Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.










                Sorry, I missed that synfast knows about NSIDE, so the lmax is by default based on NSIDE, whereas synalm does not know about it, so it takes the maximum l of the input spectrum as lmax. Setting lmax to 3 * NSIDE -1 in synalm resolves the discrepancy.







                share|improve this answer








                New contributor




                Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer






                New contributor




                Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered yesterday









                Benedict KalusBenedict Kalus

                61




                61




                New contributor




                Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                Benedict Kalus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






















                    Benedict Kalus is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Benedict Kalus is a new contributor. Be nice, and check out our Code of Conduct.













                    Benedict Kalus is a new contributor. Be nice, and check out our Code of Conduct.












                    Benedict Kalus is a new contributor. Be nice, and check out our Code of Conduct.
















                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257478%2fcls-for-fields-generated-with-synalm-disagree-with-input-cls-and-cls-for-fields%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Callistus III

                    Ostreoida

                    Plistias Cous