2D stellar map distribution

Thiago Bueno Dalpiaz
  • 1
  • 30 May '23

Greetings,

I am trying to create a 2D histogram of stellar map distributions. However, I'm having troubles with its scales

import requests
import h5py
import numpy as np
import matplotlib.pyplot as plt

def get(path, params=None):
    # make HTTP GET request to path
    r = requests.get(path, params=params, headers=headers)

    # raise exception if response code is not HTTP SUCCESS (200)
    r.raise_for_status()

    if r.headers['content-type'] == 'application/json':
        return r.json() # parse json responses automatically

    if 'content-disposition' in r.headers:
        filename = r.headers['content-disposition'].split("filename=")[1]
        with open(filename, 'wb') as f:
            f.write(r.content)
        return filename # return the filename string

    return r

baseUrl = "https://www.tng-project.org/api/TNG50-1/snapshots/99/subhalos/377657/"
headers = {"api-key": " "}
sub = get(baseUrl )

params = {'stars':'Coordinates,Masses,GFM_Metallicity'}
cutout = get(baseUrl+"cutout.hdf5", params)

with h5py.File(cutout) as f:
    dx = f['PartType4']['Coordinates'][:,0] - sub['pos_x']
    dy = f['PartType4']['Coordinates'][:,1] - sub['pos_y']
    dz = f['PartType4']['Coordinates'][:,2] - sub['pos_z']
    dr = (dx, dy, dz)
    dens = np.log10(f['PartType4']['Masses'][:])

plot = plt.hist2d(dx,dy,bins=[500, 500], weights=dens, range=[[-5, 5], [-5, 5]], cmap='viridis', cmax=-3)
cbar = plt.colorbar(shrink = .92) 
cbar.ax.set_ylabel('log $M_\odot$', fontsize=20)
plt.xlabel('$\Delta x$ [ckpc/h]')
plt.ylabel('$\Delta y$ [ckpc/h]');

But my final result is this histogram
https://www.illustris-project.org/exp/user/6271/14f27bb0b213058e71fdab53f2935dbd.png

which is pretty awkward. Any suggestions?

Thank you in advance!

Dylan Nelson
  • 5 Jun '23

Instead of dens = np.log10(f['PartType4']['Masses'][:]) I would convert to solar masses and not log, e.g. dens = f['PartType4']['Masses'][:]*1e10/0.6774 and then I would later take the log of the hist2d e.g. plot = np.log10(plot). In this way the units you write in the colorbar label would be correct.

You should be able to come up with an image similar to that made by the visualization tool.

  • Page 1 of 1