Commit 52d0a56a authored by Andrea Giannetti's avatar Andrea Giannetti
Browse files

Fixed prs queries.

parent d679bb90
Loading
Loading
Loading
Loading
+26 −19
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ def get_aggregated_ratio_from_db(
        dust_temperature: float,
        gas_density: float,
        lines: Union[list, tuple],
        session: Session) -> float:
        session: Session,
        run_id: str) -> float:
    """
    Get the aggregated ratio from the database, according to the aggregation function specified in the pre config file;
    this function works for a homogeneous model. For more complex models the query must be revised.
@@ -35,6 +36,7 @@ def get_aggregated_ratio_from_db(
    :param gas_density: the gas density of the model
    :param lines: the lines used to compute the ratio
    :param session: the SQLAlchemy session to use
    :param run_id: the id of the run
    :return: the aggregated ratio
    """
    results = session.query(GridPars, RatioMaps) \
@@ -42,13 +44,15 @@ def get_aggregated_ratio_from_db(
        .join(ModelPars) \
        .join(MomentZeroMaps) \
        .join(RatioMaps,
              or_(RatioMaps.mom_zero_map_1,
                  RatioMaps.mom_zero_map_2)) \
              or_(
                  and_(RatioMaps.mom_zero_map_1,
                       ModelPars.iline == lines[0]),
                  and_(RatioMaps.mom_zero_map_2,
                       ModelPars.iline == lines[1]))) \
        .filter(
        and_(GridPars.dust_temperature_at_reference == dust_temperature,
             GridPars.density_at_reference == gas_density,
             # GridPars.central_density == gas_density,
             or_(ModelPars.iline.in_(lines)))).order_by(GridPars.created_on.desc()).first()
             GridPars.run_id == run_id)).order_by(GridPars.created_on.desc()).first()
    return results[1].aggregated_ratio


@@ -72,8 +76,11 @@ def get_density_distribution(
        .join(ModelPars) \
        .join(MomentZeroMaps) \
        .join(RatioMaps,
              or_(RatioMaps.mom_zero_map_1,
                  RatioMaps.mom_zero_map_2)) \
              or_(
                  and_(RatioMaps.mom_zero_map_1,
                       ModelPars.iline == lines[0]),
                  and_(RatioMaps.mom_zero_map_2,
                       ModelPars.iline == lines[1]))) \
        .filter(
        and_(dust_temperature_column == dust_temperature,
             GridPars.density_at_reference == gas_density,
@@ -119,19 +126,19 @@ def main(run_id: str,
                                           coords={
                                               'gas_density': central_densities
                                           })
        # ratio_correlation =
        scatter_data = {}
        for lines in line_pairs:
            scatter_data[str(lines)] = {str(density): list() for density in central_densities}
            fig = plt.figure()
            for (tdust, nh2) in product(dust_temperatures, central_densities):
                aggregated_ratio = get_aggregated_ratio_from_db(dust_temperature=tdust,
                                                                gas_density=nh2,
                                                                lines=lines,
                                                                session=session)
                                                                session=session,
                                                                run_id=run_id)
                results.loc[tdust, nh2] = aggregated_ratio
                logger.debug(f'The aggregated ratio for lines {lines}, using {nh2}, {tdust} is: {aggregated_ratio}')
                ratio, ratio_fitsname, grid_fitsname, zoom_ratios, density_grid, ratio_values = get_density_distribution(
                ratio, ratio_fitsname, grid_fitsname, zoom_ratios, density_grid, ratio_values = \
                    get_density_distribution(
                        dust_temperature=tdust,
                        gas_density=nh2,
                        lines=lines,
@@ -158,5 +165,5 @@ def main(run_id: str,


if __name__ == '__main__':
    main(run_id='55d05c03-192a-47da-9dcf-c41df1882868', is_isothermal=False)
    main(run_id='97000860-29ae-4510-b7d3-5daaf57eb4e0', is_isothermal=False)
    # main(run_id='ba7fd3ed-5947-4dc6-bcef-38f151f19b77', is_isothermal=False)