





from math import asin, atan, cos, radians, sin, sqrt, tan

UpperCAmelCase_ 							=       6_37_81_37.0
UpperCAmelCase_ 							=       6_35_67_52.31_42_45
UpperCAmelCase_ 							=       6378137





def   lowerCamelCase__       (       UpperCamelCase__     :    float    ,      UpperCamelCase__     :    float    ,      UpperCamelCase__     :    float    ,      UpperCamelCase__     :    float  )     ->	float:



					'''simple docstring'''




					_snake_case													=			(AXIS_A - AXIS_B) / AXIS_A
					_snake_case													=			atan((1 - flattening) * tan(radians(UpperCamelCase__  )  )  )
					_snake_case													=			atan((1 - flattening) * tan(radians(UpperCamelCase__  )  )  )
					_snake_case													=			radians(UpperCamelCase__  )
					_snake_case													=			radians(UpperCamelCase__  )
					# Equation
					_snake_case													=			sin((phi_a - phi_a) / 2  )
					_snake_case													=			sin((lambda_a - lambda_a) / 2  )
					# Square both values
					sin_sq_phi *= sin_sq_phi
					sin_sq_lambda *= sin_sq_lambda
					_snake_case													=			sqrt(sin_sq_phi + (cos(UpperCamelCase__  ) * cos(UpperCamelCase__  ) * sin_sq_lambda)  )
					return 2 * RADIUS * asin(UpperCamelCase__  )


if __name__ == "__main__":
					import doctest

					doctest.testmod()










import argparse

import OmegaConf
import torch

from diffusers import DDIMScheduler, LDMPipeline, UNetLDMModel, VQModel





def   lowerCamelCase__       (       UpperCamelCase__     :    Dict    ,      UpperCamelCase__     :    List[str]    ,      UpperCamelCase__     :    Dict  )     ->	List[Any]:



					'''simple docstring'''




					_snake_case													=			OmegaConf.load(UpperCamelCase__  )
					_snake_case													=			torch.load(UpperCamelCase__    ,      map_location='cpu'  )['model']
					_snake_case													=			list(state_dict.keys()  )

					# extract state_dict for VQVAE
					_snake_case													=			{}
					_snake_case													=			'first_stage_model.'
					for key in keys:
										if key.startswith(UpperCamelCase__  ):
															_snake_case													=			state_dict[key]

    # extract state_dict for UNetLDM
					_snake_case													=			{}
					_snake_case													=			'model.diffusion_model.'
					for key in keys:
										if key.startswith(UpperCamelCase__  ):
															_snake_case													=			state_dict[key]

					_snake_case													=			config.model.params.first_stage_config.params
					_snake_case													=			config.model.params.unet_config.params

					_snake_case													=			VQModel(**UpperCamelCase__  ).eval()
					vqvae.load_state_dict(UpperCamelCase__  )

					_snake_case													=			UNetLDMModel(**UpperCamelCase__  ).eval()
					unet.load_state_dict(UpperCamelCase__  )

					_snake_case													=			DDIMScheduler(
					    timesteps=config.model.params.timesteps    ,      beta_schedule='scaled_linear'    ,      beta_start=config.model.params.linear_start    ,      beta_end=config.model.params.linear_end    ,      clip_sample=UpperCamelCase__    ,      )

					_snake_case													=			LDMPipeline(UpperCamelCase__    ,      UpperCamelCase__    ,      UpperCamelCase__  )
					pipeline.save_pretrained(UpperCamelCase__  )


if __name__ == "__main__":
					UpperCAmelCase_ 							=       argparse.ArgumentParser()
					parser.add_argument("""--checkpoint_path""", type=str, required=True)
					parser.add_argument("""--config_path""", type=str, required=True)
					parser.add_argument("""--output_path""", type=str, required=True)
					UpperCAmelCase_ 							=       parser.parse_args()

					convert_ldm_original(args.checkpoint_path, args.config_path, args.output_path)



