def main(): settings = ekster_settings.Settings() o = new_argument_parser(settings) gasfilename = o.gasfilename starsfilename = o.starsfilename sinksfilename = o.sinksfilename imagefilename = o.imagefilename bins = o.bins offset_x = o.x | units.pc offset_y = o.y | units.pc offset_z = o.z | units.pc w = o.w x_axis = o.x_axis y_axis = o.y_axis settings.plot_starscale = o.starscale settings.plot_width = w | units.pc settings.plot_image_size_scale = ( settings.plot_image_size_scale * (settings.plot_bins / bins)) or settings.plot_image_size_scale stars = read_set_from_file( starsfilename, "amuse", ) if starsfilename != "" else Particles() sinks = read_set_from_file( sinksfilename, "amuse", ) if sinksfilename != "" else Particles() if gasfilename: gas = read_set_from_file( gasfilename, "amuse", ) if hasattr(gas, "itype"): gas = gas[gas.itype == 1] # gas.h_smooth = gas.h default_temperature = 30 | units.K if not hasattr(gas, "u"): print("Setting temperature to %s" % default_temperature) gas.u = temperature_to_u(default_temperature) elif gas.u.unit is units.K: temp = gas.u del gas.u gas.u = temperature_to_u(temp) else: gas = Particles() mtot = gas.total_mass() com = mtot * gas.center_of_mass() if not sinks.is_empty(): mtot += sinks.total_mass() com += sinks.total_mass() * sinks.center_of_mass() if not stars.is_empty(): mtot += stars.total_mass() com += stars.total_mass() * stars.center_of_mass() com = com / mtot if o.use_com: offset_x = com[0] offset_y = com[1] offset_z = com[2] print(com.value_in(units.parsec)) time = o.time | units.Myr if not o.timestamp_off: try: time = gas.get_timestamp() except AttributeError: print('Unable to get timestamp, set time to 0 Myr.') time = 0.0 | units.Myr if time is None: print('Time is None, set time to 0 Myr') time = 0.0 | units.Myr print(time.in_(units.Myr)) converter = nbody_system.nbody_to_si( # 1 | units.pc, 1 | units.MSun, settings.gas_rscale, settings.gas_mscale, ) gasproperties = ["density", "temperature"] # gasproperties = ["density"] for gasproperty in gasproperties: settings.plot_width = o.w | units.pc settings.plot_bins = o.bins figure, ax = plot_hydro_and_stars( time, stars=stars, sinks=sinks, gas=gas, filename=imagefilename + ".pdf", offset_x=offset_x, offset_y=offset_y, offset_z=offset_z, x_axis=x_axis, y_axis=y_axis, title="time = %06.2f %s" % ( time.value_in(units.Myr), units.Myr, ), gasproperties=[gasproperty], # colorbar=True, # causes weird interpolation # alpha_sfe=0.02, # stars_are_sinks=False, thickness=None, length_unit=units.parsec, return_figure=True, settings=settings, ) plot_cluster_locations = False if plot_cluster_locations: from find_clusters import find_clusters clusters = find_clusters( stars, convert_nbody=converter, ) for cluster in clusters: cluster_com = cluster.center_of_mass() cluster_x = cluster_com[0].value_in(units.parsec) cluster_y = cluster_com[1].value_in(units.parsec) lagrangian = cluster.LagrangianRadii(converter) lr90 = lagrangian[0][-2] s = lr90.value_in(units.parsec) # print("Circle with x, y, z: ", x, y, s) circle = pyplot.Circle( (cluster_x, cluster_y), s, color='r', fill=False, ) ax.add_artist(circle) pyplot.savefig( gasproperty + "-" + imagefilename + ".png", dpi=settings.plot_dpi, )