Best Python code snippet using autotest_python
test_3400_update_entity.py
Source:test_3400_update_entity.py  
1from modality_agnostic.test_support.common import lazy2from unittest import TestCase, main as unittest_main3def in_memory_collection(orig_f):  # #decorator4    def use_f():5        return in_memory_collection_via_entity_dictionaries(orig_f())6    return use_f7class CommonCase(TestCase):8    def these(self):9        def useAssertSequenceEqual(actual, expected):10            assert(isinstance(expected, tuple))11            use_expected = ('update_entity', *expected)12            self.assertSequenceEqual(actual, use_expected)13        pe = self.build_end_state().result_value14        stack = list(reversed(pe.units_of_work))15        return stack.pop, stack, useAssertSequenceEqual16    @property17    def end_state(self):18        cls = self.__class__19        if hasattr(cls, evil):20            return getattr(cls, evil)21        es = self.customize_end_state(self.build_end_state())22        setattr(cls, evil, es)23        return es24    def customize_end_state(self, end_state):25        return end_state26    def build_end_state(self):27        import modality_agnostic.test_support.common as em28        listener, emissions = em.listener_and_emissions_for(self)29        ncs = notecards_via_collection(self.collection())30        def perform(eid, cud_tups):31            entity_identifier_tup = ('update_entity', eid)32            return ncs._prepare_edit(entity_identifier_tup, cud_tups, listener)33        edits = self.perform(perform)34        return EndState(edits, tuple(emissions))35    do_debug = False36class EndState:37    def __init__(self, x, emi):38        self.result_value = x39        self.emissions = emi40        self.custom_data = None41evil = '_OMG_'  # back hacky memory hack [#507.6]42class Case3250_POORLY_FORMED_REQUEST(CommonCase):43    def test_100_strange_CUD_type(self):44        self.end_state['unrecognized CUD']45    def test_200_strange_attributes(self):46        line = self.end_state['had attribute'][0]47        self.assertEqual(line, 'had attribute name(s) not in the list of known attributes.')  # noqa: E50148    def test_300_multiple(self):49        self.end_state['appears multiple']50    def test_400_custom_reason(self):51        line = self.end_state["can't update"][0]52        self.assertEqual(line, "can't update identifier because identifiers are appointed to you")  # noqa: E50153    def customize_end_state(self, end_state):54        dct = {}55        assert(end_state.result_value is None)56        em, = end_state.emissions57        for para in paragraphs_via_lines(em.to_messages()):58            k = first_N_words(2, para[0])59            dct[k] = para60        return dct61    def perform(self, perform):62        cuds = []63        cuds.append(('frobulate_attribute', 'body'))64        cuds.append(('update_attribute', 'height_in_kilograms', 'qq'))65        cuds.append(('update_attribute', 'identifier', 'qq'))66        cuds.append(('create_attribute', 'body', 'qq'))67        cuds.append(('update_attribute', 'body', 'qq'))68        return perform('BB', cuds)69    def collection(self):70        return collection_LL1()71@lazy72@in_memory_collection73def collection_minimal():74    yield {75        'identifier_string': 'QQ',76        'core_attributes': {**reqs}}77class Case3280_delete_primitive(CommonCase):78    def test_100_everything(self):79        line, = self.build_end_state().emissions[0].to_messages()80        self.assertIn('body cannot be none', line)81    def perform(self, perform):82        return perform('QQ', (('delete_attribute', 'body'),))83    def collection(self):84        return collection_minimal()85class Case3310_update_primitive(CommonCase):86    def test_100_everything(self):87        pe = self.build_end_state().result_value88        edit, = pe.units_of_work89        expect = ('update_entity', 'QQ', 'update_attribute', 'body', 'wahoo')90        self.assertSequenceEqual(edit, expect)91    def perform(self, perform):92        cuds = []93        cuds.append(('update_attribute', 'body', 'wahoo'))94        return perform('QQ', cuds)95    def collection(self):96        return collection_minimal()97@lazy98@in_memory_collection99def collection_LL1():100    #101    #   AA <-> BB <-> CC <-> DD        GG <-> HH <-> II <-> JJ102    #103    yield {104        'identifier_string': 'AA',105        'core_attributes': {'next': 'BB', **reqs}}106    yield {107        'identifier_string': 'BB',108        'core_attributes': {'previous': 'AA', 'next': 'CC', **reqs}}109    yield {110        'identifier_string': 'CC',111        'core_attributes': {'previous': 'BB', 'next': 'DD', **reqs}}112    yield {113        'identifier_string': 'DD',114        'core_attributes': {'previous': 'CC', **reqs}}115    yield {116        'identifier_string': 'GG',117        'core_attributes': {'next': 'HH', **reqs}}118    yield {119        'identifier_string': 'HH',120        'core_attributes': {'previous': 'GG', 'next': 'II', **reqs}}121    yield {122        'identifier_string': 'II',123        'core_attributes': {'previous': 'HH', 'next': 'JJ', **reqs}}124    yield {125        'identifier_string': 'JJ',126        'core_attributes': {'previous': 'II', **reqs}}127class Case3340_create_a_prext(CommonCase):128    #129    #   AA <-> BB <-> CC <-> DD        GG <-> HH <-> II <-> JJ130    #131    #                          AFTER:132    #133    #   AA <-> BB <-> CC <-> DD <-> GG <-> HH <-> II <-> JJ134    def test_100_everything(self):135        p, stack, o = self.these()136        o(p(), ('DD', 'create_attribute', 'next', 'GG'))137        o(p(), ('GG', 'create_attribute', 'previous', 'DD'))138        assert(0 == len(stack))139    def perform(self, perform):140        cud = ('create_attribute', 'previous', 'DD')141        return perform('GG', (cud,))142    def collection(self):143        return collection_LL1()144class Case3370_two_cut_one_splice_a_linked_list(CommonCase):145    #146    #   AA <-> BB <-> CC <-> DD        GG <-> HH <-> II <-> JJ147    #148    #                          AFTER:149    #150    #   AA <-> BB <-> II <-> JJ     CC <-> DD    GG <-> HH151    def test_100_everything(self):152        p, stack, o = self.these()153        o(p(), ('HH', 'delete_attribute', 'next'))154        o(p(), ('II', 'update_attribute', 'previous', 'BB'))155        o(p(), ('CC', 'delete_attribute', 'previous'))156        o(p(), ('BB', 'update_attribute', 'next', 'II'))157        assert(0 == len(stack))158    def perform(self, perform):159        return perform('BB', (('update_attribute', 'next', 'II'),))160    def collection(self):161        return collection_LL1()162@in_memory_collection163def collection_tiktok():164    yield {165        'identifier_string': 'bytedance',166        'core_attributes': {'children': ('TikTok',), **reqs}}167    yield {168        'identifier_string': 'TikTok',169        'core_attributes': {'parent': 'bytedance', **reqs}}170class Case3400_delete_parent(CommonCase):171    #172    #        bytedance173    #             |174    #          TikTok175    #176    #          AFTER:177    #178    #        bytedance179    #180    #          TikTok181    def test_100_everything(self):  # _NOW_182        p, stack, o = self.these()183        o(p(), ('bytedance', 'delete_attribute', 'children'))184        o(p(), ('TikTok', 'delete_attribute', 'parent'))185        assert(0 == len(stack))186    def perform(self, perform):187        cud = ('delete_attribute', 'parent')188        return perform('TikTok', (cud,))189    def collection(self):190        return collection_tiktok()191class Case3430_create_parent(CommonCase):192    #193    #               AAA         BBB194    #             /    \       /   \195    #           A22    A23    B22  B23   C22196    #197    #                    AFTER:198    #                AAA199    #              /  |  \200    #           A22  A23  BBB            C22201    #                    /  \202    #                  B22 B23203    def test_100_everything(self):204        p, stack, o = self.these()205        o(p(), ('AAA', 'update_attribute', 'children', ('A22', 'A23', 'BBB')))206        o(p(), ('BBB', 'create_attribute', 'parent', 'AAA'))207        assert(0 == len(stack))208    def perform(self, perform):209        cud = ('create_attribute', 'parent', 'AAA')210        return perform('BBB', (cud,))211    def collection(self):212        return collection_fellas()213class Case3460_update_parent(CommonCase):214    #215    #               AAA         BBB216    #             /    \       /   \217    #           A22    A23    B22  B23   C22218    #219    #                    AFTER:220    #               AAA          BBB221    #             /            /  |  \222    #           A22         B22  B23 A23    C22223    def test_100_everything(self):224        p, stack, o = self.these()225        o(p(), ('AAA', 'update_attribute', 'children', ('A22',)))226        o(p(), ('BBB', 'update_attribute', 'children', ('B22', 'B23', 'A23')))227        o(p(), ('A23', 'update_attribute', 'parent', 'BBB'))228        assert(0 == len(stack))229    def perform(self, perform):230        cud = ('update_attribute', 'parent', 'BBB')231        return perform('A23', (cud,))232    def collection(self):233        return collection_fellas()234@lazy235@in_memory_collection236def collection_fellas():237    #238    #               AAA         BBB239    #             /    \       /   \240    #           A22    A23    B22  B23   C22241    #242    yield {243        'identifier_string': 'AAA',244        'core_attributes': {'children': ['A22', 'A23'], **reqs}}245    yield {246        'identifier_string': 'BBB',247        'core_attributes': {'children': ['B22', 'B23'], **reqs}}248    yield {249        'identifier_string': 'C22',250        'core_attributes': reqs}251    yield {252        'identifier_string': 'A22',253        'core_attributes': {'parent': 'AAA', **reqs}}254    yield {255        'identifier_string': 'A23',256        'core_attributes': {'parent': 'AAA', **reqs}}257    yield {258        'identifier_string': 'B22',259        'core_attributes': {'parent': 'BBB', **reqs}}260    yield {261        'identifier_string': 'B23',262        'core_attributes': {'parent': 'BBB', **reqs}}263class Case3490_delete_children(CommonCase):264    #265    #               AAA         BBB266    #             /    \       /   \267    #           A22    A23    B22  B23   C22268    #269    #                    AFTER:270    #               AAA         BBB271    #             /    \272    #           A22    A23    B22  B23   C22273    def test_100_everything(self):274        p, stack, o = self.these()275        o(p(), ('B22', 'delete_attribute', 'parent'))276        o(p(), ('B23', 'delete_attribute', 'parent'))277        o(p(), ('BBB', 'delete_attribute', 'children'))278        assert(0 == len(stack))279    def perform(self, perform):280        return perform('BBB', (('delete_attribute', 'children'),))281    def collection(self):282        return collection_fellas()283class Case3520_edit_children(CommonCase):284    #285    #               AAA         BBB286    #             /    \       /   \287    #           A22    A23    B22  B23   C22288    #289    #                    AFTER:290    #                AAA        BBB291    #             /   |  \       |292    #           C22  A23 B23    B22      A22293    def test_100_everything(self):294        p, stack, o = self.these()295        o(p(), ('BBB', 'update_attribute', 'children', ('B22',)))296        o(p(), ('B23', 'update_attribute', 'parent', 'AAA'))297        o(p(), ('C22', 'create_attribute', 'parent', 'AAA'))298        o(p(), ('A22', 'delete_attribute', 'parent'))299        o(p(), ('AAA', 'update_attribute', 'children', ('C22', 'A23', 'B23')))300        assert(0 == len(stack))301    def perform(self, perform):302        cud = ('update_attribute', 'children', ('C22', 'A23', 'B23'))303        return perform('AAA', (cud,))304    def collection(self):305        return collection_fellas()306class Case3550_create_children(CommonCase):307    #308    #               AAA         BBB309    #             /    \       /   \310    #           A22    A23    B22  B23   C22311    #312    #                    AFTER:313    #               AAA314    #             /     \315    #           A22     A23316    #                 /  |  \317    #              C22  BBB B23318    #                   /319    #                 B22320    def test_100_everything(self):321        p, stack, o = self.these()322        o(p(), ('BBB', 'update_attribute', 'children', ('B22',)))323        o(p(), ('B23', 'update_attribute', 'parent', 'A23'))324        o(p(), ('C22', 'create_attribute', 'parent', 'A23'))325        o(p(), ('BBB', 'create_attribute', 'parent', 'A23'))326        o(p(), ('A23', 'create_attribute', 'children', ('C22', 'BBB', 'B23')))327        assert(0 == len(stack))328    def perform(self, perform):329        cud = ('create_attribute', 'children', ('C22', 'BBB', 'B23'))330        return perform('A23', (cud,))331    def collection(self):332        return collection_fellas()333def notecards_via_collection(coll):334    from pho import _Notecards335    return _Notecards(coll)336# == FROM will move to kiss one day probaly  #[#873.16] coll impl337def in_memory_collection_via_entity_dictionaries(ent_dcts):338    def do_retrieve_entity(eid, listener):339        if eid not in ents:340            ddct = ddct_via_eid[eid]  # ddct = two-deep dictionary341            if ddct is None:342                return whine_not_found(listener, eid)343            ents[eid] = _MinimalEntity(ddct)344        return ents[eid]345    def whine_not_found(listener, eid):346        def structer():347            return {'reason': f"not found (hello from test) '{eid}'"}348        listener('error', 'structure', 'entity_not_found', structer)349    def no_clobber():350        seen = set()351        for ddct in ent_dcts:352            k = ddct['identifier_string']353            if k in seen:354                raise RuntimeError(f"Oops, clobber: '{k}'")355            seen.add(k)356            yield k, ddct357    ddct_via_eid = {k: v for k, v in no_clobber()}358    ents = {}359    class custom_collection:  # #class-as-namespace360        retrieve_entity = do_retrieve_entity361    return custom_collection362class _MinimalEntity:363    def __init__(self, ddct):364        self._ddct = ddct365    def to_dictionary_two_deep(self):366        return self._ddct367# == TO here368def paragraphs_via_lines(lines):369    def flush():370        para = tuple(cache)371        cache.clear()372        return para373    itr = iter(lines)374    cache = [next(itr)]375    for line in itr:376        if ' ' == line[0]:377            cache.append(line)378            continue379        yield flush()380        cache.append(line)381    para = flush()382    assert(len(para))383    yield para384def _build_first_N_words():385    def first_N_words(n, s):386        return rx_for(n).match(s)[0]387    def rx_for(n):388        rx = cache.get(n)389        if rx:390            return rx391        this = "[a-zA-Z']+"392        pcs = ['^', this]393        for _ in range(1, n):394            pcs.append(' ')395            pcs.append(this)396        rx = re.compile(''.join(pcs))397        cache[n] = rx398        return rx399    import re400    cache = {}401    return first_N_words402first_N_words = _build_first_N_words()403reqs = {404    'heading': "some heading",405    'body': "some body"}406if __name__ == '__main__':407    unittest_main()408# still need to cover:409# - {update} primitive410# - delete parent when you are only child leads to delete children...halo_catalog_profiles.py
Source:halo_catalog_profiles.py  
1"""2I used this to do all of the radial, density, etc. profiles of3the target halo.4The iterative_center_of_mass callback can be uncommented to5create a series of images as we zoom in on the center of mass6from the halo scale down to the collapsed object.7For each simulation, the target halo was:8cc_512_collapse_solar_dust           DD0182  874979cc_512_collapse_solar_no_dust        DD0185  6676810### rockstar_halos_2Myr catalogs11cc_512_no_dust_continue              DD0560  4173212cc_512_no_dust_continue_no_metal     DD0560  41732 (from cc_512_no_dust_continue)13cc_512_no_dust_continue_no_metal_ms2 DD0533  41732 (from cc_512_no_dust_continue)14### rockstar_halos catalogs15cc_512_no_dust_continue              DD0560  1682516cc_512_no_dust_continue_2            DD0532 16144917cc_512_continue_collapse_dust        DD0564  5001018"""19import numpy as np20import os21import sys22import yt23from yt.extensions.astro_analysis.halo_analysis.api import \24    add_callback, \25    add_recipe, \26    HaloCatalog27from yt.extensions.astro_analysis.halo_analysis.halo_callbacks import \28    periodic_distance29from yt.extensions.p2p import \30    add_p2p_fields31from yt.extensions.p2p.halo_catalog_callbacks import \32    get_my_sphere33def iterative_center_of_mass(halo, inner_radius,34                             radius_field="virial_radius", step_ratio=0.9):35    if step_ratio <= 0.0 or step_ratio >= 1.0:36        raise RuntimeError(37            "iterative_center_of_mass: step_ratio must be between 0 and 1.")38    dds = halo.halo_catalog.data_ds39    center_orig = halo_data_center(halo)40    radius_orig = halo_data_radius(halo, radius_field="virial_radius")41    sphere = get_my_sphere(halo, radius_field="virial_radius")42    my_units = "pc"43    yt.mylog.info("Halo %d: radius: %s, center: %s." %44                  (halo.quantities["particle_identifier"],45                   sphere.radius.in_units(my_units), sphere.center))46    i = 047    try:48        while sphere.radius > inner_radius:49            new_center = sphere.quantities.center_of_mass(50                use_gas=True, use_particles=False)51            sphere = sphere.ds.sphere(52                new_center, step_ratio * sphere.radius)53            region = dds.box(sphere.center-1.05*sphere.radius,54                             sphere.center+1.05*sphere.radius)55            for ax in "xyz":56                p = yt.ProjectionPlot(57                    dds, ax, ["density", "metallicity3", "temperature"],58                    weight_field="density", center=sphere.center,59                    width=(2*sphere.radius), data_source=region)60                if sphere.radius < sphere.ds.quan(0.1, "pc"):61                    my_units = "AU"62                p.set_axes_unit(my_units)63                p.set_cmap("density", "algae")64                p.set_cmap("temperature", "gist_heat")65                p.set_cmap("metallicity3", "kamae")66                p.save("sphere_center_box/%s_%03d" % (str(dds), i))67            i+=168            yt.mylog.info("Radius: %s, center: %s." %69                          (sphere.radius.in_units(my_units), sphere.center))70    except:71        yt.mylog.info("Reached minimum radius.")72        pass73    distance = periodic_distance(74        center_orig.in_units("unitary").v,75        new_center.in_units("unitary").v)76    distance = dds.quan(distance, "unitary")77    yt.mylog.info("Recentering halo %d %f pc away." %78                  (halo.quantities["particle_identifier"],79                   distance.in_units("pc")))80    set_halo_center(halo, new_center)81    del sphere82    yt.mylog.info("Original center: %s." % center_orig.to("unitary"))83    yt.mylog.info("     New center: %s." % new_center.to("unitary"))84add_callback("iterative_center_of_mass", iterative_center_of_mass)85def my_2d_radial_profile(hc, output_dir, my_field, field_units,86                         log=True):87    hc.add_callback(88        "profile", [("index", "radius"), ("gas", my_field)],89        ["cell_mass"], weight_field=None, bin_density=20,90        logs={("gas", my_field): log, ("index", "radius"): True},91        units={("gas", my_field): field_units, ("index", "radius"): "pc"})92    hc.add_callback("save_object_as_dataset", "profiles_object",93                    output_dir=output_dir, filename=my_field)94    hc.add_callback("delete_attribute", "profiles")95    hc.add_callback("delete_attribute", "profiles_variance")96    hc.add_callback("delete_attribute", "profiles_object")97add_recipe("my_2d_radial_profile", my_2d_radial_profile)98def my_2d_density_profile(hc, output_dir, my_field, field_units,99                          log=True):100    hc.add_callback(101        "profile", [("gas", "number_density"),102                    ("gas", my_field)], ["cell_mass"],103        weight_field=None, bin_density=20,104        units={("gas", my_field): field_units,105               ("gas", "number_density"): "cm**-3"})106    hc.add_callback("save_object_as_dataset", "profiles_object",107                    output_dir=output_dir, filename=my_field)108    hc.add_callback("delete_attribute", "profiles")109    hc.add_callback("delete_attribute", "profiles_variance")110    hc.add_callback("delete_attribute", "profiles_object")111add_recipe("my_2d_density_profile", my_2d_density_profile)112def run_halo_catalog(ddsfn, hdsfn, halo_id):113    dds = yt.load(ddsfn)114    add_p2p_fields(dds)115    hds = yt.load(hdsfn)116    hc = HaloCatalog(117        halos_ds=hds, data_ds=dds,118        output_dir="halo_catalogs/profile_catalogs/%s" % dds.basename)119    hc.add_filter("quantity_value", "particle_identifier", "==", halo_id, "")120    # my_radius = dds.quan(100.0, "AU")121    my_radius = dds.quan(1.0, "pc")122    # hc.add_callback("iterative_center_of_mass", my_radius)123    hc.add_callback("field_max_center", "density")124    # calculate virial mass125    hc.add_recipe("calculate_virial_quantities",126                  [('index', 'radius'),127                   ('gas', 'cell_mass'),128                   ('gas', 'dark_matter_mass'),129                   ('gas', 'matter_mass')])130    hc.add_callback("sphere")131    # 1D mass-weighted radial profiles132    hc.add_callback(133        "profile", ("index", "radius"),134        [('index', 'radius'),135         ('gas', 'cell_mass'),136         ('gas', 'dark_matter_mass'),137         ('gas', 'matter_mass')],138        units={("index", "radius"): "pc"},139        accumulation=True,140        weight_field=None, bin_density=20)141    hc.add_callback("save_object_as_dataset", "profiles_object",142                    output_dir="profiles", filename="virial_profiles")143    hc.add_callback("delete_attribute", "profiles")144    hc.add_callback("delete_attribute", "profiles_variance")145    hc.add_callback("delete_attribute", "profiles_object")146    # hc.add_callback("set_inner_bulk_velocity", my_radius)147    hc.add_callback("set_field_max_bulk_velocity", "density")148    hc.add_callback("set_inner_angular_momentum_vector", my_radius)149    # 1D mass-weighted radial profiles150    hc.add_callback(151        "profile", ("index", "radius"),152        [("gas", "metal3_mass"),153         ("gas", "cell_mass"),154         ("gas", "dark_matter_mass"),155         ("gas", "velocity_magnitude"),156         ("gas", "velocity_spherical_radius"),157         ("gas", "velocity_spherical_theta"),158         ("gas", "velocity_spherical_phi"),159         ("gas", "sound_speed"),160         ("gas", "specific_angular_momentum_magnitude"),161         ("gas", "specific_angular_momentum_x"),162         ("gas", "specific_angular_momentum_y"),163         ("gas", "specific_angular_momentum_z"),164         ("gas", "vortical_time"),165         ("gas", "dynamical_time"),166         ("gas", "cooling_time"),167         ("gas", "density"),168         ("gas", "temperature")],169        units={("index", "radius"): "pc"},170        weight_field="cell_mass", bin_density=20)171    hc.add_callback("save_object_as_dataset", "profiles_object",172                    output_dir="profiles", filename="profiles")173    hc.add_callback("delete_attribute", "profiles")174    hc.add_callback("delete_attribute", "profiles_variance")175    hc.add_callback("delete_attribute", "profiles_object")176    # 2D density profiles177    nprofs = [("H2_fraction", ""),178              ("HD_fraction", ""),179              ("HD_H2_ratio", ""),180              ("temperature", "K"),181              ("vortical_dynamical_ratio", ""),182              ("vortical_cooling_ratio",   ""),183              ("cooling_dynamical_ratio",  ""),184              ("vortical_time", "yr"),185              ("dynamical_time","yr"),186              ("cooling_time",  "yr")]187    for my_field, field_units in nprofs:188        hc.add_recipe("my_2d_density_profile", "density_profiles",189                      my_field, field_units)190    # 2D radial profiles191    rprofs = [("density", 'g/cm**3'),192              ("metallicity3_min7", 'Zsun'),193              ("temperature", 'K'),194              ("H2_fraction", '')]195    for my_field, field_units in rprofs:196        hc.add_recipe("my_2d_radial_profile", "radial_profiles",197                      my_field, field_units)198    # 2D radial/timescale profiles199    tprofs = [("vortical_dynamical_ratio", ""),200              ("vortical_cooling_ratio",   ""),201              ("cooling_dynamical_ratio",  ""),202              ("vortical_time", "yr"),203              ("dynamical_time","yr"),204              ("cooling_time",  "yr")]205    for my_field, field_units in tprofs:206        hc.add_recipe("my_2d_radial_profile", "timescale_profiles",207                      my_field, field_units)208    # 2D radial/velocity profiles209    my_field = "cell_mass"210    hc.add_callback("profile", [("index", "radius")], [("gas", my_field)],211                    weight_field=None, bin_density=20,212                    logs={("index", "radius"): True},213                    units={("index", "radius"): "pc"})214    hc.add_callback("save_object_as_dataset", "profiles_object",215                    output_dir="velocity_profiles", filename=my_field)216    hc.add_callback("delete_attribute", "profiles")217    hc.add_callback("delete_attribute", "profiles_variance")218    hc.add_callback("delete_attribute", "profiles_object")219    vprofs = ["velocity_magnitude",220              "velocity_spherical_radius",221              "velocity_spherical_theta",222              "velocity_spherical_phi",223              "tangential_velocity_magnitude",224              "sound_speed"]225    for my_field in vprofs:226        hc.add_recipe("my_2d_radial_profile", "velocity_profiles",227                      my_field, 'km/s', log=False)228    hc.create()229if __name__ == "__main__":230    ddsfn = sys.argv[1]231    hdsfn = sys.argv[2]232    datasets = {233        'cc_512_collapse_solar_dust':       {'DD0182':  87497},234        'cc_512_collapse_solar_no_dust':    {'DD0185':  66768},235        'cc_512_no_dust_continue':          {'DD0560':  16825},236        # 'cc_512_no_dust_continue_no_metal': {'DD0560':  41732},237        # 'cc_512_no_dust_continue_no_metal_ms2': {'DD0533':  41732},238        'cc_512_no_dust_continue_2':        {'DD0532': 161449},239        'cc_512_continue_collapse_dust':    {'DD0564':  50010}}240    if len(sys.argv) > 3:241        halo_id = int(sys.argv[3])242    else:243        curdir = os.path.basename(os.path.abspath(os.curdir))244        ds_key = os.path.basename(ddsfn)245        if curdir not in datasets:246            raise RuntimeError("Can't find %s in dataset collection." % curdir)247        my_sim = datasets[curdir]248        if ds_key not in my_sim:249            raise RuntimeError("Can't find %s in %s simulation." % (ds_key, curdir))250        halo_id = my_sim[ds_key]251        yt.mylog.info("Running profiles for halo %06d." % halo_id)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
